- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我在某些 C 代码中遇到了段错误,我无法弄清楚如何读取它以便找出问题所在。
有没有人有什么技巧可以帮助我?有什么让你突然想到的吗?
这是 gdb 输出:
GNU gdb 6.8 for GNAT Pro 6.2.1 (20090115) [rev:143235]Copyright (C) 2008 Free Software Foundation, Inc.License GPLv3+: GNU GPL version 3 or later This is free software: you are free to change and redistribute it.See your support agreement for details of warranty and support.If you do not have a current support agreement, then there is absolutelyno warranty for this version of GDB. Type "show copying"and "show warranty" for details.This GDB was configured as "sparc-sun-solaris2.8"...Reading symbols from /usr/lib/libsocket.so.1...done.Loaded symbols for /usr/lib/libsocket.so.1Reading symbols from /usr/lib/libnsl.so.1...done.Loaded symbols for /usr/lib/libnsl.so.1Reading symbols from /usr/lib/libgen.so.1...done.Loaded symbols for /usr/lib/libgen.so.1Reading symbols from /usr/lib/libintl.so.1...warning: Lowest section in /usr/lib/libintl.so.1 is .dynamic at 00000074done.Loaded symbols for /usr/lib/libintl.so.1Reading symbols from /usr/lib/libw.so.1...warning: Lowest section in /usr/lib/libw.so.1 is .dynamic at 00000074done.Loaded symbols for /usr/lib/libw.so.1Reading symbols from /usr/lib/libm.so.1...done.Loaded symbols for /usr/lib/libm.so.1Reading symbols from /opt/services/AZJCommonZJX/solaris/lib/libazjcommonjcxC.so...done.Loaded symbols for /opt/services/AZJCommonZJX/solaris/lib/libazjcommonjcxC.soReading symbols from /usr/openwin/lib/libXext.so.0...done.Loaded symbols for /usr/openwin/lib/libXext.so.0Reading symbols from /usr/openwin/lib/libX11.so.4...done.Loaded symbols for /usr/openwin/lib/libX11.so.4Reading symbols from /usr/openwin/lib/libXmu.so.4...done.Loaded symbols for /usr/openwin/lib/libXmu.so.4Reading symbols from /usr/openwin/lib/libXt.so.4...done.Loaded symbols for /usr/openwin/lib/libXt.so.4Reading symbols from /usr/dt/lib/libXm.so.3...done.Loaded symbols for /usr/dt/lib/libXm.so.3Reading symbols from /usr/lib/libc.so.1...done.Loaded symbols for /usr/lib/libc.so.1Reading symbols from /opt/services/AZJCommonWork/solaris/lib/libazjcommonwork.so...done.Loaded symbols for /opt/services/AZJCommonWork/solaris/lib/libazjcommonwork.soReading symbols from /opt/services/AZJCommonWork/solaris/lib/libazjcommonworkC.so...done.Loaded symbols for /opt/services/AZJCommonWork/solaris/lib/libazjcommonworkC.soReading symbols from /app/gnatpro6.2.1/lib/gcc/sparc-sun-solaris2.8/4.3.3/rts-native/adalib/libgnarl-6.2.so...done.Loaded symbols for /opt/tools/SunOS/gnatpro6.2.1/lib/gcc/sparc-sun-solaris2.8/4.3.3/adalib/libgnarl-6.2.soReading symbols from /app/gnatpro6.2.1/lib/gcc/sparc-sun-solaris2.8/4.3.3/rts-native/adalib/libgnat-6.2.so...done.Loaded symbols for /opt/tools/SunOS/gnatpro6.2.1/lib/gcc/sparc-sun-solaris2.8/4.3.3/adalib/libgnat-6.2.soReading symbols from /usr/lib/libpthread.so.1...warning: Lowest section in /usr/lib/libpthread.so.1 is .dynamic at 00000074done.Loaded symbols for /usr/lib/libpthread.so.1Reading symbols from /usr/lib/librt.so.1...done.Loaded symbols for /usr/lib/librt.so.1Reading symbols from /app/gnatpro6.2.1/lib/libstdc++.so.6...done.Loaded symbols for /opt/tools/SunOS/gnatpro6.2.1/lib/libstdc++.so.6Reading symbols from /app/gnatpro6.2.1/lib/libgcc_s.so.1...done.Loaded symbols for /opt/tools/SunOS/gnatpro6.2.1/lib/libgcc_s.so.1Reading symbols from /usr/lib/libthread.so.1...warning: Lowest section in /usr/lib/libthread.so.1 is .dynamic at 00000074done.Loaded symbols for /usr/lib/libthread.so.1Reading symbols from /usr/lib/libaio.so.1...done.Loaded symbols for /usr/lib/libaio.so.1Reading symbols from /usr/lib/libmd.so.1...done.Loaded symbols for /usr/lib/libmd.so.1Reading symbols from /usr/lib/libm.so.2...done.Loaded symbols for /usr/lib/libm.so.2Reading symbols from /platform/sun4v/lib/libc_psr.so.1...done.Loaded symbols for /platform/SUNW,Sun-Fire-T200/lib/libc_psr.so.1Reading symbols from /lib/ld.so.1...done.Loaded symbols for /lib/ld.so.1Core was generated by `./solaris/apsui -aps_instance 1006 -aps_ato 0 -reject_menu_tearoff -aps_ipc_'.Program terminated with signal 11, Segmentation fault.[New process 75224 ]#0 0x7f1e4d00 in _XmGetFocusData () from /usr/dt/lib/libXm.so.3
Here is what gdb backtrace full shows:
(gdb) bt full#0 0x7f1e4d00 in _XmGetFocusData () from /usr/dt/lib/libXm.so.3No symbol table info available.#1 0x7f1e2768 in _XmNavigInitialize () from /usr/dt/lib/libXm.so.3No symbol table info available.#2 0x7f1e8adc in Initialize () from /usr/dt/lib/libXm.so.3No symbol table info available.#3 0x7f357760 in CallInitialize () from /usr/openwin/lib/libXt.so.4No symbol table info available.#4 0x7f3576b4 in CallInitialize () from /usr/openwin/lib/libXt.so.4No symbol table info available.#5 0x7f3576b4 in CallInitialize () from /usr/openwin/lib/libXt.so.4No symbol table info available.#6 0x7f353804 in xtCreate () from /usr/openwin/lib/libXt.so.4No symbol table info available.#7 0x7f35bf0c in _XtCreateWidget () from /usr/openwin/lib/libXt.so.4No symbol table info available.#8 0x7f35bc8c in XtCreateWidget () from /usr/openwin/lib/libXt.so.4No symbol table info available.#9 0x7f6026f8 in create_my_window (win=0xd3bc0) at /opt/services/AZJCommonZJX/src/uim/create/create_my_window.c:180 n_args = 0 args = {{name = 0x0, value = 0} } err_msg = '\0' , "ÿ¿Ïä", '\0' , "main_window_menu\000T_CMD MARITIME_TGT_CMD TEST \000K1\177}al\000\000\000\004\000\000\000\001\000\000\000\000"... shell = (Widget) 0xd50b8 object_width = 0 object_height = 1660944384 window_name = "TBM_PrimaryWin\000ä\000\000\000\000\177ÿÿø\177ÿü\000\177\023\222¤\000\000 \000\000\f\215ð\000\f\217 \177\023\222¬\177ÿü\000\000\000\000\000ÿ¿Î\200\177\005f,\000\000\000\000\177\023Vx\000\fO \000\aÀ\020\000\fO \1772*\000ui_ipc_xref." icon_pixmap = 8332422 obj = (gen_obj_list_t *) 0x6b0 vis = (vis_list_t *) 0x7f832bb8 toolbar = (toolbar_t *) 0x0#10 0x7f5f524c in create_my_window (in_buff=0x19750 "main_window_menu") at /opt/services/AZJCommonZJX/src/uim/create/create_my_window.c:431 func_name = "create_my_window" str = "\000\000\000\000\000\000\000\000¿¿Ä6'yC \000\000\000\000\000\000\000\000\177\235p0\000\000\000\000\000\003eÈ\000\003e¸\000\000\000\004ÿÿ\000\000\000\000\000\000ÿÿÿß\000\000\000\017\000\000\000\017\000\003^\200ÿ¿Ô\000\000\000\000\000\000\000\000\001\000\000\000\004\000\000\000\017ÿ¿Ó \177\2133, "\001\000\000\000\234\000\000\000\000\000\000\000\036\000\000\000\000\000\rP\000ÿ¿Ô \177\213\022\020\000"... ptr = 0x19760 "" keyword = 0x8a130 "" window_name = 0x8a130 ""---Type to continue, or q to quit--- title_name = "\000¿ÒØ\177\211îÄ\000\000\000\000\000\000\000\004", '\0' , "\003e¸\000\000\000\004ÿÿ\000\000\000\000\000\000ÿÿÿß\000\000\000\017\000\000\000 \000\001\023T\177¿sÈ\177·\fà\005øص\000\000\000@\177·\020Xÿ¿Ó8" full_title_name = 0x2b870 "TAP" object_width = 2141025804 object_height = 1 window_width = 0 window_height = 0 first_object = 1 other_obj = 0 centered_max_width = 18866798
Here is dbx output:
For information about new features see `help changes'
To remove this message, put `dbxenv suppress_startup_message 7.7' in your .dbxrc
Reading apsui
core file header read successfully
Reading ld.so.1
Reading libsocket.so.1
Reading libnsl.so.1
Reading libgen.so.1
Reading libintl.so.1
Reading libw.so.1
Reading libm.so.1
Reading librt.so.1
Reading libazjcommonjcxC.so
Reading libXext.so.0
Reading libX11.so.4
Reading libXmu.so.4
Reading libXt.so.4
Reading libXm.so.3
Reading libazjcommonwork.so
Reading libazjcommonworkC.so
Reading libgnarl-6.2.so
Reading libgnat-6.2.so
Reading libpthread.so.1
Reading libc.so.1
Reading libaio.so.1
Reading libmd.so.1
Reading libstdc++.so.6.0.10
Reading libgcc_s.so.1
Reading libthread.so.1
Reading libm.so.2
Reading libc_psr.so.1
t@1 (l@1) program terminated by signal SEGV (no mapping at the fault address)
0x7f264d00: _XmGetFocusData+0x0098: ld [%o0], %o1
Current function is create_my_window
180 win->main_window = MyWindow(shell, win->name, args, n_args);
>check -all
access checking - ON
memuse checking - ON
Running: apsui
(process id 18052)
Reading rtcapihook.so
Reading libdl.so.1
Reading rtcaudit.so
Reading libmapmalloc.so.1
Reading rtcboot.so
Reading librtc.so
RTC: Enabling Error Checking...
RTC: Using UltraSparc trap mechanism
RTC: See `help rtc showmap' and `help rtc limitations' for details.
RTC: Running program...
azjcommonworkdummy.adb elaborated
User Interface version TOOLKIT : 22 MAR 2010 UIMPID=18052
Read from unallocated (rua) on thread 1:
Attempting to read 4 bytes through NULL pointer
t@1 (l@1) stopped in _XmGetFocusData at 0x5d164d00
0x5d164d00: _XmGetFocusData+0x0098: ld [%o0], %o1
Current function is create_my_window
180 win->main_window = MyWindow(shell, win->name, args, n_args);
这是堆栈跟踪中我可以修改的最后一个函数调用(不在外部库中 - 在 create_my_window 中)。可以在此处查看此类的完整代码:http://utilitybase.com/paste/26607
void create_my_window( window_t *win)
{
Cardinal n_args;
Arg args[MAX_ARGS];
Widget shell = NULL;
//MORE STUFF HERE
memset(&(args), 0, sizeof(Arg)*MAX_ARGS); n_args = 0;
if (win->attributes != PRIMARY_WINDOW) {
XtSetArg(args[n_args], XmNtopAttachment, XmATTACH_FORM); n_args++;
XtSetArg(args[n_args], XmNbottomAttachment, XmATTACH_FORM); n_args++;
XtSetArg(args[n_args], XmNleftAttachment, XmATTACH_FORM); n_args++;
XtSetArg(args[n_args], XmNrightAttachment, XmATTACH_FORM); n_args++;
XtSetArg(args[n_args], XmNtopOffset, 0); n_args++;
XtSetArg(args[n_args], XmNbottomOffset, 0); n_args++;
XtSetArg(args[n_args], XmNleftOffset, 0); n_args++;
XtSetArg(args[n_args], XmNrightOffset, 0); n_args++;
}
win->main_window = XmCreateMainWindow(shell, win->name, args, n_args);
编辑
我在函数调用之前在 gdb 中添加了一个断点,并打印了一些值(不确定这是否有帮助 - 我是 n00b):
Breakpoint 1, create_my_window (win=0x9b378)
at /opt/services/AZJCommonZJX/src/jzs/create/create_my_window.c:179
179 printf("%d",n_args);
(gdb) p *win
$1 = {struct_type = 1045, next = 0x0, hash_name = 971,
name = 0x994e8 "error_log", widget = 0x0, main_window = 0x0, workarea = 0x0,
menu_bar = 0x0, message_window = 0x0, window_RC = 0x0, working_box = 0,
working_identifier = 0x0, has_message_area = 0, pos = {x = 0, y = 0},
illegal_char_set = 0x0, height = 0, width = 0, configured = 0,
actions = 0x0, title = 0x99d18, help_text = 0x0, groups = 0x0,
scroll_bars = 0x0, write_protect = 0, attributes = 0, initial_focus = {
obj_type = 0, obj_name = 0x0, area = 0x0}, text_edit = {
text_selected_widget = 0x0, text_focus_widget = 0x0, updated_widget = 0x0,
start = 0, end = 0, updated_text = 0x0, last_operation = 0},
close_rqt = 0x0, kill_application_action_list_name = 0x0, parent = 0x0,
gen_objs = 0x99da0, panes = 0x0, table_list = 0x0, selected_table = 0x0,
dialogs = 0x0, has_been_loaded = 0 '\0', source_file_name = 0x0}
(gdb) p *shell
$2 = {core = {self = 0x9db50, widget_class = 0xfec7897c, parent = 0x0,
xrm_name = 466, being_destroyed = 0 '\0', destroy_callbacks = 0x9ae58,
constraints = 0x0, x = 0, y = 0, width = 0, height = 0, border_width = 1,
managed = 0 '\0', sensitive = 1 '\001', ancestor_sensitive = 1 '\001',
event_table = 0x9ad98, tm = {translations = 0x0, proc_table = 0x0,
current_state = 0x0, lastEventTime = 0}, accelerators = 0x0,
border_pixel = 0, border_pixmap = 2, popup_list = 0x0, num_popups = 0,
name = 0x7776e "TBM_Dialog_Fixed", screen = 0x7a7e0, colormap = 32,
window = 0, depth = 24, background_pixel = 12825262,
background_pixmap = 2, visible = 1 '\001', mapped_when_managed = 1 '\001'}}
(gdb) p *args
$3 = {name = 0x0, value = 0}
(gdb) p *n_args
Cannot access memory at address 0x0
(gdb) p n_args
$4 = 0
(gdb) p args
$5 = {{name = 0x0, value = 0} <repeats 20 times>}
最佳答案
鉴于 dbx 表示“试图通过 NULL 指针读取 4 个字节”,并且错误是在函数调用行而不是在 XmCreateMainWindow
中报告的功能,我假设问题与语句 win->name
有关.这是这行 C 语言中唯一可以在实际调用函数之前读取指针的地方(它将读取存储在 win->name
中的数据拷贝并将拷贝传递给函数)。
尝试在调用 XmCreateMainWindow
的正上方的行中插入以下内容
assert(win != NULL);
您需要 #include <assert.h>
如果还没有。这应该验证 win
调用函数时不是 NULL 指针。为了彻底,您可能想为 shell
添加类似的行
关于c++ - 故障排除段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2294116/
#include using namespace std; class C{ private: int value; public: C(){ value = 0;
这个问题已经有答案了: What is the difference between char a[] = ?string?; and char *p = ?string?;? (8 个回答) 已关闭
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 7 年前。 此帖子已于 8 个月
除了调试之外,是否有任何针对 c、c++ 或 c# 的测试工具,其工作原理类似于将独立函数复制粘贴到某个文本框,然后在其他文本框中输入参数? 最佳答案 也许您会考虑单元测试。我推荐你谷歌测试和谷歌模拟
我想在第二台显示器中移动一个窗口 (HWND)。问题是我尝试了很多方法,例如将分辨率加倍或输入负值,但它永远无法将窗口放在我的第二台显示器上。 关于如何在 C/C++/c# 中执行此操作的任何线索 最
我正在寻找 C/C++/C## 中不同类型 DES 的现有实现。我的运行平台是Windows XP/Vista/7。 我正在尝试编写一个 C# 程序,它将使用 DES 算法进行加密和解密。我需要一些实
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
有没有办法强制将另一个 窗口置于顶部? 不是应用程序的窗口,而是另一个已经在系统上运行的窗口。 (Windows, C/C++/C#) 最佳答案 SetWindowPos(that_window_ha
假设您可以在 C/C++ 或 Csharp 之间做出选择,并且您打算在 Windows 和 Linux 服务器上运行同一服务器的多个实例,那么构建套接字服务器应用程序的最明智选择是什么? 最佳答案 如
你们能告诉我它们之间的区别吗? 顺便问一下,有什么叫C++库或C库的吗? 最佳答案 C++ 标准库 和 C 标准库 是 C++ 和 C 标准定义的库,提供给 C++ 和 C 程序使用。那是那些词的共同
下面的测试代码,我将输出信息放在注释中。我使用的是 gcc 4.8.5 和 Centos 7.2。 #include #include class C { public:
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
我的客户将使用名为 annoucement 的结构/类与客户通信。我想我会用 C++ 编写服务器。会有很多不同的类继承annoucement。我的问题是通过网络将这些类发送给客户端 我想也许我应该使用
我在 C# 中有以下函数: public Matrix ConcatDescriptors(IList> descriptors) { int cols = descriptors[0].Co
我有一个项目要编写一个函数来对某些数据执行某些操作。我可以用 C/C++ 编写代码,但我不想与雇主共享该函数的代码。相反,我只想让他有权在他自己的代码中调用该函数。是否可以?我想到了这两种方法 - 在
我使用的是编写糟糕的第 3 方 (C/C++) Api。我从托管代码(C++/CLI)中使用它。有时会出现“访问冲突错误”。这使整个应用程序崩溃。我知道我无法处理这些错误[如果指针访问非法内存位置等,
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 7 年前。
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,因为
我有一些 C 代码,将使用 P/Invoke 从 C# 调用。我正在尝试为这个 C 函数定义一个 C# 等效项。 SomeData* DoSomething(); struct SomeData {
这个问题已经有答案了: Why are these constructs using pre and post-increment undefined behavior? (14 个回答) 已关闭 6
我是一名优秀的程序员,十分优秀!