gcc gprof/gcov/other - how to get sequence of function calls/exits + control flow statements

给你一囗甜甜゛ 提交于 2019-12-11 05:06:44

问题


BACKGROUND

We have testers for our embedded GUI product and when a tester declares "test failed", sometimes it's hard for us developers to reproduce the exact problem because we don't have the exact trace of what happened.

We do currently have a logging framework but us devs have to manually input those logging statements in the code which is fine . . . except when a hard-to-reproduce bug occurs and we didn't have a log statement at the 'right' location and then when we re-build, re-run the test with the same steps, we get a different result.

ISSUE

We would like a solution wherein the compiler produces extra instrumentation code that allows us to see the exact sequence of events including, at the minimum:

  1. function enter/exit (already provided by -finstrument-functions)
  2. control-flow statement enter i.e. entering if/else, which case statement we jumped to

The log would look like this:

int main() entered
if-line 5 entered
else-line 10 entered
void EventLoop() entered
. . .

Some additional nice-to-haves are

  1. Parameter values on function entry AND exit (for pass-by-reference types)
  2. Function return value

QUESTION

Are there any gcc tools or even paid tools that can do this instrumentation automatically?


回答1:


You can either use gdb for that, and you can automate that (I've got a tool for that in the works, you find it here or you can try to use gcov.

The gcov implementation is so, that it loads the latest gcov data when you start the program. But: you can manually dump and load the data. If you call __gcov_flush it will dump the current data and reset the current state. However: if you do that several times it will always merge the data, so you'd also need to rename the gcov data file then.



来源:https://stackoverflow.com/questions/39296202/gcc-gprof-gcov-other-how-to-get-sequence-of-function-calls-exits-control-flo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!