1 /* Copyright (C) 2021 Free Software Foundation, Inc.
4 This file is part of GNU Binutils.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
25 #include "StringBuilder.h"
26 #include "Application.h"
27 #include "DbeSession.h"
28 #include "Experiment.h"
29 #include "Exp_Layout.h"
30 #include "DataObject.h"
34 #include "ClassFile.h"
36 #include "LoadObject.h"
37 #include "dbe_types.h"
43 LO_InstHTableSize = 4096,
48 LoadObject::create_item (const char *nm, int64_t chksum)
50 LoadObject *lo = new LoadObject (nm);
51 lo->checksum = chksum;
52 dbeSession->append (lo);
57 LoadObject::create_item (const char *nm, const char *_runTimePath, DbeFile *df)
59 LoadObject *lo = new LoadObject (nm);
60 lo->runTimePath = dbe_strdup (_runTimePath);
61 lo->dbeFile->orig_location = dbe_strdup (_runTimePath);
64 if ((df->filetype & DbeFile::F_JAR_FILE) != 0)
66 if (lo->dbeFile->find_in_jar_file (nm, df->get_jar_file ()))
68 lo->dbeFile->inArchive = df->inArchive;
69 lo->dbeFile->container = df;
74 lo->dbeFile->set_location (df->get_location ());
75 lo->dbeFile->sbuf = df->sbuf;
76 lo->dbeFile->inArchive = df->inArchive;
79 dbeSession->append (lo);
83 LoadObject::LoadObject (const char *loname)
89 need_swap_endian = false;
90 instHTable = new DbeInstr*[LO_InstHTableSize];
91 for (int i = 0; i < LO_InstHTableSize; i++)
94 functions = new Vector<Function*>;
95 funcHTable = new Function*[HTableSize];
96 for (int i = 0; i < HTableSize; i++)
99 seg_modules = new Vector<Module*>;
100 modules = new HashMap<char*, Module*>;
102 noname = dbeSession->createUnknownModule (this);
103 modules->put (noname->get_name (), noname);
109 seg_modules_map = NULL;
111 warnq = new Emsgqueue (NTXT ("lo_warnq"));
112 commentq = new Emsgqueue (NTXT ("lo_commentq"));
120 char *nm = (char *) loname;
121 if (strncmp (nm, NTXT ("./"), 2) == 0)
124 dbeFile = new DbeFile (nm);
125 dbeFile->filetype |= DbeFile::F_LOADOBJ | DbeFile::F_FILE;
128 LoadObject::~LoadObject ()
130 delete seg_modules_map;
147 LoadObject::get_elf ()
151 if (dbeFile->get_need_refind ())
156 char *fnm = dbeFile->get_location ();
159 append_msg (CMSG_ERROR, GTXT ("Cannot find file: `%s'"),
160 dbeFile->get_name ());
163 Elf::Elf_status st = Elf::ELF_ERR_CANT_OPEN_FILE;
164 elf_lo = Elf::elf_begin (fnm, &st);
168 case Elf::ELF_ERR_CANT_OPEN_FILE:
169 append_msg (CMSG_ERROR, GTXT ("Cannot open ELF file `%s'"), fnm);
171 case Elf::ELF_ERR_BAD_ELF_FORMAT:
173 append_msg (CMSG_ERROR, GTXT ("Cannot read ELF header of `%s'"),
182 LoadObject::openDebugInfo (char *fname, Stabs::Stab_status *stp)
184 if (objStabs == NULL)
188 objStabs = new Stabs (fname, get_pathname ());
189 Stabs::Stab_status st = objStabs->get_status ();
190 if ((st == Stabs::DBGD_ERR_NONE) && (checksum != 0))
192 Elf *elf = get_elf ();
193 if (elf && (checksum != elf->elf_checksum ()))
195 char *buf = dbe_sprintf (GTXT ("*** Note: '%s' has an unexpected checksum value; perhaps it was rebuilt. File ignored"),
197 commentq->append (new Emsg (CMSG_ERROR, buf));
199 st = Stabs::DBGD_ERR_CHK_SUM;
204 if (st != Stabs::DBGD_ERR_NONE)
214 LoadObject::get_addr ()
216 return MAKE_ADDRESS (seg_idx, 0);
220 LoadObject::compare (const char *_path, int64_t _checksum)
222 return _checksum == checksum && dbe_strcmp (_path, get_pathname ()) == 0;
226 LoadObject::compare (const char *_path, const char *_runTimePath, DbeFile *df)
229 if (dbe_strcmp (_path, get_pathname ()) != 0)
234 if (dbe_strcmp (_runTimePath, runTimePath) != 0)
236 ret |= CMP_RUNTIMEPATH;
238 if (df && dbeFile->compare (df))
244 LoadObject::set_platform (Platform_t pltf, int wsz)
251 platform = (wsz == W64) ? Sparcv9 : Sparc;
255 platform = (wsz == W64) ? Amd64 : Intel;
264 LoadObject::set_name (char *string)
267 pathname = dbe_strdup (string);
269 p = get_basename (pathname);
271 name = dbe_strdup (p);
272 else // set a short name to "<basename>"
273 name = dbe_sprintf (NTXT ("<%s>"), p);
277 LoadObject::dump_functions (FILE *out)
282 if (platform == Java)
285 Vector<JMethod*> *jmethods = (Vector<JMethod*>*)functions;
286 Vec_loop (JMethod*, jmethods, index, jmthd)
288 fprintf (out, "id %6llu, @0x%llx sz-%lld %s (module = %s)\n",
289 (unsigned long long) jmthd->id, (long long) jmthd->get_mid (),
290 (long long) jmthd->size, jmthd->get_name (),
291 jmthd->module ? jmthd->module->file_name : noname->file_name);
296 Vec_loop (Function*, functions, index, fitem)
298 if (fitem->alias && fitem->alias != fitem)
299 fprintf (out, "id %6llu, @0x%llx - %s == alias of '%s'\n",
300 (ull_t) fitem->id, (ull_t) fitem->img_offset,
301 fitem->get_name (), fitem->alias->get_name ());
304 mname = fitem->module ? fitem->module->file_name : noname->file_name;
305 sname = fitem->getDefSrcName ();
307 "id %6llu, @0x%llx - 0x%llx [save 0x%llx] o-%lld sz-%lld %s (module = %s)",
308 (ull_t) fitem->id, (ull_t) fitem->img_offset,
309 (ull_t) (fitem->img_offset + fitem->size),
310 (ull_t) fitem->save_addr, (ull_t) fitem->img_offset,
311 (ll_t) fitem->size, fitem->get_name (), mname);
312 if (sname && !streq (sname, mname))
313 fprintf (out, " (Source = %s)", sname);
321 LoadObject::get_index (Function *func)
327 int right = functions->size () - 1;
328 offset = func->img_offset;
329 while (left <= right)
331 x = (left + right) / 2;
332 fp = functions->fetch (x);
336 if (offset >= fp->img_offset + fp->size)
338 if (offset >= fp->img_offset)
342 if (offset < fp->img_offset)
344 else if (offset >= fp->img_offset + fp->size)
353 LoadObject::get_alias (Function *func)
355 Function *fp, *alias;
357 static char buf[1024];
358 if (func->img_offset == 0 || func->alias == NULL)
360 int fid = get_index (func);
364 nsize = functions->size ();
366 for (index = fid; index < nsize; index++)
368 fp = functions->fetch (index);
369 if (fp->alias != alias)
377 for (index--; index >= 0; index--)
379 fp = functions->fetch (index);
380 if (fp->alias != alias)
384 size_t len = strlen (buf);
387 snprintf (buf + len, sizeof (buf) - len, NTXT (", "));
390 snprintf (buf + len, sizeof (buf) - len, "%s", fp->get_name ());
397 LoadObject::find_dbeinstr (uint64_t file_off)
399 int hash = (((int) file_off) >> 2) & (LO_InstHTableSize - 1);
400 DbeInstr *instr = instHTable[hash];
401 if (instr && instr->img_offset == file_off)
403 Function *fp = find_function (file_off);
405 fp = dbeSession->get_Unknown_Function ();
406 uint64_t func_off = file_off - fp->img_offset;
407 instr = fp->find_dbeinstr (0, func_off);
408 instHTable[hash] = instr;
413 LoadObject::find_function (uint64_t foff)
415 // Look up in the hash table
416 int hash = (((int) foff) >> 6) & (HTableSize - 1);
417 Function *func = funcHTable[hash];
418 if (func && foff >= func->img_offset && foff < func->img_offset + func->size)
419 return func->alias ? func->alias : func;
424 int right = functions->size () - 1;
425 while (left <= right)
427 int x = (left + right) / 2;
428 Function *fp = functions->fetch (x);
431 if (foff < fp->img_offset)
433 else if (foff >= fp->img_offset + fp->size)
442 // Plug the hole with a static function
443 char *func_name = NULL;
444 Size low_bound = 0, high_bound = 0;
447 int last = functions->size () - 1;
448 uint64_t usize = (uint64_t) size;
451 // Cannot map to this LoadObject. Probably LoadObject was changed.
452 if (last >= 0 && functions->fetch (last)->img_offset == usize)
454 // Function is already created
455 func = functions->fetch (last);
456 if (func->size < 0 || (uint64_t) func->size < foff - usize)
457 func->size = foff - usize;
463 func_name = dbe_sprintf (GTXT ("<static>@0x%llx (%s) -- no functions found"),
471 func_name = dbe_sprintf (GTXT ("<static>@0x%llx (%s) -- no functions found"),
474 else if (foff < functions->fetch (0)->img_offset)
477 high_bound = functions->fetch (0)->img_offset;
481 Function *fp = functions->fetch (last);
482 if (foff >= fp->img_offset + fp->size)
484 low_bound = fp->img_offset + fp->size;
489 fp = functions->fetch (left);
490 if (foff >= fp->img_offset + fp->size)
492 low_bound = fp->img_offset + fp->size;
493 high_bound = functions->fetch (left + 1)->img_offset;
497 Function *fp1 = functions->fetch (left - 1);
498 low_bound = fp1->img_offset + fp1->size;
499 high_bound = fp->img_offset;
507 func = dbeSession->createFunction ();
508 func->size = (unsigned) (high_bound - low_bound);
509 func->module = noname;
510 func->img_fname = get_pathname ();
511 func->img_offset = (off_t) low_bound;
512 noname->functions->append (func); // unordered
513 if (func_name == NULL)
514 func_name = dbe_sprintf (GTXT ("<static>@0x%llx (%s)"), low_bound,
516 func->set_name (func_name);
519 // now insert the function
520 functions->insert (left, func);
523 // Update the hash table
524 funcHTable[hash] = func;
525 return func->alias ? func->alias : func;
529 fixFuncAlias (Vector<Function*> *SymLst)
532 int64_t len, bestLen, maxSize;
533 Function *sym, *bestAlias;
535 // XXXX it is a clone of Stabs::fixSymtabAlias()
536 ind = SymLst->size () - 1;
537 for (i = 0; i < ind; i++)
539 bestAlias = SymLst->fetch (i);
540 if (bestAlias->img_offset == 0) // Ignore this bad symbol
542 sym = SymLst->fetch (i + 1);
543 if (bestAlias->img_offset != sym->img_offset)
545 if (bestAlias->size == 0
546 || sym->img_offset < bestAlias->img_offset + bestAlias->size)
547 bestAlias->size = (int) (sym->img_offset - bestAlias->img_offset);
551 // Find a "best" alias
552 bestLen = strlen (bestAlias->get_name ());
553 maxSize = bestAlias->size;
554 for (k = i + 1; k <= ind; k++)
556 sym = SymLst->fetch (k);
557 if (bestAlias->img_offset != sym->img_offset)
559 if ((maxSize == 0) ||
560 (sym->img_offset < bestAlias->img_offset + maxSize))
561 maxSize = sym->img_offset - bestAlias->img_offset;
564 if (maxSize < sym->size)
566 len = strlen (sym->get_name ());
575 sym = SymLst->fetch (i);
576 sym->alias = bestAlias;
584 LoadObject::post_process_functions ()
586 if (flags & SEG_FLAG_DYNAMIC || platform == Java)
589 char *msg = GTXT ("Processing Load Object Data");
590 if (dbeSession->is_interactive ())
591 theApplication->set_progress (1, msg);
593 // First sort the functions
594 functions->sort (func_compare);
595 fixFuncAlias (functions);
599 Vec_loop (Module*, seg_modules, index, mitem)
601 mitem->functions->sort (func_compare);
604 // Find any derived functions, and set their derivedNode
606 Vec_loop (Function*, functions, index, fitem)
608 if (dbeSession->is_interactive () && index % 5000 == 0)
610 int percent = (int) (100.0 * index / functions->size ());
611 theApplication->set_progress (percent, (percent != 0) ? NULL : msg);
613 fitem->findDerivedFunctions ();
616 // 4987698: get the alias name for MAIN_
617 fitem = find_function (NTXT ("MAIN_"));
619 fitem->module->read_stabs ();
620 fitem = find_function (NTXT ("@plt"));
622 fitem->flags |= FUNC_FLAG_PLT;
623 if (dbeSession->is_interactive ())
624 theApplication->set_progress (0, NTXT (""));
628 LoadObject::func_compare (const void *p1, const void *p2)
630 Function *f1 = *(Function **) p1;
631 Function *f2 = *(Function **) p2;
632 if (f1->img_offset != f2->img_offset)
633 return f1->img_offset > f2->img_offset ? 1 : -1;
635 // annotated source not available for weak symbols.
636 if ((f1->module->flags & MOD_FLAG_UNKNOWN) != 0)
638 if ((f2->module->flags & MOD_FLAG_UNKNOWN) == 0)
641 else if ((f2->module->flags & MOD_FLAG_UNKNOWN) != 0)
643 return strcoll (f1->get_name (), f2->get_name ());
647 LoadObject::find_function (char *fname)
651 Vec_loop (Function*, functions, index, fitem)
653 if (strcmp (fitem->get_name (), fname) == 0)
656 return (Function *) NULL;
660 LoadObject::find_function (char *fname, unsigned int chksum)
664 Vec_loop (Function*, functions, index, fitem)
666 if (fitem->chksum == chksum && strcmp (fitem->get_name (), fname) == 0)
669 return (Function *) NULL;
673 LoadObject::find_module (char *mname)
675 for (int i = 0, sz = seg_modules ? seg_modules->size () : 0; i < sz; i++)
677 Module *module = seg_modules->fetch (i);
678 if (strcmp (module->get_name (), mname) == 0)
681 return (Module *) NULL;
684 LoadObject::Arch_status
685 LoadObject::sync_read_stabs ()
687 Arch_status st = ARCHIVE_SUCCESS;
694 post_process_functions ();
702 LoadObject::Arch_status
703 LoadObject::read_stabs ()
705 if ((dbeFile->filetype & DbeFile::F_FICTION) != 0)
706 return ARCHIVE_SUCCESS;
707 Arch_status stabs_status = ARCHIVE_ERR_OPEN;
708 if (platform == Java)
711 for (int i = 0, sz = seg_modules ? seg_modules->size () : 0; i < sz; i++)
713 Module *mod = seg_modules->fetch (i);
715 && (mod->dbeFile->filetype & DbeFile::F_JAVACLASS) != 0)
723 int status = cf->readFile ();
727 stabs_status = ARCHIVE_SUCCESS;
729 case Module::AE_NOSTABS:
730 stabs_status = ARCHIVE_NO_STABS;
732 case Module::AE_NOTREAD:
734 stabs_status = ARCHIVE_ERR_OPEN;
739 else if (strchr (pathname, '`'))
740 return ARCHIVE_SUCCESS;
743 Arch_status st = ARCHIVE_WRONG_ARCH;
744 Elf *elf = get_elf ();
747 if (read_archive () == 0)
748 st = ARCHIVE_SUCCESS;
751 char *msg = dbe_sprintf (GTXT ("*** Warning: Can't open file: %s"),
752 dbeFile->get_name ());
753 warnq->append (new Emsg (CMSG_ERROR, msg));
757 else if (checksum != 0 && checksum != elf->elf_checksum ())
759 if (read_archive () == 0)
760 st = ARCHIVE_SUCCESS;
763 char *msg = dbe_sprintf (
764 GTXT ("*** Note: '%s' has an unexpected checksum value; perhaps it was rebuilt. File ignored"),
765 dbeFile->get_location ());
766 commentq->append (new Emsg (CMSG_ERROR, msg));
770 if (st == ARCHIVE_SUCCESS) // An old archive is used
773 Stabs::Stab_status status = Stabs::DBGD_ERR_CANT_OPEN_FILE;
774 char *location = dbeFile->get_location (true);
775 if (location == NULL)
776 return ARCHIVE_ERR_OPEN;
778 if (openDebugInfo (location, &status))
780 status = objStabs->read_archive (this);
781 isRelocatable = objStabs->is_relocatable ();
782 size = objStabs->get_textsz ();
783 platform = objStabs->get_platform ();
784 wsize = objStabs->get_class ();
789 case Stabs::DBGD_ERR_NONE:
790 stabs_status = ARCHIVE_SUCCESS;
792 case Stabs::DBGD_ERR_CANT_OPEN_FILE:
793 stabs_status = ARCHIVE_ERR_OPEN;
795 case Stabs::DBGD_ERR_BAD_ELF_LIB:
796 case Stabs::DBGD_ERR_BAD_ELF_FORMAT:
797 stabs_status = ARCHIVE_BAD_STABS;
799 case Stabs::DBGD_ERR_NO_STABS:
800 stabs_status = ARCHIVE_NO_STABS;
802 case Stabs::DBGD_ERR_NO_DWARF:
803 stabs_status = ARCHIVE_NO_DWARF;
806 stabs_status = ARCHIVE_BAD_STABS;
813 #define ARCH_STRLEN(s) ((strlen(s) + 4) & ~0x3 )
816 offsetCmp (const void *a, const void *b)
818 uint32_t o1 = ((inst_info_t *) a)->offset;
819 uint32_t o2 = ((inst_info_t *) b)->offset;
820 return o1 == o2 ? 0 : (o1 < o2 ? -1 : 1);
824 LoadObject::read_archive ()
826 if (arch_name == NULL)
829 Function *func = NULL;
831 Data_window *dwin = new Data_window (arch_name);
832 if (dwin->not_opened ())
835 buf = dbe_sprintf (GTXT ("*** Warning: Error opening file for reading: %s: %s"),
836 arch_name, strerror (errno));
837 warnq->append (new Emsg (CMSG_ERROR, buf));
841 dwin->need_swap_endian = need_swap_endian;
843 // Prevent reading earlier archive files, which didn't support versioning.
845 ARCH_common *cpkt = (ARCH_common*) dwin->bind (offset, sizeof (ARCH_common));
849 v16 = (uint16_t) cpkt->type;
850 if (dwin->decode (v16) != ARCH_SEGMENT)
855 buf = dbe_sprintf (GTXT ("archive file malformed %s"), arch_name);
856 warnq->append (new Emsg (CMSG_WARN, buf));
862 unsigned long long pointer_invalid = 0;
863 for (int64_t last_offset = -5000;;)
865 cpkt = (ARCH_common*) dwin->bind (offset, sizeof (ARCH_common));
868 v16 = (uint16_t) cpkt->size;
869 uint32_t cpktsize = dwin->decode (v16);
870 cpkt = (ARCH_common*) dwin->bind (offset, cpktsize);
871 if ((cpkt == NULL) || (cpktsize == 0))
873 buf = dbe_sprintf (GTXT ("archive file malformed %s"), arch_name);
874 warnq->append (new Emsg (CMSG_WARN, buf));
879 // Update the progress bar
880 if (dbeSession->is_interactive () && ((offset - last_offset) >= 5000))
882 last_offset = offset;
883 int percent = (int) (100.0 * offset / dwin->get_fsize ());
885 msg = dbe_sprintf (GTXT ("Reading Load Object Data: %s"), name);
886 theApplication->set_progress (percent, (percent != 0) ? NULL : msg);
888 char *ptr = (char *) cpkt;
889 v16 = (uint16_t) cpkt->type;
890 switch (dwin->decode (v16))
894 ARCH_segment *aseg = (ARCH_segment*) cpkt;
895 if (dwin->decode (aseg->version) != ARCH_VERSION)
897 buf = dbe_sprintf (GTXT ("Archive file version mismatch for %s"), arch_name);
898 warnq->append (new Emsg (CMSG_ERROR, buf));
900 if (dbeSession->is_interactive ())
901 theApplication->set_progress (0, "");
905 size = dwin->decode (aseg->textsz);
906 Platform_t pltf = (Platform_t) dwin->decode (aseg->platform);
909 platform = pltf; // override if known
910 wsize = (platform == Sparcv9 || platform == Amd64) ? W64 : W32;
916 ARCH_message *amsg = (ARCH_message*) cpkt;
917 buf = status_str ((Arch_status) dwin->decode (amsg->errcode));
918 commentq->append (new Emsg (CMSG_ARCHIVE, buf));
924 ARCH_info *ainf = (ARCH_info*) cpkt;
925 Emsg *m = new Emsg (CMSG_ARCHIVE, (char*) (ainf + 1));
926 commentq->append (m);
931 ARCH_module *amod = (ARCH_module*) cpkt;
932 char *str = ((char*) amod) + sizeof (ARCH_module);
933 if (streq (str, SP_UNKNOWN_NAME) &&
934 streq (str + ARCH_STRLEN (str), SP_UNKNOWN_NAME))
939 mod = dbeSession->createModule (this, str);
940 mod->lang_code = (Sp_lang_code) dwin->decode (amod->lang_code);
941 mod->fragmented = dwin->decode (amod->fragmented);
942 str += ARCH_STRLEN (str);
943 mod->set_file_name (dbe_strdup (str));
944 modules->put (get_basename (str), mod);
951 ARCH_function *afnc = (ARCH_function*) cpkt;
952 func = dbeSession->createFunction ();
953 func->img_offset = dwin->decode (afnc->offset);
954 func->size = dwin->decode (afnc->size);
955 func->save_addr = dwin->decode (afnc->save_addr)
956 - dwin->decode (afnc->offset);
958 func->set_name (((char*) afnc) + sizeof (ARCH_function));
959 mod->functions->append (func);
960 functions->append (func);
966 Dprintf (DEBUG_LOADOBJ, "LDINSTR list for %s\n", mod->get_name ());
967 if (mod->infoList == NULL)
968 mod->infoList = new Vector<inst_info_t*>;
969 for (memop_info_t *mp = (memop_info_t*) (ptr + sizeof (ARCH_aninfo));
970 (char*) mp < ptr + cpktsize; mp++)
972 memop_info_t *memop = new memop_info_t;
973 memop->offset = dwin->decode (mp->offset);
974 memop->id = dwin->decode (mp->id);
975 memop->signature = dwin->decode (mp->signature);
976 memop->datatype_id = dwin->decode (mp->datatype_id);
977 mod->ldMemops.append (memop);
979 inst_info_t *instop = new inst_info_t;
980 instop->type = CPF_INSTR_TYPE_LD;
981 instop->offset = memop->offset;
982 instop->memop = memop;
983 mod->infoList->incorporate (instop, offsetCmp);
984 Dprintf (DEBUG_LOADOBJ,
985 "ld: offset=0x%04x id=0x%08x sig=0x%08x dtid=0x%08x\n",
986 memop->offset, memop->id, memop->signature,
989 Dprintf (DEBUG_LOADOBJ, "LDINSTR list of %lld for %s\n",
990 (long long) mod->ldMemops.size (), mod->get_name ());
995 Dprintf (DEBUG_LOADOBJ, NTXT ("STINSTR list for %s\n"), mod->get_name ());
996 if (mod->infoList == NULL)
997 mod->infoList = new Vector<inst_info_t*>;
998 for (memop_info_t *mp = (memop_info_t*) (ptr + sizeof (ARCH_aninfo));
999 ((char *) mp) < ptr + cpktsize; mp++)
1001 memop_info_t *memop = new memop_info_t;
1002 memop->offset = dwin->decode (mp->offset);
1003 memop->id = dwin->decode (mp->id);
1004 memop->signature = dwin->decode (mp->signature);
1005 memop->datatype_id = dwin->decode (mp->datatype_id);
1006 mod->stMemops.append (memop);
1008 inst_info_t *instop = new inst_info_t;
1009 instop->type = CPF_INSTR_TYPE_ST;
1010 instop->offset = memop->offset;
1011 instop->memop = memop;
1012 mod->infoList->incorporate (instop, offsetCmp);
1013 Dprintf (DEBUG_LOADOBJ,
1014 "st: offset=0x%04x id=0x%08x sig=0x%08x dtid=0x%08x\n",
1015 memop->offset, memop->id, memop->signature,
1016 memop->datatype_id);
1018 Dprintf (DEBUG_LOADOBJ, "STINSTR list of %lld for %s\n",
1019 (long long) mod->stMemops.size (), mod->get_name ());
1024 Dprintf (DEBUG_LOADOBJ, "PFINSTR list for %s\n", mod->get_name ());
1025 if (mod->infoList == NULL)
1026 mod->infoList = new Vector<inst_info_t*>;
1027 for (memop_info_t *mp = (memop_info_t*) (ptr + sizeof (ARCH_aninfo));
1028 ((char*) mp) < ptr + cpkt->size; mp++)
1030 memop_info_t *memop = new memop_info_t;
1031 memop->offset = dwin->decode (mp->offset);
1032 memop->id = dwin->decode (mp->id);
1033 memop->signature = dwin->decode (mp->signature);
1034 memop->datatype_id = dwin->decode (mp->datatype_id);
1035 mod->pfMemops.append (memop);
1037 inst_info_t *instop = new inst_info_t;
1038 instop->type = CPF_INSTR_TYPE_PREFETCH;
1039 instop->offset = memop->offset;
1040 instop->memop = memop;
1041 mod->infoList->incorporate (instop, offsetCmp);
1042 Dprintf (DEBUG_LOADOBJ,
1043 "pf: offset=0x%04x id=0x%08x sig=0x%08x dtid=0x%08x\n",
1044 memop->offset, memop->id, memop->signature,
1045 memop->datatype_id);
1047 Dprintf (DEBUG_LOADOBJ, "PFINSTR list of %lld for %s\n",
1048 (long long) mod->pfMemops.size (), mod->get_name ());
1053 for (target_info_t *tp = (target_info_t*) (ptr + sizeof (ARCH_aninfo));
1054 ((char*) tp) < ptr + cpkt->size; tp++)
1056 target_info_t *bTarget = new target_info_t;
1057 bTarget->offset = dwin->decode (tp->offset);
1058 mod->bTargets.append (bTarget);
1060 Dprintf (DEBUG_LOADOBJ, "BRTARGET list of %lld for %s\n",
1061 (long long) mod->infoList->size (), mod->get_name ());
1064 /* Check if the prointer is valid - should be even. */
1065 pointer_invalid = (unsigned long long) (offset + cpktsize) & 1;
1066 break; // ignore unknown packets
1068 if (pointer_invalid)
1075 if (dbeSession->is_interactive ())
1076 theApplication->set_progress (0, NTXT (""));
1081 LoadObject::status_str (Arch_status rv, char */*arg*/)
1085 case ARCHIVE_SUCCESS:
1088 case ARCHIVE_BAD_STABS:
1089 return dbe_sprintf (GTXT ("Error: unable to read symbol table of %s"),
1091 case ARCHIVE_ERR_SEG:
1092 return dbe_sprintf (GTXT ("Error: unable to read load object file %s"),
1094 case ARCHIVE_ERR_OPEN:
1095 return dbe_sprintf (GTXT ("Error: unable to open file %s"),
1097 case ARCHIVE_ERR_MAP:
1098 return dbe_sprintf (GTXT ("Error: unable to map file %s"),
1100 case ARCHIVE_WARN_CHECKSUM:
1101 return dbe_sprintf (GTXT ("Note: checksum differs from that recorded in experiment for %s"),
1103 case ARCHIVE_WARN_MTIME:
1104 return dbe_sprintf (GTXT ("Warning: last-modified time differs from that recorded in experiment for %s"),
1106 case ARCHIVE_WARN_HOST:
1107 return dbe_sprintf (GTXT ("Try running er_archive -F on the experiment, on the host where it was recorded"));
1108 case ARCHIVE_ERR_VERSION:
1109 return dbe_sprintf (GTXT ("Error: Wrong version of archive for %s"),
1111 case ARCHIVE_NO_STABS:
1112 return dbe_sprintf (GTXT ("Note: no stabs or dwarf information in %s"),
1114 case ARCHIVE_WRONG_ARCH:
1116 return dbe_sprintf (GTXT ("Error: file %s is built for Intel, and can't be read on SPARC"),
1119 return dbe_sprintf (GTXT ("Error: file %s is built for SPARC, and can't be read on Intel"),
1122 case ARCHIVE_NO_LIBDWARF:
1123 return dbe_strdup (GTXT ("Warning: no libdwarf found to read DWARF symbol tables"));
1124 case ARCHIVE_NO_DWARF:
1125 return dbe_sprintf (GTXT ("Note: no DWARF symbol table in %s"), name);
1127 return dbe_sprintf (GTXT ("Warning: unexpected archive error %d"),
1133 LoadObject::get_checksum ()
1135 char *errmsg = NULL;
1136 uint32_t crcval = get_cksum (pathname, &errmsg);
1137 if (0 == crcval && errmsg)
1139 warnq->append (new Emsg (CMSG_ERROR, errmsg));
1146 get_module_map_key (Module *mod)
1148 return mod->lang_code == Sp_lang_java ? mod->get_name () : mod->file_name;
1152 LoadObject::get_comparable_Module (Module *mod)
1154 if (mod->loadobject == this)
1156 if (get_module_map_key (mod) == NULL)
1158 if (seg_modules_map == NULL)
1160 seg_modules_map = new HashMap<char*, Module*>;
1161 for (int i = 0; i < seg_modules->size (); i++)
1163 Module *m = seg_modules->fetch (i);
1164 char *key = get_module_map_key (m);
1167 seg_modules_map->put (m->file_name, m);
1168 char *bname = get_basename (key);
1170 seg_modules_map->put (bname, m);
1175 char *key = get_module_map_key (mod);
1176 Module *cmpMod = seg_modules_map->get (key);
1177 if (cmpMod && cmpMod->comparable_objs == NULL)
1179 char *bname = get_basename (key);
1182 cmpMod = seg_modules_map->get (bname);
1183 if (cmpMod && cmpMod->comparable_objs == NULL)
1190 LoadObject::get_comparable_objs ()
1192 update_comparable_objs ();
1193 if (comparable_objs || dbeSession->expGroups->size () <= 1)
1194 return comparable_objs;
1195 comparable_objs = new Vector<Histable*>(dbeSession->expGroups->size ());
1196 for (int i = 0, sz = dbeSession->expGroups->size (); i < sz; i++)
1198 ExpGroup *gr = dbeSession->expGroups->fetch (i);
1199 Histable *h = gr->get_comparable_loadObject (this);
1200 comparable_objs->append (h);
1202 h->comparable_objs = comparable_objs;
1204 dump_comparable_objs ();
1205 return comparable_objs;
1209 LoadObject::append_module (Module *mod)
1211 seg_modules->append (mod);
1212 if (seg_modules_map == NULL)
1213 seg_modules_map = new HashMap<char*, Module*>;
1214 char *key = get_module_map_key (mod);
1217 seg_modules_map->put (key, mod);
1218 char *bname = get_basename (key);
1220 seg_modules_map->put (bname, mod);
1224 // LIBRARY_VISIBILITY
1226 LoadObject::get_hide_function ()
1228 if (h_function == NULL)
1229 h_function = dbeSession->create_hide_function (this);
1234 LoadObject::get_hide_instr (DbeInstr *instr)
1236 if (h_instr == NULL)
1238 Function *hf = get_hide_function ();
1239 h_instr = hf->create_hide_instr (instr);