aboutsummaryrefslogtreecommitdiff
path: root/gprofng/src/ArchiveExp.cc
blob: e7ebfa913cc4edd2a1adb5f1ee81167165074631 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/* Copyright (C) 2021 Free Software Foundation, Inc.
   Contributed by Oracle.

   This file is part of GNU Binutils.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3, or (at your option)
   any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, 51 Franklin Street - Fifth Floor, Boston,
   MA 02110-1301, USA.  */

#include "config.h"
#include <stdio.h>
#include <unistd.h>

#include "util.h"
#include "DbeSession.h"
#include "LoadObject.h"
#include "ArchiveExp.h"
#include "DbeFile.h"
#include "CallStack.h"
#include "gp-archive.h"
#include "Function.h"
#include "Module.h"

ArchiveExp::ArchiveExp (char *path) : Experiment ()
{
  force_flag = false;
  copyso_flag = false;
  use_fndr_archives = true;
  status = find_expdir (path);
  if (status == SUCCESS)
    read_log_file ();
}

ArchiveExp::~ArchiveExp () { }

void
ArchiveExp::read_data (int s_option)
{
  read_archives ();
  read_map_file ();
  if (read_java_classes_file () == SUCCESS)
    {
      for (int i = 0, sz = loadObjs ? loadObjs->size () : 0; i < sz; i++)
	{
	  LoadObject *lo = loadObjs->get (i);
	  Dprintf (DEBUG_ARCHIVE, NTXT ("%s:%d loadObjs[%d]=%-25s %s\n"),
		   get_basename (__FILE__), (int) __LINE__, i,
		   STR (lo->get_name ()), STR (lo->get_pathname ()));
	  if ((lo->dbeFile->filetype & DbeFile::F_JAVACLASS) == 0)
	    continue;
	  lo->isUsed = true;
	  if ((s_option & ARCH_EXE_ONLY) != 0)
	    continue;
	  lo->sync_read_stabs ();
	}
    }
  if ((s_option & (ARCH_USED_EXE_ONLY | ARCH_USED_SRC_ONLY)) != 0)
    {
      read_frameinfo_file ();
      resolveFrameInfo = true;
      Vector<DataDescriptor*> *ddscr = getDataDescriptors ();
      delete ddscr; // getDataDescriptors() forces reading of experiment data
      CallStack *callStack = callTree ();
      if (callStack)
	{
	  if (DEBUG_ARCHIVE)
	    {
	      Dprintf (DEBUG_ARCHIVE, NTXT ("stacks=%p\n"), callStack);
	      callStack->print (NULL);
	    }
	  for (int n = 0;; n++)
	    {
	      CallStackNode *node = callStack->get_node (n);
	      if (node == NULL)
		break;
	      do
		{
		  Histable *h = node->get_instr ();
		  Histable::Type t = h->get_type ();
		  if (t == Histable::INSTR)
		    {
		      DbeInstr *dbeInstr = (DbeInstr *) h;
		      if (!dbeInstr->isUsed)
			{
			  Function *func = (Function *) dbeInstr->convertto (Histable::FUNCTION);
			  if (!func->isUsed)
			    {
			      func->isUsed = true;
			      func->module->isUsed = true;
			      func->module->loadobject->isUsed = true;
			    }
			  DbeLine *dbeLine = (DbeLine *) dbeInstr->convertto (Histable::LINE);
			  if (dbeLine)
			    dbeLine->sourceFile->isUsed = true;
			}
		    }
		  else if (t == Histable::LINE)
		    {
		      DbeLine * dbeLine = (DbeLine *) h;
		      dbeLine->sourceFile->isUsed = true;
		    }
		  node = node->ancestor;
		}
	      while (node);
	    }
	}
    }
}

char *
ArchiveExp::createLinkToFndrArchive (LoadObject *lo, int /* hide_msg */)
{
  // For example, archives of libc.so will be:
  //  <exp>/archives/<libc.so_check_sum>
  //  <exp>/M_r0.er/archives/libc.so_<hash> -> ../../archives/<libc.so_check_sum>
  if (!create_dir (get_fndr_arch_name ()))
    {
      fprintf (stderr, GTXT ("Unable to create directory `%s'\n"), get_fndr_arch_name ());
      return NULL;
    }
  uint32_t checksum = lo->get_checksum ();
  char *linkName = dbe_sprintf (NTXT ("../../%s/%u"), SP_ARCHIVES_DIR, checksum);
  char *nm = lo->get_pathname ();
  char *symLinkName = getNameInArchive (nm, false);
  if (symlink (linkName, symLinkName) != 0)
    {
      fprintf (stderr, GTXT ("Unable to create link `%s' -> `%s'\n"),
	       symLinkName, linkName);
      free (linkName);
      free (symLinkName);
      return NULL;
    }
  free (linkName);
  free (symLinkName);

  // Return a full path inside founder archive:
  return dbe_sprintf (NTXT ("%s/%u"), get_fndr_arch_name (), checksum);
}