Thread: [Beginner Question] How to print the call link graph?
Hi community,
I use the gdb to track the postgres like this:
...
pq_getbyte () at pqcomm.c:980
980 in pqcomm.c
(gdb) next
985 in pqcomm.c
(gdb) next
986 in pqcomm.c
(gdb) next
SocketBackend (inBuf=0x7ffc8f7e1310) at postgres.c:372
372 postgres.c: Directory not empty.
(gdb) next
403 in postgres.c
(gdb) next
406 in postgres.c
(gdb) next
407 in postgres.c
(gdb) next
980 in pqcomm.c
(gdb) next
985 in pqcomm.c
(gdb) next
986 in pqcomm.c
(gdb) next
SocketBackend (inBuf=0x7ffc8f7e1310) at postgres.c:372
372 postgres.c: Directory not empty.
(gdb) next
403 in postgres.c
(gdb) next
406 in postgres.c
(gdb) next
407 in postgres.c
(gdb) next
...
But the question is:
It's too slow to input 'next' to run the postgres, I used to try to use the 'continut', but the gdb will run the postgres directly and not print the function name and code line
I want to it print like this:
... -> pq_getbyte () at pqcomm.c:980 -> SocketBackend (inBuf=0x7ffc8f7e1310) at postgres.c:372 -> ...
Can someone provide me some advice?
Thanks in advance!
Yours,
Wen Yi
On 7/1/23 02:10, Wen Yi wrote: > Hi community, > I use the gdb to track the postgres like this: > > ... > pq_getbyte () at pqcomm.c:980 > 980 in pqcomm.c > (gdb) next > 985 in pqcomm.c > (gdb) next > 986 in pqcomm.c > (gdb) next > SocketBackend (inBuf=0x7ffc8f7e1310) at postgres.c:372 > > 372 postgres.c: Directory not empty. > (gdb) next > 403 in postgres.c > (gdb) next > 406 in postgres.c > (gdb) next > 407 in postgres.c > (gdb) next > ... > > But the question is: > It's too slow to input 'next' to run the postgres, I used to try to use > the 'continut', but the gdb will run the postgres directly and not print > the function name and code line > > I want to it print like this: > > ... -> pq_getbyte () at pqcomm.c:980 -> SocketBackend > (inBuf=0x7ffc8f7e1310) at postgres.c:372 -> ... > > Can someone provide me some advice? If no one here can, then superuser.com, unix.stackexchange.com or stackoverflow.com should be able to. (Just don't cross-post...) -- Born in Arizona, moved to Babylonia.
On Sat, Jul 01, 2023 at 03:10:27PM +0800, Wen Yi wrote: > Hi community, > I use the gdb to track the postgres like this: > > ... > > pq_getbyte () at pqcomm.c:980 > 980 in pqcomm.c > (gdb) next > [...] > It's too slow to input 'next' to run the postgres, I used to try to use > the 'continut', but the gdb will run the postgres directly and not > print the function name and code line > > > I want to it print like this: > > > ... -> pq_getbyte () at pqcomm.c:980 -> SocketBackend (inBuf=0x7ffc8f7e1310) at postgres.c:372 -> ... > > Can someone provide me some advice? > Thanks in advance! I'm not sure what you want to do exactly, but just in case the usual way to do is to put a breakpoint at the function you're interested in (e.g. "break exec_simple_query"), or a specific line (e.g. "break filename.c:42"), and then show the backtrace (backtrace or just bt).
> If no one here can, then superuser.com, unix.stackexchange.com or
> stackoverflow.com should be able to. (Just don't cross-post...)
If I understand the question this is a GDB question, correct? If so, I would simply set a breakpoint in GDB at that function like so:
b SocketBackend
commands
bt 2
end
this will break then print a backtrace of the last 2 functions (you can remove the 2 to get a full backtrace or change it to some other value). You could also add a continue (c) after the bt to have it run and just print out the backtrace until all is done (save the result to a file using the set logging command)
--
Regards,
Garfield A. Lewis
> On 01/07/2023 09:10 CEST Wen Yi <wen-yi@qq.com> wrote: > > I use the gdb to track the postgres like this: > > ... > pq_getbyte () at pqcomm.c:980 > 980 in pqcomm.c > (gdb) next > 985 in pqcomm.c > (gdb) next > 986 in pqcomm.c > (gdb) next > SocketBackend (inBuf=0x7ffc8f7e1310) at postgres.c:372 > > 372 postgres.c: Directory not empty. > (gdb) next > 403 in postgres.c > (gdb) next > 406 in postgres.c > (gdb) next > 407 in postgres.c > (gdb) next > ... > > But the question is: > It's too slow to input 'next' to run the postgres, I used to try to use the > 'continut', but the gdb will run the postgres directly and not print the > function name and code line > > I want to it print like this: > > ... -> pq_getbyte () at pqcomm.c:980 -> SocketBackend (inBuf=0x7ffc8f7e1310) at postgres.c:372 -> ... > > Can someone provide me some advice? > Thanks in advance! The Postgres wiki has a page on this topic: https://wiki.postgresql.org/wiki/Getting_a_stack_trace_of_a_running_PostgreSQL_backend_on_Linux/BSD Look for "backtrace" and gdb's bt command. -- Erik
OK, that helps me a lot.
I just want to get the trace of function call.
Thanks very much!
Yours,
Wen Yi