Differences between revisions 20 and 21
Revision 20 as of 2011-09-23 12:46:35
Size: 5952
Comment: +Is there a way to step into the last call (foo) without stepping into the inner calls (bar, baz)?
Revision 21 as of 2011-10-17 15:46:37
Size: 5941
Comment:
Deletions are marked like this. Additions are marked like this.
Line 34: Line 34:

. GDB 6.8 was released with -Werror configured in by default. You can disable it by configuring with:
  . GDB 6.8 was released with -Werror configured in by default. You can disable it by configuring with:
Line 42: Line 41:

. We can help with FSF's original GDB, and also with the GDBs shipped by the biggest distros. if you are lucky, somebody might know some peculiarities about some small distro's GDB.
  . We can help with FSF's original GDB, and also with the GDBs shipped by the biggest distros. if you are lucky, somebody might know some peculiarities about some small distro's GDB.
Line 46: Line 44:

. Apple has their own fork of GDB, and they are no longer pulling changes from the FSF GDB. Any bugs in this fork should be reported to Apple; there's nothing we can do about them. The FSF GDB has recently been ported to MacOS; however, it is believed that it will not work in XCode.
  . Apple has their own fork of GDB, and they are no longer pulling changes from the FSF GDB. Any bugs in this fork should be reported to Apple; there's nothing we can do about them. The FSF GDB has recently been ported to MacOS; however, it is believed that it will not work in XCode.
Line 50: Line 47:

. See [[STLSupport]].
  . See [[STLSupport]].
Line 54: Line 50:

. Your gdb 32bit/64bit architecture setting may not match that of gdbserver. Try to load the executable by {{{file}}} first. You may also check {{{set/show architecture}}}.
  . Your gdb 32bit/64bit architecture setting may not match that of gdbserver. Try to load the executable by {{{file}}} first. You may also check {{{set/show architecture}}}.
Line 58: Line 53:

. Compile the debugged program with gcc option {{{-g}}}.
  . Compile the debugged program with gcc option {{{-g}}}.
Line 62: Line 56:

. Use {{{set print elements -1}}}.
  . Use {{{set print elements -1}}}.
Line 66: Line 59:

