Merge revisions 14445 and 14446 from the BUF_REMOVAL branch to trunk.
Two things:
- remove the buffer argument from VG_(DebugInfo_sect_kind)
- allocate AddrInfo::SectKind::objname dynamically


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14719 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/callgrind/bb.c b/callgrind/bb.c
index 0dd1d33..b9b3812 100644
--- a/callgrind/bb.c
+++ b/callgrind/bb.c
@@ -141,7 +141,7 @@
    bb->jmp         = (CJmpInfo*) &(bb->instr[instr_count]);
    bb->instr_len   = 0;
    bb->cost_count  = 0;
-   bb->sect_kind   = VG_(DebugInfo_sect_kind)(NULL, 0, offset + obj->offset);
+   bb->sect_kind   = VG_(DebugInfo_sect_kind)(NULL, offset + obj->offset);
    bb->fn          = 0;
    bb->line        = 0;
    bb->is_entry    = 0;
diff --git a/coregrind/m_addrinfo.c b/coregrind/m_addrinfo.c
index 0cc29ef..8b364e2 100644
--- a/coregrind/m_addrinfo.c
+++ b/coregrind/m_addrinfo.c
@@ -203,17 +203,12 @@
    }
 
    /* -- last ditch attempt at classification -- */
-   vg_assert( sizeof(ai->Addr.SectKind.objname) > 4 );
-   VG_(memset)( &ai->Addr.SectKind.objname, 
-                0, sizeof(ai->Addr.SectKind.objname));
-   VG_(strcpy)( ai->Addr.SectKind.objname, "???" );
-   sect = VG_(DebugInfo_sect_kind)( &ai->Addr.SectKind.objname[0],
-                                    sizeof(ai->Addr.SectKind.objname)-1, a);
+   sect = VG_(DebugInfo_sect_kind)( &name, a);
+   ai->Addr.SectKind.objname = VG_(strdup)("mc.da.dsname", name);
+
    if (sect != Vg_SectUnknown) {
       ai->tag = Addr_SectKind;
       ai->Addr.SectKind.kind = sect;
-      vg_assert( ai->Addr.SectKind.objname
-                    [ sizeof(ai->Addr.SectKind.objname)-1 ] == 0);
       return;
    }
 
@@ -305,6 +300,7 @@
          break;
 
       case Addr_SectKind:
+         VG_(free)(ai->Addr.SectKind.objname);
          break;
 
       default:
diff --git a/coregrind/m_debuginfo/debuginfo.c b/coregrind/m_debuginfo/debuginfo.c
index 11e2037..217f1d1 100644
--- a/coregrind/m_debuginfo/debuginfo.c
+++ b/coregrind/m_debuginfo/debuginfo.c
@@ -4274,12 +4274,11 @@
 }
 
 /* Given an address 'a', make a guess of which section of which object
-   it comes from.  If name is non-NULL, then the last n_name-1
-   characters of the object's name is put in name[0 .. n_name-2], and
-   name[n_name-1] is set to zero (guaranteed zero terminated). */
-
-VgSectKind VG_(DebugInfo_sect_kind)( /*OUT*/HChar* name, SizeT n_name, 
-                                     Addr a)
+   it comes from.  If name is non-NULL, then the object's name is put
+   in *name. The returned name, if any, should be saved away, if there is
+   a chance that a debug-info will be discarded and the name is being
+   used later on. */
+VgSectKind VG_(DebugInfo_sect_kind)( /*OUT*/const HChar** name, Addr a)
 {
    DebugInfo* di;
    VgSectKind res = Vg_SectUnknown;
@@ -4357,29 +4356,11 @@
               || (di != NULL && res != Vg_SectUnknown) );
 
    if (name) {
-
-      vg_assert(n_name >= 8);
-
       if (di && di->fsm.filename) {
-         Int i, j;
-         Int fnlen = VG_(strlen)(di->fsm.filename);
-         Int start_at = 1 + fnlen - n_name;
-         if (start_at < 0) start_at = 0;
-         vg_assert(start_at < fnlen);
-         i = start_at; j = 0;
-         while (True) {
-            vg_assert(j >= 0 && j < n_name);
-            vg_assert(i >= 0 && i <= fnlen);
-            name[j] = di->fsm.filename[i];
-            if (di->fsm.filename[i] == 0) break;
-            i++; j++;
-         }
-         vg_assert(i == fnlen);
+         *name = di->fsm.filename;
       } else {
-         VG_(snprintf)(name, n_name, "%s", "???");
+         *name = "???";
       }
-
-      name[n_name-1] = 0;
    }
 
    return res;
