public inbox for libabigail@sourceware.org
 help / color / mirror / Atom feed
From: "Guillermo E. Martinez" <guillermo.e.martinez@oracle.com>
To: libabigail@sourceware.org
Subject: [PATCH] ctf-reader: add support to looks for debug information to extract kABI
Date: Fri,  8 Jul 2022 08:47:25 -0500	[thread overview]
Message-ID: <20220708134725.188383-1-guillermo.e.martinez@oracle.com> (raw)

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


             reply	other threads:[~2022-07-08 13:47 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-08 13:47 Guillermo E. Martinez [this message]
2022-07-11 11:50 ` Dodji Seketeli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220708134725.188383-1-guillermo.e.martinez@oracle.com \
    --to=guillermo.e.martinez@oracle.com \
    --cc=libabigail@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).