printing - View/Print function code from within GDB -
i trying develop simple text based user interface runs gdb commands. want user able set , break/trace point @ area of code , run debug commands.
i want user enter function needs debugged. take function name , print out source code of function, ask user select line of code @ set break/trace point. @ moment, using disassemble command can print out memory addresses user, want print actual source code instead.
can done in gdb?
currently:
dump of assembler code function test_function: 0x03800f70 <test_function+0>: push %ebp 0x03800f71 <test_function+1>: mov %esp,%ebp 0x03800f73 <test_function+3>: sub $0x48,%esp
what want:
void main() { printf("hello world\n"); }
thanks!
edit: i'm getting this:
(gdb) list myfunction 941 directory/directory_etc/sourcefile.c: no such file or directory. in directory/directory_etc/sourcefile.c
then tried specifying linenum:
(gdb) list directory/directory_etc/sourcefile.c:941 936 in directory/directory_etc/sourcefile.c
so behaviour similar describing, "list filename:linenum" still isnt working
thank you!
use:
(gdb) list function
see online of list command details:
(gdb) list list specified function or line. no argument, lists ten more lines after or around previous listing. "list -" lists ten lines before previous ten-line listing. 1 argument specifies line, , ten lines listed around line. 2 arguments comma between specify starting , ending lines list. lines can specified in these ways: linenum, list around line in current file, file:linenum, list around line in file, function, list around beginning of function, file:function, distinguish among like-named static functions. *address, list around line containing address. 2 args if 1 empty stands ten lines away other arg.
for non-toy projects, you'll hit case this:
$ gdb /bin/true <...> (gdb) start <...> (gdb) list printf file: "/usr/include/bits/stdio2.h", line number: 104 file: "printf.c", line number: 29
which lists multiple definitions of function in code base. in printf()
case above, non-overloaded pure c function has 2 definitions. 1 defined in stdio2.h
. can use list file:linenum
form specify 1 want list:
(gdb) list printf.c:29 24 25 /* write formatted output stdout format string format. */ 26 /* varargs1 */ 27 int 28 __printf (const char *format, ...) 29 { 30 va_list arg; 31 int done; 32 33 va_start (arg, format);
for "sourcefile.c: no such file or directory" errors you're seeing, need tell gdb source code. see gdb manual: source path. you'll need have source code function want list on machine.
Comments
Post a Comment