gdb忽略了我的断点等等

时间:2014-06-19 10:37:47

标签: debugging gdb

我有一种情况,我在gdb中设置断点,但没有任何影响,程序继续运行。

如果我通常从shell运行程序,最终它会在syslog上打印一些东西(第483行)。

所以,我在gdb中运行相同的程序,我在这一行设置了一个断点(483)并点击了run,但是程序继续运行直到结束。

...
Reading symbols from /usr/src/scannedonly-0.21/src/scannedonlyd_clamav...done.
(gdb) b 483
Breakpoint 1 at 0x804a8f1: file scannedonlyd_clamav.c, line 483.
(gdb) run -n
Starting program: /usr/src/scannedonly-0.21/src/scannedonlyd_clamav
[Thread debugging using libthread_db enabled]
HAVE_LIBCLAMAV_CL_INIT: 1
main
mark
mark2
mark3
about to load_engine()
load_engine()
LibClamAV Error: Can't load /usr/local/share/clamav/daily.cvd: Can't allocate memory

Program exited with code 02.
(gdb)

以下是来源的一部分:

 469 static struct cl_engine *load_engine()
 ...
 480         cl_engine_set_num(tmp, CL_ENGINE_MAX_SCANSIZE, (long long) 1024 * 1024 * 1024 * 5);
 481         cl_engine_set_num(tmp, CL_ENGINE_MAX_FILESIZE, (long long) 1024 * 1024 * 1024 * 5);
 482         if ((ret = cl_load(cl_retdbdir(), tmp, &sigs, CL_DB_STDOPT)) != CL_SUCCESS) {
 483                 syslog(LOG_CRIT, "WARNING2: Loading ClamAV database failed: %s", cl_strerror(ret));
 484                 cl_engine_free(tmp);
 485                 return NULL;

如果我设置一个断点来运行load_engine(),它看起来像是设置一个断点到另一个源文件。

好消息是它在断点处停止,但它就像在块注释中运行一样(第493,497行):

Reading symbols from /usr/src/scannedonly-0.21/src/scannedonlyd_clamav...done.
(gdb) b load_engine
Breakpoint 1 at 0x80496f7: file /usr/include/bits/stdio2.h, line 105.
(gdb) run -n
Starting program: /usr/src/scannedonly-0.21/src/scannedonlyd_clamav -n
[Thread debugging using libthread_db enabled]
HAVE_LIBCLAMAV_CL_INIT: 1
main
mark
mark2
mark3
about to load_engine()

Breakpoint 1, load_engine () at /usr/include/bits/stdio2.h:105
105       return __printf_chk (__USE_FORTIFY_LEVEL - 1, __fmt, __va_arg_pack ());
(gdb) n
493     #else
(gdb) n
105       return __printf_chk (__USE_FORTIFY_LEVEL - 1, __fmt, __va_arg_pack ());
(gdb) n
load_engine()
497             }
(gdb) list
492     /*
493     #else
494             if ((ret = cl_load(cl_retdbdir(), &tmp, &sigs, CL_DB_STDOPT))) {
495                     syslog(LOG_CRIT, "WARNING: Loading ClamAV database failed: %s", cl_strerror(ret));
496                     return NULL;
497             }
498             if ((ret = cl_build(tmp))) {
499                     syslog(LOG_CRIT, "WARNING: Building ClamAV engine failed: %s", cl_strerror(ret));
500                     cl_free(tmp);
501                     return NULL;

如果我在main()中的另一条线(1200)处设置了一个断点,它会在正确的行停止但在下一次按下时,程序流会跳过行。 它在单个" next"上从第1200行到1208,虽然它不应该(我发布"列表"所以你也可以看到来源) :

Reading symbols from /usr/src/scannedonly-0.21/src/scannedonlyd_clamav...done.
(gdb) b 1200
Breakpoint 1 at 0x804b97e: file scannedonlyd_clamav.c, line 1200.
(gdb) run -n
Starting program: /usr/src/scannedonly-0.21/src/scannedonlyd_clamav -n
[Thread debugging using libthread_db enabled]
HAVE_LIBCLAMAV_CL_INIT: 1
main
mark
mark2
mark3

Breakpoint 1, main (argc=2, argv=0xbffff794) at scannedonlyd_clamav.c:1200
1200    #endif
(gdb) list
1195    #ifdef HAVE_LIBCLAMAV_CL_INIT
1196            if (cl_init(CL_INIT_DEFAULT) != CL_SUCCESS) {
1197                    syslog(LOG_CRIT, "ABORT, failed to initialize libclamav");
1198                    exit(3);
1199            }
1200    #endif
1201            DEBUG_MSG("about to load_engine()\n");
1202            engine[0] = load_engine();
1203            engine[1] = NULL;
1204            current_engine = 0;
(gdb) n
1208            }
(gdb) list
1203            engine[1] = NULL;
1204            current_engine = 0;
1205            if (engine[0] == NULL) {
1206                    syslog(LOG_CRIT, "ABORT, exiting: no clam engine");
1207                    exit(2);
1208            }
1209            memset(&dbstat, 0, sizeof(struct cl_stat));
1210            cl_statinidir(cl_retdbdir(), &dbstat);
1211    #ifndef HAVE_LIBCLAMAV_CL_INIT
1212            memset(&limits, 0, sizeof(struct cl_limits));

我做错了吗? 有什么想法吗?

Btw," run -n"只是在控制台中打印msgs的程序的参数。

1 个答案:

答案 0 :(得分:0)

问题毕竟是源中的\ r \ n字符。 删除它们可以解决问题。