加载标记为 "read on demand" 的 gdb 源

Load gdb sources marked as "read on demand"

我正在 GDB 中调试 C 应用程序 (postgres)。当我遇到断点时,堆栈的顶部帧将始终有源信息,但较低的帧通常不会:

(gdb) bt
#0  findTargetlistEntrySQL99 (pstate=0x555555ef8f78, node=0x555555ef8c08, tlist=0x555555ef90d0, exprKind=EXPR_KIND_GROUP_BY) at /home/sergei/postgresql/src/backend/parser/parse_clause.c:1775
#1  0x00005555556c6e9d in findTargetlistEntrySQL92 (pstate=<optimized out>, node=<optimized out>, tlist=<optimized out>, exprKind=<optimized out>) at /home/sergei/postgresql/src/backend/parser/parse_clause.c:1744
#2  0x00005555556c72d5 in transformGroupClauseExpr (flatresult=flatresult@entry=0x7fffffffd0a0, seen_local=seen_local@entry=0x0, pstate=pstate@entry=0x555555ef8f78, gexpr=gexpr@entry=0x555555ef8c08, targetlist=targetlist@entry=0x555555ef90d0, sortClause=sortClause@entry=0x0, exprKind=EXPR_KIND_GROUP_BY, useSQL99=0 '[=11=]0', toplevel=1 '[=11=]1') at /home/sergei/postgresql/src/backend/parser/parse_clause.c:1970
#3  0x00005555556c9192 in transformGroupClause (pstate=0x555555ef8f78, grouplist=<optimized out>, groupingSets=0x555555ef90f0, targetlist=0x555555ef90d0, sortClause=0x0, exprKind=EXPR_KIND_GROUP_BY, useSQL99=0 '[=11=]0') at /home/sergei/postgresql/src/backend/parser/parse_clause.c:2287
#4  0x00005555556aa111 in transformStmt ()
#5  0x00005555556abe6d in parse_analyze ()
#6  0x000055555574c50e in DefineView ()
#7  0x0000555555867bda in ProcessUtilitySlow.isra.4 ()
#8  0x0000555555866a97 in standard_ProcessUtility ()
#9  0x0000555555864084 in PortalRunUtility ()
#10 0x0000555555864b95 in PortalRunMulti ()
#11 0x00005555558657a4 in PortalRun ()
#12 0x00005555558631f2 in exec_simple_query (query_string=0x555555ea6de0 "-- Statistics views\n\nCREATE VIEW pg_stat_all_tables AS\n    SELECT\n", ' ' <repeats 12 times>, "C.oid AS relid,\n", ' ' <repeats 12 times>, "N.nspname AS schemaname,\n", ' ' <repeats 12 times>, "C.relname AS relname,\n", ' ' <repeats 12 times>, "pg_stat_get_numscans(C."...) at /home/sergei/postgresql/src/backend/tcop/postgres.c:1094
#13 PostgresMain (argc=<optimized out>, argv=<optimized out>, dbname=<optimized out>, username=<optimized out>) at /home/sergei/postgresql/src/backend/tcop/postgres.c:4069
#14 0x00005555555f719d in main ()

起初我怀疑是GDB找不到下层框架的源文件。然而,事实并非如此:info sources 显示了这些源文件,但它们被标记为 "read on demand"。例如第6帧的函数DefineView定义在view.c.

(gdb) info sources
Source files for which symbols have been read in:
    ...
Source files for which symbols will be read in on demand:
    ... , /home/sergei/postgresql/src/backend/commands/view.c , ...

所有源文件路径(包括view.c)都是正确的。 如何让 GDB 加载这些源代码?我正在使用来自 IDE 的 GDB,因此涉及一次性配置更改的解决方案是更可取的。

命令行选项 gdb --readnow,应该会导致 gdb 在发现符号文件时读取它们。