1

I am very sorry, if my English is bad. This problem is getting me for days. I have a simple C source code with a sub function which I am examining. First I am creating the .out file with gcc. This file I am examining with GDB. But if I want to disassemble the called function I always get an error message from gdb. Prolog:

unix@unix-laptop:~/booksrc $ gcc -g stack_example.c
unix@unix-laptop:~/booksrc $ gdb -q ./a.out
Using host libthread_db library "/lib/tls/i686/cmov/libthread_db.so.1".
(gdb) disass main
Dump of assembler code for function main:
0x08048357 <main+0>:    push   %ebp
0x08048358 <main+1>:    mov    %esp,%ebp
0x0804835a <main+3>:    sub    $0x18,%esp
0x0804835d <main+6>:    and    $0xfffffff0,%esp
0x08048360 <main+9>:    mov    $0x0,%eax
0x08048365 <main+14>:   sub    %eax,%esp
0x08048367 <main+16>:   movl   $0x4,0xc(%esp)
0x0804836f <main+24>:   movl   $0x3,0x8(%esp)
0x08048377 <main+32>:   movl   $0x2,0x4(%esp)
0x0804837f <main+40>:   movl   $0x1,(%esp)
0x08048386 <main+47>:   call   0x8048344 <test_function>
0x0804838b <main+52>:   leave  
0x0804838c <main+53>:   ret    
End of assembler dump.
(gdb) disass test_function()
You can't do that without a process to debug.
(gdb)

Do you have an idea for the reason of the error? I have already used google but I can't find anything to solve the problem. I also searched for the instructions to be sure that the syntax is right. http://visualgdb.com/gdbreference/commands/disassemble

Thanks for reading, Intersect!

4
  • How do you compile your C code ; show the exact command (it should start with gcc -Wall -g). How do you run gdb? Which versions of gcc and of gdb are you using? Commented Aug 19, 2014 at 19:56
  • Please edit your question to show the typed command in place (not as screenshots on some external site). Start each command with at least four spaces in a separate paragraph. Commented Aug 19, 2014 at 20:00
  • Please put the TEXT of the error messages here! Putting an image to an external site is not welcome. Commented Aug 19, 2014 at 20:05
  • Done. I read the comments yet. In future i will post always the error message.. it was easier, because i am working in a virtualbox... Commented Aug 19, 2014 at 20:14

2 Answers 2

2

The syntax (of the gdb command) is disass function-name so you should type

 disass test_function

Read the genuine GDB documentation.

But you typed wrongly disass test_function() ; then ending parenthesis are wrong.

Be sure that you compiled your source code with gcc -Wall -g

At last, you could ask gcc to output an assembler file. Try for instance to compile your source.c file with

gcc -O1 -S -fverbose-asm source.c

(you could omit the -O1 or replace it with -g if you wanted to)

then look with an editor (or some pager) into the generated source.s assembly file.

Sign up to request clarification or add additional context in comments.

Comments

0

Maybe the function isn't there because it was inlined during compilation. I had never seen your error message before, sorry.

Please try to compile with the following additional flags:

-O0 -g

You can also see all function start addresses with:

objdump -x <filename>

This gives you a list of symbols in your executable file which includes all the start points of functions.

You can also disassemble your code with:

objdump -d <filename>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.