[Bug tools/28043] New: Add LSDA decoding to eu-readelf

2021-07-01 Thread woodard at redhat dot com via Elfutils-devel
https://sourceware.org/bugzilla/show_bug.cgi?id=28043

Bug ID: 28043
   Summary: Add LSDA decoding to eu-readelf
   Product: elfutils
   Version: unspecified
Status: NEW
  Severity: normal
  Priority: P2
 Component: tools
  Assignee: unassigned at sourceware dot org
  Reporter: woodard at redhat dot com
CC: elfutils-devel at sourceware dot org
  Target Milestone: ---

One thing that is an important aspect of compatibility between libraries and
their consumers (apps and other libraries) are the exceptions thrown and
caught. Ideally you want to make sure that all exceptions that could be thrown
are properly caught

Unfortunately it is currently EXTREMELY difficult to look at an ELF file see
which exceptions are thrown or caught. That information is readily available in
the ELF file it just isn't being decoded. This forces a user to manually
interpret the ELF file and decode the LSDA by hand to list the types. This is
very likely above the level of most developers. It would be nice if eu-readelf
were able to decode the LSDA and print it in a human understandable form.

I propose a feature that does this:

eu-readelf --exceptions-thrown 
eu-readelf --exceptions-caught 

and maybe:

eu-readelf --exceptions

which effectively is the same as eu-readelf --exceptions-thrown
--exceptions-caught

So far the best descriptions of how to decode those sections that I have been
able to find are: 
https://www.airs.com/blog/archives/464 and
http://www.hexblog.com/wp-content/uploads/2012/06/Recon-2012-Skochinsky-Compiler-Internals.pdf
(start at about page 35)
The code that processes that section in GCC can be found in
gcc/libgcc/unwind-c.c that could be a good reference.

Once you have the LSDA decoding capabilities it may also be worthwhile to print
out the decoded fields when doing --debug-dump=frame and pretty print the
structures pointed to by the LSDA pointers.

There is a possibility that at least at times llvm generates a different
version of the LSDA and so for a fully functional tool you may also want to
decode any flavors of LSDA that llvm may generate as well.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

[Bug tools/28043] Add LSDA decoding to eu-readelf

2021-07-01 Thread woodard at redhat dot com via Elfutils-devel
https://sourceware.org/bugzilla/show_bug.cgi?id=28043

--- Comment #1 from Ben Woodard  ---
Having code or maybe even an API that decodes the LSDA would also be helpful
for elfutils-libs users like libabigail as they work to resolve issues like:
https://sourceware.org/bugzilla/show_bug.cgi?id=28025

-- 
You are receiving this mail because:
You are on the CC list for the bug.

PR27711

2021-07-01 Thread Noah Sanci via Elfutils-devel
diff --git a/debuginfod/ChangeLog b/debuginfod/ChangeLog
index 286c910a..5afbafcd 100644
--- a/debuginfod/ChangeLog
+++ b/debuginfod/ChangeLog
@@ -1,3 +1,8 @@
+2021-07-01  Noah Sanci 
+   PR27711
+   * debuginfod.cxx (groom): Allowed the use of regexes during the
+   grooming process.
+
 2021-06-03  Frank Ch. Eigler 

