gpt4 book ai didi

c - OSX 10.11.6 lldb 说断点 1 : no locations (pending)

转载 作者:行者123 更新时间:2023-11-30 14:59:24 27 4
gpt4 key购买 nike

我在 OSX 上进行了 C、Make 和 lldb 的基本事件,但它似乎没有按照文档中的规定工作。学习“lldb”调试器的简单 C 编码练习是“Learning C The Hard Way”(Shaw,Zed A.,2015)中的练习 4,因此这是一个陈旧的、没有复杂性的示例,说明了应该如何进行工作。只有 OSX 的行为不像其手册和帮助页面所说的那样。

Makefile 中是否有根本性的缺失?文档给我的语法是否不正确?此版本的 OSX 或编译器或 lldb 是否存在错误?你能不能不在 OSX 上的 C 语言的 main() 方法上设置断点,这样这个练习就有根本性的缺陷并且两年内没有人注意到?

感谢您花时间查看...

这是整个用例输出:

My-MacBook-Pro:Exercises Me$ ls -als total 48
0 drwxr-xr-x 7 Me staff 238 Mar 12 20:56 .
0 drwxr-xr-x 8 Me staff 272 Feb 26 02:11 ..
24 -rw-r--r--@ 1 Me staff 10244 Mar 12 20:56 .DS_Store
0 drwxr-xr-x 5 Me staff 170 Mar 3 02:48 BonusContent
8 -rw-r--r--@ 1 Me staff 48 Mar 12 20:56 Makefile
8 -rw-r--r--@ 1 Me staff 322 Feb 28 00:50 ex1.c
8 -rw-r--r-- 1 v staff 184 Mar 12 19:53 ex3.c

My-MacBook-Pro:Exercises Me$ cat ex3.c
#include <stdio.h>

int main(int argc, char *argv[])
{
int age = 10;
int height = 72;
printf(" I am %d years old.\n", age);
printf(" I am %d inches tall.\n", height);
return 0;
}

My-MacBook-Pro:Exercises Me$ cat Makefile
CFLAGS=-Wall -g

all: ex3

clean:
rm -f ex3

My-MacBook-Pro:Exercises Me$ make ex3
cc -Wall -g ex3.c -o ex3
My-MacBook-Pro:Exercises Me$

My-MacBook-Pro:Exercises Me$ lldb ex3
(lldb) target create "ex3"
Current executable set to 'ex3' (x86_64).
(lldb) breakpoint set --method main
Breakpoint 1: no locations (pending).
WARNING: Unable to resolve breakpoint to any actual locations.
(lldb)

My-MacBook-Pro:Exercises Me$ ls -als
total 72
0 drwxr-xr-x 9 Me staff 306 Mar 12 20:57 .
0 drwxr-xr-x 8 Me staff 272 Feb 26 02:11 ..
24 -rw-r--r--@ 1 Me staff 10244 Mar 12 20:57 .DS_Store
0 drwxr-xr-x 5 Me staff 170 Mar 3 02:48 BonusContent
8 -rw-r--r--@ 1 Me staff 48 Mar 12 20:56 Makefile
8 -rw-r--r--@ 1 Me staff 322 Feb 28 00:50 ex1.c
24 -rwxr-xr-x 1 Me staff 8712 Mar 12 20:57 ex3
8 -rw-r--r-- 1 Me staff 184 Mar 12 19:53 ex3.c
0 drwxr-xr-x 3 Me staff 102 Mar 12 20:57 ex3.dSYM

My-MacBook-Pro:Exercises Me$ sw_vers
ProductName: Mac OS X
ProductVersion: 10.11.6
BuildVersion: 15G1217
My-MacBook-Pro:Exercises Me$

My-MacBook-Pro:Exercises Me$ clang --version -g
Apple LLVM version 8.0.0 (clang-800.0.42.1)
Target: x86_64-apple-darwin15.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
My-MacBook-Pro:Exercises Me$

My-MacBook-Pro:Exercises Me$ make --version
GNU Make 3.81
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

This program built for i386-apple-darwin11.3.0
My-MacBook-Pro:Exercises Me$

My-MacBook-Pro:Exercises Me$ lldb --version
lldb-360.1.70

回复“奥拉夫”: LLDB Documentation

(lldb) breakpoint set --name main
(lldb) br s -n main
(lldb) b main

在旧版本的 OSX 上,还有另一个线程在 2015 年出现了类似的错误消息,但其“解决方案”不起作用,并且实际上根本不使用 Make 来忽略该问题。

我想尝试避免正交或复杂的“建议”,比如“你为什么不使用 C,尝试使用其他语言”,或者“我更喜欢使用不同的调试器,所以使用这个一”...这些不会回答问题:)

最佳答案

b 命令和breakpoint set 命令有很大不同。 b 是一个 DWIM 类型命令,它尽可能地尝试模拟 gdb 断点解析器的语法。它最终会使用适当的断点类型分派(dispatch)到中断集

breakpoint set -n foo 创建通用“符号名称匹配”断点。例如,它将匹配一个名为“foo”的函数或一个 ObjC 选择器“foo”或一个名为“foo”的 C++ 方法... b foo 分派(dispatch)到 breakpoint set -n foo

但有时您知道只想在类方法(C++ 或 Swift)上设置断点,在这种情况下您可以使用 --method 选项来适当限制搜索。 ObjC 选择器和 --selector 选项也是如此。

就您而言, --name 有效,但 --method 无效,这是正确的行为。你的 main 是一个纯 C 函数,而不是一个类方法。

顺便说一句,b实际上是一个lldb“正则表达式命令”,请参阅

(lldb) help command regex

了解更多详情。您可以通过打开回显正则表达式命令解析来查看该命令实际执行的操作:

(lldb) set set interpreter.expand-regex-aliases 1

然后尝试一些断点:

(lldb) b main
breakpoint set --name 'main'

(lldb) b foo.c:11
breakpoint set --file 'foo.c' --line 11

等等...

关于c - OSX 10.11.6 lldb 说断点 1 : no locations (pending),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42753523/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com