public inbox for libabigail@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] ctf-reader: add support to looks for debug information to extract kABI
@ 2022-07-08 13:47 Guillermo E. Martinez
  2022-07-11 11:50 ` Dodji Seketeli
  0 siblings, 1 reply; 2+ messages in thread
From: Guillermo E. Martinez @ 2022-07-08 13:47 UTC (permalink / raw)
  To: libabigail

Hello,

This patch update the ctf-reader in libabigail to allows use 
`--debug-info-dir' option to looks for `vmllinux.ctfa' and in this
way compare stand alone `vmlinux' file and `modules', as follows:

abidiff --ctf /path/to/[vmlinux|modulev1.ko] --d1 /path/to/vmlinux_ctfa_v1 \
   /path/to/[vmlinux|modulev2.ko] --d2 /path/to/vmlinux_ctfa_v2

Please let me know your thoughts

Thanks in advanced,
guillermo
---

abidiff tool is now able to looks for CTF debug information to extract
the kABI, it uses the standard `--debug-info-dir' option to locate
`vmlinux.ctfa`, looking at first instance in the base directory
where the ELF binary (vmlinux/module) is want to be processed.

	* src/abg-ctf-reader.cc (find_ctfa_file): Add new function
	meant to locate the Linux Kernel debug information file
	`vmlinux.ctfa'.
	(ctf_reader::read_corpus): Use `find_ctfa_file' function.

Signed-off-by: Guillermo E. Martinez <guillermo.e.martinez@oracle.com>
---
 src/abg-ctf-reader.cc | 47 ++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 42 insertions(+), 5 deletions(-)

diff --git a/src/abg-ctf-reader.cc b/src/abg-ctf-reader.cc
index 77e77d13..c1ea15aa 100644
--- a/src/abg-ctf-reader.cc
+++ b/src/abg-ctf-reader.cc
@@ -43,6 +43,8 @@ namespace abigail
 namespace ctf_reader
 {
 using std::dynamic_pointer_cast;
+using abigail::tools_utils::dir_name;
+using abigail::tools_utils::file_exists;
 
 class read_context
 {
@@ -1515,6 +1517,42 @@ slurp_elf_info(read_context *ctxt,
   status |= elf_reader::STATUS_OK;
 }
 
+/// Looks for vmlinux.ctfa file in default directory or in
+/// directories provided by debug-info-dir command line option,
+/// it stores location path in @ref ctfa_file.
+///
+/// @param ctxt the read context.
+/// @param ctfa_file file name found.
+/// @return true if file is found.
+static bool
+find_ctfa_file(read_context *ctxt, std::string& ctfa_file)
+{
+  std::string ctfa_dirname;
+  dir_name(ctxt->filename, ctfa_dirname, false);
+
+  // In corpus group we assume vmlinux as first file to
+  // be processed, so default location for vmlinux.cfa
+  // is vmlinux dirname.
+  ctfa_file = ctfa_dirname + "/vmlinux.ctfa";
+  if (file_exists(ctfa_file))
+    return true;
+
+  // If it's proccessing a module, then location directory
+  // for vmlinux.ctfa should be provided with --debug-info-dir
+  // option.
+  for (vector<char**>::const_iterator i = ctxt->debug_info_root_paths_.begin();
+       i != ctxt->debug_info_root_paths_.end();
+       ++i)
+    {
+      ctfa_dirname = **i;
+      ctfa_file = ctfa_dirname + "/vmlinux.ctfa";
+      if (file_exists(ctfa_file))
+        return true;
+    }
+
+  return false;
+}
+
 /// Create and return a new read context to process CTF information
 /// from a given ELF file.
 ///
@@ -1577,12 +1615,11 @@ read_corpus(read_context *ctxt, elf_reader::status &status)
   int errp;
   if (corp->get_origin() & corpus::LINUX_KERNEL_BINARY_ORIGIN)
     {
-      std::string filename;
-      if (tools_utils::base_name(ctxt->filename, filename)
-          && filename == "vmlinux")
+      if (ctxt->ctfa == NULL)
         {
-          std::string vmlinux_ctfa_path = ctxt->filename + ".ctfa";
-          ctxt->ctfa = ctf_arc_open(vmlinux_ctfa_path.c_str(), &errp);
+          std::string ctfa_filename;
+          if (find_ctfa_file(ctxt, ctfa_filename))
+            ctxt->ctfa = ctf_arc_open(ctfa_filename.c_str(), &errp);
         }
     }
   else
-- 
2.35.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-07-11 11:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-08 13:47 [PATCH] ctf-reader: add support to looks for debug information to extract kABI Guillermo E. Martinez
2022-07-11 11:50 ` Dodji Seketeli

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).