PR27863
diff --git a/debuginfod/debuginfod.cxx b/debuginfod/debuginfod.cxx
index 543044c6..4f7fd2d5 100644
--- a/debuginfod/debuginfod.cxx
+++ b/debuginfod/debuginfod.cxx
@@ -360,6 +360,7 @@ static const struct argp_option options[] =
{ "database", 'd', "FILE", 0, "Path to sqlite database.", 0 },
{ "ddl", 'D', "SQL", 0, "Apply extra sqlite ddl/pragma to connection.", 0 },
{ "verbose", 'v', NULL, 0, "Increase verbosity.", 0 },
+   { "regex-groom", 'r', NULL, 0,"Uses regexes from -I and -X
arguments to groom the database.",0},
 #define ARGP_KEY_FDCACHE_FDS 0x1001
{ "fdcache-fds", ARGP_KEY_FDCACHE_FDS, "NUM", 0, "Maximum number
of archive files to keep in fdcache.", 0 },
 #define ARGP_KEY_FDCACHE_MBS 0x1002
@@ -407,6 +408,7 @@ static map scan_archives;
 static vector extra_ddl;
 static regex_t file_include_regex;
 static regex_t file_exclude_regex;
+static bool regex_groom = false;
 static bool traverse_logical;
 static long fdcache_fds;
 static long fdcache_mbs;
@@ -527,6 +529,9 @@ parse_opt (int key, char *arg,
   if (rc != 0)
 argp_failure(state, 1, EINVAL, "regular expression");
   break;
+case 'r':
+  regex_groom = true;
+  break;
 case ARGP_KEY_FDCACHE_FDS:
   fdcache_fds = atol (arg);
   break;
@@ -3249,8 +3254,11 @@ void groom()
   int64_t fileid = sqlite3_column_int64 (files, 1);
   const char* filename = ((const char*) sqlite3_column_text
(files, 2) ?: "");
   struct stat s;
+  bool reg_include = !regexec (&file_include_regex, filename, 0, 0, 0);
+  bool reg_exclude = !regexec (&file_exclude_regex, filename, 0, 0, 0);
+
   rc = stat(filename, &s);
-  if (rc < 0 || (mtime != (int64_t) s.st_mtime))
+  if ( (regex_groom && reg_exclude && !reg_include) ||  rc < 0 ||
(mtime != (int64_t) s.st_mtime) )
 {
   if (verbose > 2)
 obatched(clog) << "groom: forgetting file=" << filename
<< " mtime=" << mtime << endl;
@@ -3261,7 +3269,6 @@ void groom()
 }
   else
 inc_metric("groomed_total", "decision", "fresh");
-
   if (sigusr1 != forced_rescan_count) // stop early if scan triggered
 break;
 }
diff --git a/doc/debuginfod.8 b/doc/debuginfod.8
index 1ba42cf6..1adf703a 100644
--- a/doc/debuginfod.8
+++ b/doc/debuginfod.8
@@ -159,6 +159,9 @@ scan, independent of the rescan time (including if
it was zero),
 interrupting a groom pass (if any).

 .TP
+.B "\-r"
+Apply the -I and -X during groom cycles, so that files excluded by
the regexes are removed from the index. These parameters are in
addition to what normally qualifies a file for grooming, not a
replacement.
+
 .B "\-g SECONDS" "\-\-groom\-time=SECONDS"
 Set the groom time for the index database.  This is the amount of time
 the grooming thread will wait after finishing a grooming pass before
diff --git a/tests/ChangeLog b/tests/ChangeLog
index d8fa97fa..346b9e6e 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,8 @@
+2021-07-01  Noah Sanci 
+   PR2711
+   * run-debuginfod-find.sh: Added test case for grooming the database
+   using regexes.
+
 2021-06-16  Frank Ch. Eigler 

* run-debuginfod-find.sh: Fix intermittent groom/stale failure,
diff --git a/tests/run-debuginfod-find.sh b/tests/run-debuginfod-find.sh
index 456dc2f8..bd78bf46 100755
--- a/tests/run-debuginfod-find.sh
+++ b/tests/run-debuginfod-find.sh
@@ -36,13 +36,14 @@ export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache
 PID1=0
 PID2=0
 PID3=0
+PID4=0

 cleanup()
 {
-  if [ $PID1 -ne 0 ]; then kill $PID1 || true; wait $PID1; fi
-  if [ $PID2 -ne 0 ]; then kill $PID2 || true; wait $PID2; fi
-  if [ $PID3 -ne 0 ]; then kill $PID3 || true; wait $PID3; fi
-
+  if [ $PID1 -ne 0 ]; then kill $PID1; wait $PID1; fi
+  if [ $PID2 -ne 0 ]; then kill $PID2; wait $PID2; fi
+  if [ $PID3 -ne 0 ]; then kill $PID3; wait $PID3; fi
+  if [ $PID4 -ne 0 ]; then kill $PID4; wait $PID4; fi
   rm -rf F R D L Z ${PWD}/foobar ${PWD}/mocktree
${PWD}/.client_cache* ${PWD}/tmp*
   exit_cleanup
 }
@@ -293,7 +294,7 @@ kill -USR1 $PID1
 wait_ready $PORT1 'thread_work_total{role="traverse"}' 3
 wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
 wait_ready $PORT1 'thread_busy{role="scan"}' 0
-
+cp $DB $DB.backup
 # Rerun same tests for the prog2 binary
 filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find -v
debuginfo $BUILDID2 2>vlog`
 cmp $filename F/prog2
@@ -705,4 +706,29 @@ DEBUGINFOD_URLS="file://${PWD}/mocktree/"
 filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find
source aabbccdd /my/path/main.c`
 cmp $filename ${local_dir}/main.c

-exit 0
+