. If you can recompile the program try [[http://people.redhat.com/jkratoch/itrace.c|itrace.c]]. For breakpoint on each function entry you can use GDB {{{rbreak}}}. With recompilation one can also put breakpoint on {{{__cyg_profile_func_enter}}} and {{{__cyg_profile_func_exit}}}.
  . If you can recompile the program try [[http://people.redhat.com/jkratoch/itrace.c|itrace.c]]. For breakpoint on each function entry you can use GDB {{{rbreak}}}. With recompilation one can also put breakpoint on {{{__cyg_profile_func_enter}}} and {{{__cyg_profile_func_exit}}}.
Line 70: Line 62:

. Try {{{setenforce 0}}} (SELinux) or {{{echo 0 >/proc/sys/kernel/yama/ptrace_scope}}} (ptrace scope) to disable system security protections.
  . Try {{{setenforce 0}}} (SELinux) or {{{echo 0 >/proc/sys/kernel/yama/ptrace_scope}}} (ptrace scope) to disable system security protections.
Line 74: Line 65:

. Without GDB you can setup (with Linux kernel) {{{/proc/sys/kernel/core_pattern}}}, it is used by bugreporting tools like [[https://fedorahosted.org/abrt/wiki|ABRT]] or [[https://wiki.ubuntu.com/Apport|Apport]].
  . Without GDB you can setup (with Linux kernel) {{{/proc/sys/kernel/core_pattern}}}, it is used by bugreporting tools like [[https://fedorahosted.org/abrt/wiki|ABRT]] or [[https://wiki.ubuntu.com/Apport|Apport]].
Line 78: Line 68:

. Such native feature is missing in GDB ({{{DW_TAG_GNU_call_site}}} should make it possible now). One can workaround it by a macro using {{{record, next, reverse-step, reverse-finish, step, record stop}}} if the inferior functions do not run for too long. Otherwise [[http://people.redhat.com/jkratoch/ignorefunc.cmd|ignorefunc.cmd]] and use {{{ignorefunc bar}}} and {{{ignorefunc baz}}} before making {{{step}}}.
  . Such native feature is missing in GDB ({{{DW_TAG_GNU_call_site}}} should make it possible now). One can workaround it by a macro using {{{record, next, reverse-step, reverse-finish, step, record stop}}} if the inferior functions do not run for too long. Otherwise [[http://people.redhat.com/jkratoch/ignorefunc.cmd|ignorefunc.cmd]] and use {{{ignorefunc bar}}} and {{{ignorefunc baz}}} before making {{{step}}}.
  1. How do I disable the Type <return> to continue, or q <return> to quit pagination prompt in GDB?

    • Either with set height 0 or set pagination off

  2. GDB reports a nonsensical return value from an inferior function call. What's going on?

    • GDB doesn't know the return type nor the type of the arguments for that function call, because there's no debug information available for it. Either provide debuginfo for the program or library which contains the function, or cast the function to a function pointer of the appropriate signature.

      For example, to call fabs, which takes a double and returns a double, use:

      (gdb) print ((double (*) (double)) fabs) ( -1.25 )
  3. How do I load/unload a shared library in GDB?

    • GDB doesn't manipulate shared libraries. This is done by the operating system's dynamic linker. GDB just obtains the list of shared libraries from it, and works with that.
  4. How to show the current instruction when single-stepping instructions?

    • (gdb) display/i $pc
  5. GDB reports Cannot find user-level thread for LWP 23957: generic error, how do I fix this?

    • There are several common causes:
      • You have a mismatch between libthread_db.so.1 and libpthread.so.0 (this most often happens when you have multiple installations of glibc, or when you debug a program on remote target, and host and target have different glibc versions).

      • You are using 64-bit debugger to debug 32-bit program, and your kernel has a 32-bit ptrace emulation bug. FIXME: add reference to specific kernel fix.

      This has also been known to happen when one of DOSEMU's signal handlers is invoked from DPMI context, where the $gs register has a value different from what GDB and/or libthread_db.so.0 expect; SamuelBronson found running the program under gdbserver to alleviate the problem, at least with version 6.8.50.20090620-cvs on i386.

  6. GDB does not see any threads besides the one in which crash occurred; or SIGTRAP kills my program when I set a breakpoint.

    • This frequently happen on Linux, especially on embedded targets. There are two common causes:
      • you are using glibc, and you have stripped libpthread.so.0

      • mismatch between libpthread.so.0 and libthread_db.so.1

      GDB itself does not know how to decode "thread control blocks" maintained by glibc and considered to be glibc private implementation detail. It uses libthread_db.so.1 (part of glibc) to help it do so. Therefore, libthread_db.so.1 and libpthread.so.0 must match in version and compilation flags. In addition, libthread_db.so.1 requires certain non-global symbols to be present in libpthread.so.0. Solution: use strip --strip-debug libpthread.so.0 instead of strip libpthread.so.0.

  7. GDB 6.8 doesn't compile with GCC x.y because of -Werror, what should I do?

    • GDB 6.8 was released with -Werror configured in by default. You can disable it by configuring with:
    $ /path/to/gdb-6.8/configure --disable-werror
  8. Why doesn't anybody on the GDB IRC channel answer my question about my small distro's GDB, or my custom GDB?

    • We can help with FSF's original GDB, and also with the GDBs shipped by the biggest distros. if you are lucky, somebody might know some peculiarities about some small distro's GDB.
  9. I've run into a bug in GDB while using XCode. Can you help?

    • Apple has their own fork of GDB, and they are no longer pulling changes from the FSF GDB. Any bugs in this fork should be reported to Apple; there's nothing we can do about them. The FSF GDB has recently been ported to MacOS; however, it is believed that it will not work in XCode.
  10. How do I print an STL container?

  11. When connecting to gdbserver I get Remote register badly formatted, g packet reply to long etc.

    • Your gdb 32bit/64bit architecture setting may not match that of gdbserver. Try to load the executable by file first. You may also check set/show architecture.

  12. When I try break 1 or list I get: No symbol table is loaded.

    • Compile the debugged program with gcc option -g.

  13. Ending of the string is truncated with ..., is there a way to get the whole string?

    • Use set print elements -1.

  14. How to trace every function entry and return?

    • If you can recompile the program try itrace.c. For breakpoint on each function entry you can use GDB rbreak. With recompilation one can also put breakpoint on __cyg_profile_func_enter and __cyg_profile_func_exit.

  15. Getting an internal error or other error while attaching to processes on GNU/Linux

    • Try setenforce 0 (SELinux) or echo 0 >/proc/sys/kernel/yama/ptrace_scope (ptrace scope) to disable system security protections.

  16. Is there a way to set commands to be run on a segfault?

    • Without GDB you can setup (with Linux kernel) /proc/sys/kernel/core_pattern, it is used by bugreporting tools like ABRT or Apport.

  17. Is there a way to step into the last call (foo) without stepping into the inner calls (bar, baz)? foo (bar (), baz ());

    • Such native feature is missing in GDB (DW_TAG_GNU_call_site should make it possible now). One can workaround it by a macro using record, next, reverse-step, reverse-finish, step, record stop if the inferior functions do not run for too long. Otherwise ignorefunc.cmd and use ignorefunc bar and ignorefunc baz before making step.

None: FAQ (last edited 2021-01-05 22:29:23 by JonnyGrant)

All content (C) 2008 Free Software Foundation. For terms of use, redistribution, and modification, please see the WikiLicense page.