- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我最近从 Mac OS X 10.7 升级到 10.9。由于 OS X 不再支持 gdb,我通过 macports 安装了 GNU gdb。在能够使用它之前,我必须按照描述对其进行代码设计 here .现在我可以使用 gdb 作为调试器,但是在附加到进程时我在设置断点时遇到了问题。我会为你做一个例子。我拿了这个示例 C 代码
#include <unistd.h>
#include <stdio.h>
void f() {
printf("f()\n");
}
int main() {
printf("sleeping 30 seconds...\n");
sleep(30);
printf("invoking f()\n");
f();
}
并编译它
gcc -g a.c
如果我现在尝试调试
gdb a.out
并在 gdb 中运行它,结果如下(如预期的那样)
GNU gdb (GDB) 7.6
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin13.0.0".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /private/tmp/a.out...Reading symbols from /private/tmp/a.out.dSYM/Contents/Resources/DWARF/a.out...done.
done.
(gdb) break f
Breakpoint 1 at 0x100000ee0: file a.c, line 5.
(gdb) r
Starting program: /private/tmp/a.out
sleeping 30 seconds...
invoking f()
Breakpoint 1, f () at a.c:5
5 printf("f()\n");
(gdb) c
Continuing.
f()
[Inferior 1 (process 78776) exited with code 012]
(gdb)
所以我所做的是打开 gdb,在函数 f() 处设置断点,运行程序,然后在 f() 内停止时简单地发出继续命令。如果我现在做同样的事情但附加到已经运行的进程,我不能设置断点,并且在发出 continue 命令使进程在附加后继续时我也会收到错误。这是结果:
GNU gdb (GDB) 7.6
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin13.0.0".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
(gdb) attach 78794
Attaching to process 78794
Reading symbols from /private/tmp/a.out...Reading symbols from /private/tmp/a.out.dSYM/Contents/Resources/DWARF/a.out...done.
done.
0x00007fff8516da3a in ?? ()
(gdb) break f
Cannot access memory at address 0x100000edc
(gdb) c
Continuing.
warning: Mach error at "darwin-nat.c:726" in function "void darwin_resume_thread(struct inferior *, darwin_thread_t *, int, int)": (os/kern) failure (0x5)
[Inferior 1 (process 78794) exited normally]
(gdb)
因此,首先,在附加时,gdb 不会提供有关代码中当前位置的任何信息(?? () 中的 0x00007fff8516da3a),这可能没问题,因为我很可能在进程处于 sleep 状态时停止了该进程() 函数。
但是,当我尝试在 f() 处设置断点时,出现“无法访问内存”错误,断点显然没有设置。事实上,当我发出 continue 命令时,该过程只是照常进行并终止而不会在 f() 处停止。
此外,在尝试继续时,我还会收到“Mach error at [...] (os/kern) failure (0x5)”。即使使用
设置断点也不起作用(gdb) break a.c:5
Cannot access memory at address 0x100000edc
我也尝试在网络和 stackoverflow 上进行搜索,但没有找到该问题的答案。感谢您的帮助。
最佳答案
我找到了解决问题的(不是很满意)解决方案。使用 MacPorts,我安装了苹果版的 GDB:
sudo port install gdb-apple
此版本的 GDB 能够附加到进程并正确设置断点,甚至在 Eclipse CDT 中也是如此。我发现的唯一缺陷是,在 Eclipse 中,我需要在附加到进程之前设置断点。如果我尝试在已经附加的情况下设置断点,则该过程将失败。我不知道为什么。
我希望这个答案可以帮助到别人,如果你们中的任何人找到更好的解决方案,我将很高兴知道。
关于c - Mac OS X Mavericks - gdb - 附加到进程时无法设置断点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21477094/
我从 git 克隆: git clone git://git.apache.org/mesos.git 并且还做了 brew install autoconf automake libtool 然后尝
我已经在 Mavericks 上安装了 XQuartz 2.7.5。在那之后,我用 mplayer 播放的视频似乎加载到了一个单独的窗口中,所有白色都停留在播放音频上。我通过使用 launchctl
最近,我将我的 OS X 更新到了 10.9( Mavericks );不幸的是,尽管我将 Xcode 命令行更新为 OS X Mavericks 的 5.1.1,但 gfortran 停止工作。前段
尝试使用 Homebrew 软件在 mac os x mavericks 上安装 zlib-devel 不起作用: brew install zlib-devel Error: No availabl
更新:我看到有人尝试将 PyCharm 与 SSHFS 结合使用,而 JetBrains 说:“不”。也许这行不通? 我正在尝试在我工作的客户办公室的 SSHFS 安装磁盘上使用 WebStorm —
给定以下程序: #import int main(int argc, char *argv[]) { @autoreleasepool { NSDateFormatter *
我的快速查看生成器以前可以正常工作,但现在坏了。 这是一个错误还是我做错了什么? 这是我的代码: OSStatus GeneratePreviewForURL(void *thisInterface,
我很难让 PhpMyAdmin 在 Mavericks 上工作。 我通过取消注释/etc/apache2/httpd.conf 中的 LoadModule 指令在 apache 中启用了 PHP,我已
我知道还为时过早,但我已经升级到 OSX mavericks,我无法使用 Homebrew 安装 opencv。 ==> Installing dependencies for opencv:
我正在使用 vagrant Geodjango box 并且端口转发对我不起作用。 在盒子上,我运行了: python manage.py runserver 0.0.0.0:8000 但是 http
我一直在用 homebrew在 OSX Mavericks 上有一段时间了,但是我现在正在处理需要将文件添加到那些相同安装程序的文件夹中。 这是输入时的问题: $ brew info ant 我收到
我在前一周升级到 Mavericks,从那以后开始遇到 Homebrew 软件问题。 'brew doctor' 报告没有问题,但我目前正在尝试安装 Apache Thrift,但它失败了。有什么建议
我找不到任何关于此的信息,而且我从未对推送通知做过任何事情(但我模糊地知道它们是如何工作的)。在Mavericks中,既然OS X可以接收来自网站等各种事物的推送通知,那么iPhone模拟器可以接收推
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 9 年前。 Improve this ques
我有一个包含以下文本的 lldb 命令文件: settings set -- auto-confirm true breakpoint set --name main proc
我刚刚更新到 OS X Mavericks 中的命令行工具的最新版本,现在在编译我的(以前工作的)代码时,它会抛出以下错误 > clang: warning: no such sysroot dire
我正在尝试使用此脚本选择“Soundflower (2ch)”作为我的音频输出: tell application "System Preferences" activate set
在早期版本的 OS X 上,Applescript 如下: tell application "System Events" to tell process "Google Chrome" get p
我正在尝试在Genymotion中安装Google Play。但是,当我将zip放到仿真器中时,它会将文件保存在/sd.../中,而不是将其闪烁。我如何获得zip闪存? 最佳答案 如果您使用的是Mac
我的 Java 应用程序有一个构建在另一台服务器计算机上的应用程序。该服务器机器现已升级为 Mavericks + xcode 5.1。早些时候,我遇到了未使用 Mavericks + xcode 5
我是一名优秀的程序员,十分优秀!