diff --git a/drd/drd_error.c b/drd/drd_error.c
index e3df0b5..c510b88 100644
--- a/drd/drd_error.c
+++ b/drd/drd_error.c
@@ -221,11 +221,10 @@
       if (xml)
          print_err_detail("  </allocation_context>\n");
    } else {
-      HChar sect_name[64];
+      const HChar *sect_name;
       VgSectKind sect_kind;
 
-      sect_kind = VG_(DebugInfo_sect_kind)(sect_name, sizeof(sect_name),
-                                           dri->addr);
+      sect_kind = VG_(DebugInfo_sect_kind)(&sect_name, dri->addr);
       if (sect_kind != Vg_SectUnknown) {
          print_err_detail("%sAllocation context: %ps section of %ps%s\n",
                           auxwhat_prefix, VG_(pp_SectKind)(sect_kind),
diff --git a/drd/drd_load_store.c b/drd/drd_load_store.c
index a7928d5..95e9f42 100644
--- a/drd/drd_load_store.c
+++ b/drd/drd_load_store.c
@@ -624,7 +624,7 @@
          /* relocated in another way than by later binutils versions. The  */
          /* linker e.g. does not generate .got.plt sections on CentOS 3.0. */
       case Ist_IMark:
-         instrument = VG_(DebugInfo_sect_kind)(NULL, 0, st->Ist.IMark.addr)
+         instrument = VG_(DebugInfo_sect_kind)(NULL, st->Ist.IMark.addr)
             != Vg_SectPLT;
          addStmtToIRSB(bb, st);
          break;
diff --git a/drd/drd_main.c b/drd/drd_main.c
index a24588b..0960fe5 100644
--- a/drd/drd_main.c
+++ b/drd/drd_main.c
@@ -447,7 +447,7 @@
           VG_(strcmp)(VG_(DebugInfo_get_soname)(di), "libpthread.so.0") == 0) {
 	 if (trace_sectsuppr)
 	    VG_(dmsg)("Suppressing .bss @ 0x%lx size %ld\n", avma, size);
-         tl_assert(VG_(DebugInfo_sect_kind)(NULL, 0, avma) == Vg_SectBSS);
+         tl_assert(VG_(DebugInfo_sect_kind)(NULL, avma) == Vg_SectBSS);
          DRD_(start_suppression)(avma, avma + size, ".bss");
       }
 
@@ -457,7 +457,7 @@
       if (size > 0) {
 	 if (trace_sectsuppr)
 	    VG_(dmsg)("Suppressing .plt @ 0x%lx size %ld\n", avma, size);
-         tl_assert(VG_(DebugInfo_sect_kind)(NULL, 0, avma) == Vg_SectPLT);
+         tl_assert(VG_(DebugInfo_sect_kind)(NULL, avma) == Vg_SectPLT);
          DRD_(start_suppression)(avma, avma + size, ".plt");
       }
 
@@ -467,7 +467,7 @@
       if (size > 0) {
 	 if (trace_sectsuppr)
 	    VG_(dmsg)("Suppressing .got.plt @ 0x%lx size %ld\n", avma, size);
-         tl_assert(VG_(DebugInfo_sect_kind)(NULL, 0, avma) == Vg_SectGOTPLT);
+         tl_assert(VG_(DebugInfo_sect_kind)(NULL, avma) == Vg_SectGOTPLT);
          DRD_(start_suppression)(avma, avma + size, ".gotplt");
       }
 
@@ -477,7 +477,7 @@
       if (size > 0) {
 	 if (trace_sectsuppr)
 	    VG_(dmsg)("Suppressing .got @ 0x%lx size %ld\n", avma, size);
-         tl_assert(VG_(DebugInfo_sect_kind)(NULL, 0, avma) == Vg_SectGOT);
+         tl_assert(VG_(DebugInfo_sect_kind)(NULL, avma) == Vg_SectGOT);
          DRD_(start_suppression)(avma, avma + size, ".got");
       }
    }
diff --git a/helgrind/hg_errors.c b/helgrind/hg_errors.c
index 0e96d7e..65703e6 100644
--- a/helgrind/hg_errors.c
+++ b/helgrind/hg_errors.c
@@ -464,7 +464,7 @@
       linked routine, into the table (or whatever) when it is called
       for the first time. */
    {
-     VgSectKind sect = VG_(DebugInfo_sect_kind)( NULL, 0, data_addr );
+     VgSectKind sect = VG_(DebugInfo_sect_kind)( NULL, data_addr );
      if (0) VG_(printf)("XXXXXXXXX RACE on %#lx %s\n",
                         data_addr, VG_(pp_SectKind)(sect));
      /* SectPLT is required on ???-linux */
diff --git a/include/pub_tool_addrinfo.h b/include/pub_tool_addrinfo.h
index 84afdde..6e089e7 100644
--- a/include/pub_tool_addrinfo.h
+++ b/include/pub_tool_addrinfo.h
@@ -169,7 +169,7 @@
       // Could only narrow it down to be the PLT/GOT/etc of a given
       // object.  Better than nothing, perhaps.
       struct {
-         HChar      objname[128];
+         HChar      *objname;
          VgSectKind kind;
       } SectKind;
 
diff --git a/include/pub_tool_debuginfo.h b/include/pub_tool_debuginfo.h
index 2c0f815..95b203a 100644
--- a/include/pub_tool_debuginfo.h
+++ b/include/pub_tool_debuginfo.h
@@ -262,11 +262,10 @@
 const HChar* VG_(pp_SectKind)( VgSectKind kind );
 
 /* Given an address 'a', make a guess of which section of which object
-   it comes from.  If name is non-NULL, then the last n_name-1
-   characters of the object's name is put in name[0 .. n_name-2], and
-   name[n_name-1] is set to zero (guaranteed zero terminated). */
-VgSectKind VG_(DebugInfo_sect_kind)( /*OUT*/HChar* name, SizeT n_name, 
-                                     Addr a);
+   it comes from.  If name is non-NULL, then the object's name is put
+   into *name. The returned name is persistent as long as the debuginfo
+   it belongs to isn't discarded. */
+VgSectKind VG_(DebugInfo_sect_kind)( /*OUT*/const HChar** name, Addr a);
 
 
 #endif   // __PUB_TOOL_DEBUGINFO_H