How to know which file a specific function is in with gdb? - gdb

Anyone knows how to know which file a specific function is in with gdb?

there is also info func which accepts a regular expression.
(gdb) info func ^bp1$
All functions matching regular expression "^bp1$":
File test.c:
void bp1();

Assuming the function name is someFunc, first find the address of the function:
info address someFunc
And assuming you got the adress someAddress, use list with that address:
list *someAddress
Example from a gdb session:
(gdb) info address main
Symbol "main" is a function at address 0x406159.
(gdb) list *0x406159
0x406159 is in main (../src/staapp-test.cpp:221).

Related

Find the function that calculated a variable in GDB

In debug mode using gdb, I can see that a function is consuming a variable, called h. I would like to know which gdb command to use to find the location (i.e. declaration of the variable or definition of another function calculating the variable) in the source code where h is calculated before being consumed by the said (second) function.
(gdb) p h
$1 = 2.556769473467e+33
(gdb) "a command to show the function that calculated h"

gdb "Couldn't find method ..." (Method from a library)

I compiled my code only with -g flag. I have this exact expression in my code:
auto b = some_func(row[0].as<MyType>());
But when I want to inspect part of the expression:
(gdb) print row[0].as<MyType>()
Couldn't find method pqxx::field::as<MyType>
I get this error. Even though I run it in the debugger when in the same block of code the whole expression is.
(the library in which the method resides is a C++ PostgreSQL libpqxx.so)
(gdb 8.3)
That's not the only thing that doesn't work. When I do:
(gdb) print my_unordered_map.find(MyType(1))
A syntax error in expression, near `1))'.
Or:
(gdb) print my_unordered_map.find(my_lambda(row[0]))
Invalid data type for function to be called.
(also for just my_lambda(row[0])) Even though exactly this was compiled.

gdb print symbol at address relative to base address

I found a suspicious deadlock at address myfile.exe+0x144c7 (from list of threads in ProcessExplorer). Now, I want to know which function it is.
info symbol addr
requires that addr is absolute. Is there a command that takes the relative address given by ProcessExplorer. I can add 0x400000 but it would be better if GDB could do it for me.
gdb accepts an expression for the symbol address, so you can do something like this:
info symbol 0x40000000 + 0x144c7
If you check "info variables" (or use nm on the executable) there's probably a symbolic name for the text segment containing your code, so you can also do something like:
info symbol _init + 0x144c7
Note that symbol might not work as expected if your problem is in a DLL or other text segment.

Get line number for lambda using GDB

We've a backtrace for a segfault that quotes a compiler-generated name for a lambda:
(gdb) bt
#0 std::_Function_handler<std::function<bool()>(), bold::AdHocOptionTreeBuilder::buildTree(bold::Agent*)::__lambda59>::_M_invoke(const std::_Any_data &) (__functor=...) at /usr/include/c++/4.8/functional:2057
#1 0x08146d2c in operator() (this=<optimized out>) at /usr/include/c++/4.8/functional:2464
...
The assigned name is bold::AdHocOptionTreeBuilder::buildTree(bold::Agent*)::__lambda59. However as you can tell that file has a lot of lambda in it! Is there a way to map that generated function's name to a line number in the source code? We have line numbers for other functions, however here it's only quoted as a type param for std::_Function_handler<>.
The linker option -Map mapfile should give you the information showing where each function originated, including lambda's. nm --line-numbers might work too, if the program was compiled with debug info -g.
Also, I think you can use set print symbol-filename on in GDB, and then evaluate &bold::AdHocOptionTreeBuilder::buildTree(bold::Agent*)::__lambda59

How to set a breakpoint in V8 using GDB

I am fairly new to GDB and V8 JavaScript engine.
After compiling shell.cc(/v8/v8-trunk/samples/Shell.cc), I try to set the breakpoint(b Parser::Parser) in parser.cc(/v8/v8-trunk/src), then GDB unexpectedly displays an error message: Can't find member of namespace, class, struct, or union named "Parser::Parser". However, the source code of the method "Parser::Parser" can be found in parser.cc.
Any ideas? thanks.
(gdb) c
Continuing.
V8 version 3.13.1 [sample shell]
> 3+5;
8
>
Program received signal SIGINT, Interrupt.
0x00752402 in __kernel_vsyscall ()
(gdb) b Parser::Parser
Can't find member of namespace, class, struct, or union named "Parser::Parser"
Hint: try 'Parser::Parser<TAB> or 'Parser::Parser<ESC-?>
(Note leading single quote.)
(gdb)
You need to specify namespaces also. According to parser.cc, Parser::Parser is located inside v8::internal namespace. Try this:
(gdb) b 'v8::internal::Parser::Parser'