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

时间:2015-02-25 19:12:23

标签: c++ exception clang lldb cgal

我通常手动调试我的代码,但我试图使用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获取相同的信息。

1 个答案:

答案 0 :(得分:0)

我不知道你想要得到什么。你可以通过在异常抛出上设置断点来使lldb停止在将抛出异常的位置:

(lldb) break set -n __cxa_throw

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

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

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

注意,在抛出错误之前,错误文本很可能只是由检查器代码压缩并打印出来。调试器无法知道这是一件特别的事情,它能做的最好的事情是将它打印到控制台以及所有其他文本转到stderr ......