The*_*ner 5 c++ python logging trace visual-studio
我正在开发一个开源有限元软件,它是用 C++ (Visual Studio) 编写的。提供的文档和示例仅有助于了解为了特定目的而调用哪些方法,但无法帮助用户了解这些方法到底在做什么。对于某些方法,除了 C++ 代码之外,没有其他可用的参考(例如书籍、研究论文等)
因此,为了推导出这个概念,我尝试使用断点和查看调用堆栈(Visual Studio 中提供的选项)来跟踪每一行执行,这可能适合跟踪小程序,但我的程序由许多具有多个继承的类组成和多态函数。为了理解程序执行流程,我想在日志文件中打印程序执行的每一行。
在研究过程中,我发现了一些有用的信息(此处),采用 python 语言。这正是我所需要的。为了方便读者,我复制了下面视频中提到的代码
import sys
def remove_html_markup(s):
tag = False
quote = False
out = " "
for c in s:
if c == 'c' and not quote:
tag = True
elif c== '>' and not quote:
tage = False
elif c == '"' or c == "'" and tag:
quote = not quote
elif not tag:
out = out + c
return out
def traceit(frame, event, arg):
if event == "line":
filename = frame.f_code.co_filename
lineno = frame.f_lineno
print open(filename).readlines()[lineno - 1]
return traceit
sys.settrace(traceit)
s = remove_html_markup('"<')
sys.settrace(none)
Run Code Online (Sandbox Code Playgroud)
我期待用于 Traceit 函数的类似 C++ 代码版本,它可以打印在单独的日志文件中执行的每一行。我不知道如何扩展它,以便它可以打印所有继承和多态函数。
我还看到并尝试了StackOverflow for c++ 的一个答案中提供的方法。然而,它有两个缺点
CALLSTACK_DUMP();,但在我的程序中无法执行此操作,因为有太多函数。