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. */
26 #include "DbeSession.h"
27 #include "LoadObject.h"
28 #include "ArchiveExp.h"
30 #include "CallStack.h"
31 #include "gp-archive.h"
35 ArchiveExp::ArchiveExp (char *path
) : Experiment ()
39 use_fndr_archives
= true;
40 status
= find_expdir (path
);
41 if (status
== SUCCESS
)
45 ArchiveExp::~ArchiveExp () { }
48 ArchiveExp::read_data (int s_option
)
52 if (read_java_classes_file () == SUCCESS
)
54 for (int i
= 0, sz
= loadObjs
? loadObjs
->size () : 0; i
< sz
; i
++)
56 LoadObject
*lo
= loadObjs
->get (i
);
57 Dprintf (DEBUG_ARCHIVE
, NTXT ("%s:%d loadObjs[%d]=%-25s %s\n"),
58 get_basename (__FILE__
), (int) __LINE__
, i
,
59 STR (lo
->get_name ()), STR (lo
->get_pathname ()));
60 if ((lo
->dbeFile
->filetype
& DbeFile::F_JAVACLASS
) == 0)
63 if ((s_option
& ARCH_EXE_ONLY
) != 0)
65 lo
->sync_read_stabs ();
68 if ((s_option
& (ARCH_USED_EXE_ONLY
| ARCH_USED_SRC_ONLY
)) != 0)
70 read_frameinfo_file ();
71 resolveFrameInfo
= true;
72 Vector
<DataDescriptor
*> *ddscr
= getDataDescriptors ();
73 delete ddscr
; // getDataDescriptors() forces reading of experiment data
74 CallStack
*callStack
= callTree ();
79 Dprintf (DEBUG_ARCHIVE
, NTXT ("stacks=%p\n"), callStack
);
80 callStack
->print (NULL
);
84 CallStackNode
*node
= callStack
->get_node (n
);
89 Histable
*h
= node
->get_instr ();
90 Histable::Type t
= h
->get_type ();
91 if (t
== Histable::INSTR
)
93 DbeInstr
*dbeInstr
= (DbeInstr
*) h
;
94 if (!dbeInstr
->isUsed
)
96 Function
*func
= (Function
*) dbeInstr
->convertto (Histable::FUNCTION
);
100 func
->module
->isUsed
= true;
101 func
->module
->loadobject
->isUsed
= true;
103 DbeLine
*dbeLine
= (DbeLine
*) dbeInstr
->convertto (Histable::LINE
);
105 dbeLine
->sourceFile
->isUsed
= true;
108 else if (t
== Histable::LINE
)
110 DbeLine
* dbeLine
= (DbeLine
*) h
;
111 dbeLine
->sourceFile
->isUsed
= true;
113 node
= node
->ancestor
;
122 ArchiveExp::createLinkToFndrArchive (LoadObject
*lo
, int /* hide_msg */)
124 // For example, archives of libc.so will be:
125 // <exp>/archives/<libc.so_check_sum>
126 // <exp>/M_r0.er/archives/libc.so_<hash> -> ../../archives/<libc.so_check_sum>
127 if (!create_dir (get_fndr_arch_name ()))
129 fprintf (stderr
, GTXT ("Unable to create directory `%s'\n"), get_fndr_arch_name ());
132 uint32_t checksum
= lo
->get_checksum ();
133 char *linkName
= dbe_sprintf (NTXT ("../../%s/%u"), SP_ARCHIVES_DIR
, checksum
);
134 char *nm
= lo
->get_pathname ();
135 char *symLinkName
= getNameInArchive (nm
, false);
136 if (symlink (linkName
, symLinkName
) != 0)
138 fprintf (stderr
, GTXT ("Unable to create link `%s' -> `%s'\n"),
139 symLinkName
, linkName
);
147 // Return a full path inside founder archive:
148 return dbe_sprintf (NTXT ("%s/%u"), get_fndr_arch_name (), checksum
);