简体   繁体   English

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

[英]How to display CGAL exceptions in command line lldb

I usually debug my code by hand, but I am trying to use lldb to debug a CGAL project. 我通常手动调试代码,但是我试图使用lldb调试CGAL项目。 Therefore, this is a newbie lldb question. 因此,这是一个新手lldb问题。 The following code causes an exception (that is the expected behavior). 以下代码导致异常(这是预期的行为)。 When I compile and run the following code in Xcode (using os-x's built-in clang compiler) 当我在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;
}

I get the following information: 我得到以下信息:

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) 

I would like to know how to get the same information from lldb on the command line. 我想知道如何在命令行上从lldb获取相同的信息。

I don't know quite what you want to get. 我不知道你想得到什么。 You can get lldb to stop at the point where the exception is going to be thrown by setting a breakpoint on the exception throw: 通过在异常引发上设置断点,可以使lldb停止在将引发异常的位置:

(lldb) break set -n __cxa_throw

Then you will stop in the debugger at the point where the the exception is about to be delivered. 然后,您将在调试器中将要交付异常的位置停止。 It is often helpful to see the context for the exception. 查看异常的上下文通常会很有帮助。 Note that if the library you are working with or your own code uses exceptions a lot it might get tedious to wade through all the unrelated hits... If you just want to see the backtrace, you can put a command on the breakpoint that prints the backtrace and continues. 请注意,如果您正在使用的库或您自己的代码使用大量异常,则遍历所有不相关的匹配项可能会很乏味……如果您只想查看回溯,则可以在要打印的断点上放置命令回溯并继续。 The last one printed will be the interesting one... Do this like: 最后打印的将是有趣的一个。

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

This adds a command to the last set breakpoint (specify the breakpoint number as an argument to the command if it wasn't the last one.) 这会将命令添加到最后一个设置的断点(如果断点号不是最后一个,则将其指定为命令的参数。)

Note, it's most likely the error text is just consed up and printed out by the checker code before throwing the error. 请注意,最有可能在抛出错误之前,错误代码只是被错误代码检查并打印出来。 The debugger has no way of knowing this is a special thing, the best it can do is print it to the console along with all other text going to stderr... 调试器无法知道这是一件特殊的事情,它能做的最好的事情就是将它与其他所有要发送到stderr的文本一起打印到控制台上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM