[PATCH 10/17] tapsets: format verbose probe addresses off the shared stream

Aaron Merey amerey@redhat.com
Mon Nov 23 04:14:24 GMT 2026


SDT workers printing verbose probe addresses change the numeric base
of the same stream. Format each address before writing it to clog or
cout so the shared formatting flags stay untouched.

  WARNING: ThreadSanitizer: data race
    Write of size 4 at 0x0000009b1f80 by thread T20:
      #1 dec ... ios_base.h:1096
      #3 sdt_query::handle_probe_entry() ... tapsets.cxx:9343
    Previous write of size 4 at 0x0000009b1f80 by thread T19:
      #0 setf ... ios_base.h:107
      #3 sdt_query::handle_probe_entry() ... tapsets.cxx:9343

Assisted-by: Codex <noreply@openai.com>
---
 dwflpp.cxx    | 13 ++++++-------
 setupdwfl.cxx |  6 ++----
 staputil.h    |  6 ++++--
 tapsets.cxx   | 24 ++++++++++++------------
 4 files changed, 24 insertions(+), 25 deletions(-)

diff --git a/dwflpp.cxx b/dwflpp.cxx
index 2da2296e6..42d087df2 100644
--- a/dwflpp.cxx
+++ b/dwflpp.cxx
@@ -2088,8 +2088,7 @@ dwflpp::get_cu_lines_sorted_by_lineno(const char *srcfile)
          {
            clog << _F("found the following lines for %s:", src.c_str()) << endl;
            for (auto i  = lines->begin(); i != lines->end(); ++i)
-             cout << DWARF_LINENO(*i) << " = " << hex
-                  << DWARF_LINEADDR(*i) << dec << endl;
+             cout << DWARF_LINENO(*i) << " = " << lex_cast_hex(DWARF_LINEADDR(*i), false) << endl;
          }
        return lines;
      });
@@ -2994,7 +2993,7 @@ dwflpp::resolve_prologue_endings (func_info_map_t & funcs)
           if (DWARF_LINEPROLOGUEEND(postprologue_srcline))
             clog << _(" (marked)");
 
-          clog << " = 0x" << hex << postprologue_addr << dec << "\n";
+          clog << " = 0x" << lex_cast_hex(postprologue_addr, false) << "\n";
         }
 
     } // loop over functions
@@ -5422,8 +5421,8 @@ dwflpp::get_cfa_ops (Dwarf_Addr pc)
   Dwarf_Op *cfa_ops = NULL;
 
   if (sess.verbose > 2)
-    clog << "get_cfa_ops @0x" << hex << pc << dec
-	 << ", foc().module_start @0x" << hex << foc().module_start << dec << endl;
+    clog << "get_cfa_ops @0x" << lex_cast_hex(pc, false)
+	 << ", foc().module_start @0x" << lex_cast_hex(foc().module_start, false) << endl;
 
   // Try debug_frame first, then fall back on eh_frame.
   size_t cfa_nops = 0;
