{"id":2757,"date":"2022-08-30T15:27:31","date_gmt":"2022-08-30T15:27:31","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/02\/08\/core-dump-and-gcov-coverage-report-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:27:31","modified_gmt":"2022-08-30T15:27:31","slug":"core-dump-and-gcov-coverage-report-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/core-dump-and-gcov-coverage-report-collection-of-common-programming-errors\/","title":{"rendered":"Core dump and gcov coverage report-Collection of common programming errors"},"content":{"rendered":"<p>If you have need to do regression testing of code coverage automatedly. Try this:<\/p>\n<p>https:\/\/www.osadl.org\/Dumping-gcov-data-at-runtime-simple-ex.online-coverage-analysis.0.html<\/p>\n<p>Inside your program&#8217;s &#8220;main.c&#8221; put:<\/p>\n<pre><code>static unsigned long long i = 0;\nvoid __gcov_flush(void); \/* check in gcc sources gcc\/gcov-io.h for the prototype *\/\n\nvoid my_handler(int signum)\n{\n  printf(\"received signal\\n\");\n  printf(\"%llu\\n\", i);\n  __gcov_flush(); \/* dump coverage data on receiving SIGUSR1 *\/\n}\n\nint main(int argc, char **argv)\n{\n  struct sigaction new_action, old_action;\n  int n;\n\n  \/* setup signal hander *\/\n  new_action.sa_handler = my_handler;\n  sigemptyset(&amp;new_action.sa_mask);\n  new_action.sa_flags = 0;\n\n  sigaction(SIGUSR1, NULL, &amp;old_action);\n  if (old_action.sa_handler != SIG_IGN)\n    sigaction (SIGUSR1, &amp;new_action, NULL);\n  \/\/blah......\n<\/code><\/pre>\n<p>Then re-build your program and run:<\/p>\n<pre><code>$ .\/hello &amp;\n$ killall -USR1 hello\nreceived signal\n2514147346\n<\/code><\/pre>\n<p>this way it should still generate .gcda files<\/p>\n<pre><code>$ gcov hello\nFile 'hello.c'\nLines executed:100.00% of 14\nhello.c:creating 'hello.c.gcov'\n<\/code><\/pre>\n<p id=\"rop\"><small>Originally posted 2014-02-08 15:59:51. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>If you have need to do regression testing of code coverage automatedly. Try this: https:\/\/www.osadl.org\/Dumping-gcov-data-at-runtime-simple-ex.online-coverage-analysis.0.html Inside your program&#8217;s &#8220;main.c&#8221; put: static unsigned long long i = 0; void __gcov_flush(void); \/* check in gcc sources gcc\/gcov-io.h for the prototype *\/ void my_handler(int signum) { printf(&#8220;received signal\\n&#8221;); printf(&#8220;%llu\\n&#8221;, i); __gcov_flush(); \/* dump coverage data on receiving SIGUSR1 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2757","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2757","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2757"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2757\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2757"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2757"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2757"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}