如何在命令行 lldb 中显示 CGAL 异常

How to display CGAL exceptions in command line lldb

我通常手动调试我的代码,但我正在尝试使用 lldb 来调试 CGAL 项目。因此,这是一个新手 lldb 问题。以下代码导致异常(这是预期的行为)。当我编译 运行 Xcode 中的以下代码时(使用 os-x 的内置 clang 编译器)

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Polygon_with_holes_2.h>
#include <CGAL/Boolean_set_operations_2.h>

typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Point_2<K> Point;
typedef CGAL::Polygon_2<K> Polygon_2;
typedef CGAL::Polygon_with_holes_2<K> Polygon_with_holes_2;

int main(){
    Polygon_2 p,q;
    Polygon_with_holes_2 r;

p.push_back(Point(0,0));
p.push_back(Point(1,0));
p.push_back(Point(1,1));

q.push_back(Point(0,0));
q.push_back(Point(0,1));
q.push_back(Point(1,1));

CGAL::join(p,q,r);

return 0;
}

我得到以下信息:

CGAL warning: check violation!
Expression : valid_orientation
File       : /opt/local/include/CGAL/Boolean_set_operations_2/Gps_polygon_validation.h
Line       : 310
Explanation: The polygon has a wrong orientation.
Refer to the bug-reporting instructions at http://www.cgal.org/bug_report.html
CGAL error: precondition violation!
Expression : is_valid_unknown_polygon(p, t)
File       : /opt/local/include/CGAL/General_polygon_set_on_surface_2.h
Line       : 45
Explanation: 
Refer to the bug-reporting instructions at http://www.cgal.org/bug_report.html
libc++abi.dylib: terminating with uncaught exception of type CGAL::Precondition_exception: CGAL ERROR: precondition violation!
Expr: is_valid_unknown_polygon(p, t)
File: /opt/local/include/CGAL/General_polygon_set_on_surface_2.h
Line: 45
(lldb) 

我想知道如何在命令行上从 lldb 获取相同的信息。

我不太清楚你想要得到什么。您可以通过在异常抛出处设置断点来让 lldb 在将要抛出异常的点停止:

(lldb) break set -n __cxa_throw

然后您将在调试器中停止在即将传递异常的位置。查看异常的上下文通常很有帮助。请注意,如果您正在使用的库或您自己的代码大量使用异常,那么浏览所有不相关的命中可能会变得乏味......如果您只想查看回溯,您可以在打印的断点上放置一个命令回溯并继续。最后打印的将是有趣的...这样做:

(lldb) br comm add
Enter your debugger command(s).  Type 'DONE' to end.
> bt 
> continue 
> DONE

这会向最后设置的断点添加一个命令(如果不是最后一个,请将断点编号指定为命令的参数。)

请注意,错误文本很可能是在抛出错误之前由检查代码整理并打印出来的。调试器无法知道这是一件特殊的事情,它能做的最好的事情就是将它与所有其他要发送到 stderr 的文本一起打印到控制台...