@@ -5433,7 +5432,7 @@ dwflpp::get_cfa_ops (Dwarf_Addr pc)
   if (cfi != NULL)
     {
       if (sess.verbose > 3)
-	clog << "got dwarf cfi bias: 0x" << hex << bias << dec << endl;
+	clog << "got dwarf cfi bias: 0x" << lex_cast_hex(bias, false) << endl;
       if (dwarf_cfi_addrframe (cfi, pc - bias, &frame) == 0)
 	dwarf_frame_cfa (frame, &cfa_ops, &cfa_nops);
       else if (sess.verbose > 3)
@@ -5448,7 +5447,7 @@ dwflpp::get_cfa_ops (Dwarf_Addr pc)
       if (cfi != NULL)
 	{
 	  if (sess.verbose > 3)
-	    clog << "got eh cfi bias: 0x" << hex << bias << dec << endl;
+	    clog << "got eh cfi bias: 0x" << lex_cast_hex(bias, false) << endl;
 	  Dwarf_Frame *frame = NULL;
 	  if (dwarf_cfi_addrframe (cfi, pc - bias, &frame) == 0)
 	    dwarf_frame_cfa (frame, &cfa_ops, &cfa_nops);
diff --git a/setupdwfl.cxx b/setupdwfl.cxx
index 63f467e18..c55266101 100644
--- a/setupdwfl.cxx
+++ b/setupdwfl.cxx
@@ -794,10 +794,8 @@ setup_dwfl_kernel (unsigned *modules_found, systemtap_session &s)
           (void) dwfl_module_info (kmod, NULL, &start, &end, NULL, NULL,
                                    &mainf, &dbgf);
           if (elf != NULL && dw != NULL)
-            // NB: this function also has a local string named hex (build-id).
             clog << _("Opened kernel ELF+DWARF ")
-                 << "[" << std::hex << std::showbase << start << "-" << end
-                 << std::noshowbase << std::dec << "] "
+                 << "[" << lex_cast_hex (start) << "-" << lex_cast_hex (end) << "] "
                  << (mainf ?: dbgf ?: "?") << endl;
           else
             clog << _F("Kernel ELF/DWARF still missing after build-id lookup: %s",
@@ -1575,7 +1573,7 @@ build_id_from_raw_notes (const vector<unsigned char> &blob,
         clog << "  " << cands[i].hex
              << " owner_size=" << cands[i].owner_size
              << " score=" << cands[i].score
-             << " @" << hex << cands[i].off << dec << endl;
+             << " @" << lex_cast_hex(cands[i].off, false) << endl;
     }
 
   // Require either a dominant owner (the flat image itself) or some
diff --git a/staputil.h b/staputil.h
index 6dee9cbc5..56dc67cbb 100644
--- a/staputil.h
+++ b/staputil.h
@@ -229,10 +229,12 @@ inline uint8_t lex_cast(std::string const & in)
 
 template <typename IN>
 inline std::string
-lex_cast_hex(IN const & in)
+lex_cast_hex(IN const & in, bool showbase = true)
 {
   std::ostringstream ss;
-  if (!(ss << std::showbase << std::hex << in << std::dec))
+  if (showbase)
+    ss << std::showbase;
+  if (!(ss << std::hex << in << std::dec))
     throw std::runtime_error(_("bad lexical cast"));
   return ss.str();
 }
diff --git a/tapsets.cxx b/tapsets.cxx
index e7f39b85a..0ca618fad 100644
--- a/tapsets.cxx
+++ b/tapsets.cxx
@@ -1929,7 +1929,7 @@ dwarf_query::add_probe_point(interned_string dw_funcname,
       else if (has_process)
         clog << _(" process=") << module;
       if (reloc_section != "") clog << " reloc=" << reloc_section;
-      clog << " pc=0x" << hex << addr << dec;
+      clog << " pc=0x" << lex_cast_hex(addr, false);
     }
 
   dwflpp::blocklisted_type blocklisted = dw.blocklisted_p (funcname, filename,
@@ -2489,7 +2489,7 @@ query_addr(Dwarf_Addr addr, dwarf_query *q)
   uint64_t t0 = 0;
 
   if (q->sess.verbose > 2)
-    clog << "query_addr 0x" << hex << addr << dec << endl;
+    clog << "query_addr 0x" << lex_cast_hex(addr, false) << endl;
 
   // First pick which CU contains this address
   if (time_p) t0 = dwarf_timing_now_ns ();
@@ -2635,7 +2635,7 @@ query_plt_statement(dwarf_query *q)
 
   Dwarf_Addr addr = q->statement_num_val;
   if (q->sess.verbose > 2)
-    clog << "query_plt_statement 0x" << hex << addr << dec << endl;
+    clog << "query_plt_statement 0x" << lex_cast_hex(addr, false) << endl;
 
   // First adjust the raw address to dwfl's elf bias.
   Dwarf_Addr elf_bias;
@@ -9334,13 +9334,13 @@ sdt_query::handle_probe_entry()
       switch (probe_type)
 	{
 	case uprobe1_type:
-	  clog << "uprobe1 at 0x" << hex << pc << dec << endl;
+	  clog << "uprobe1 at 0x" << lex_cast_hex(pc, false) << endl;
 	  break;
 	case uprobe2_type:
-	  clog << "uprobe2 at 0x" << hex << pc << dec << endl;
+	  clog << "uprobe2 at 0x" << lex_cast_hex(pc, false) << endl;
 	  break;
 	case uprobe3_type:
-	  clog << "uprobe3 at 0x" << hex << pc << dec << endl;
+	  clog << "uprobe3 at 0x" << lex_cast_hex(pc, false) << endl;
 	  break;
 	default:
 	  clog << "unknown!" << endl;
@@ -9606,7 +9606,7 @@ sdt_query::setup_note_probe_entry (const string& scn_name,
   semaphore += bias;
 
   if (sess.verbose > 4)
-    clog << _F(" saw .note.stapsdt %s%s ", probe_name.c_str(), (provider_name != "" ? _(" (provider ")+provider_name+") " : "").c_str()) << "@0x" << hex << pc << dec << endl;
+    clog << _F(" saw .note.stapsdt %s%s ", probe_name.c_str(), (provider_name != "" ? _(" (provider ")+provider_name+") " : "").c_str()) << "@0x" << lex_cast_hex(pc, false) << endl;
 
   handle_probe_entry();
 }
@@ -9666,7 +9666,7 @@ sdt_query::iterate_over_probe_entries()
 	}
       if (sess.verbose > 4)
 	clog << _("saw .probes ") << probe_name << (provider_name != "" ? _(" (provider ")+provider_name+") " : "")
-	     << "@0x" << hex << pc << dec << endl;
+	     << "@0x" << lex_cast_hex(pc, false) << endl;
 
       focus.mod_info->marks.insert(make_pair(provider_name, probe_name));
 
@@ -9706,7 +9706,7 @@ sdt_query::record_semaphore (vector<derived_probe *> & results, unsigned start)
         for (unsigned i = start; i < results.size(); ++i)
           results[i]->sdt_semaphore_addr = addr;
         if (sess.verbose > 2)
-          clog << _(", found at 0x") << hex << addr << dec << endl;
+          clog << _(", found at 0x") << lex_cast_hex(addr, false) << endl;
         return;
       }
     else
@@ -9763,15 +9763,15 @@ sdt_query::convert_location ()
 	    {
 	    case uprobe1_type:
               clog << _("probe_type == uprobe1, use statement addr: 0x")
-		   << hex << pc << dec << endl;
+		   << lex_cast_hex(pc, false) << endl;
 	      break;
 	    case uprobe2_type:
               clog << _("probe_type == uprobe2, use statement addr: 0x")
-		   << hex << pc << dec << endl;
+		   << lex_cast_hex(pc, false) << endl;
             break;
 	    case uprobe3_type:
               clog << _("probe_type == uprobe3, use statement addr: 0x")
-		   << hex << pc << dec << endl;
+		   << lex_cast_hex(pc, false) << endl;
 	      break;
 	    default:
               clog << _F("probe_type == use_uprobe_no_dwarf, use label name: _stapprobe1_%s",
-- 
2.56.1



More information about the Systemtap mailing list