HPCToolkit
loadmap.h
Go to the documentation of this file.
1 // -*-Mode: C++;-*- // technically C99
2 
3 // * BeginRiceCopyright *****************************************************
4 //
5 // $HeadURL$
6 // $Id$
7 //
8 // --------------------------------------------------------------------------
9 // Part of HPCToolkit (hpctoolkit.org)
10 //
11 // Information about sources of support for research and development of
12 // HPCToolkit is at 'hpctoolkit.org' and in 'README.Acknowledgments'.
13 // --------------------------------------------------------------------------
14 //
15 // Copyright ((c)) 2002-2019, Rice University
16 // All rights reserved.
17 //
18 // Redistribution and use in source and binary forms, with or without
19 // modification, are permitted provided that the following conditions are
20 // met:
21 //
22 // * Redistributions of source code must retain the above copyright
23 // notice, this list of conditions and the following disclaimer.
24 //
25 // * Redistributions in binary form must reproduce the above copyright
26 // notice, this list of conditions and the following disclaimer in the
27 // documentation and/or other materials provided with the distribution.
28 //
29 // * Neither the name of Rice University (RICE) nor the names of its
30 // contributors may be used to endorse or promote products derived from
31 // this software without specific prior written permission.
32 //
33 // This software is provided by RICE and contributors "as is" and any
34 // express or implied warranties, including, but not limited to, the
35 // implied warranties of merchantability and fitness for a particular
36 // purpose are disclaimed. In no event shall RICE or contributors be
37 // liable for any direct, indirect, incidental, special, exemplary, or
38 // consequential damages (including, but not limited to, procurement of
39 // substitute goods or services; loss of use, data, or profits; or
40 // business interruption) however caused and on any theory of liability,
41 // whether in contract, strict liability, or tort (including negligence
42 // or otherwise) arising in any way out of the use of this software, even
43 // if advised of the possibility of such damage.
44 //
45 // ******************************************************* EndRiceCopyright *
46 
47 #ifndef LOADMAP_H
48 #define LOADMAP_H
49 
50 #include <stdio.h>
51 
52 /* an "loadmap" is an interval of time during which no two dynamic
53  libraries are mapped to the same region of the address space.
54  an loadmap can span across dlopen and dlclose operations. an loadmap
55  ends when a dlopen maps a new load module on top of a region of
56  the address space that has previously been occupied by another
57  module earlier during the loadmap.
58 */
59 
60 // Local includes
61 
62 #include <lib/prof-lean/hpcio.h>
63 #include <lib/prof-lean/hpcfmt.h>
65 
66 #include "fnbounds_file_header.h"
67 
68 
69 //***************************************************************************
70 //
71 //***************************************************************************
72 
73 typedef struct dso_info_t {
74  char* name;
75  void* start_addr;
76  void* end_addr;
77  uintptr_t start_to_ref_dist;
78  void** table;
79  unsigned long map_size;
80  unsigned long nsymbols;
82 
83  struct dso_info_t* next; //to only be used with dso_free_list
84  struct dso_info_t* prev;
85 
86 } dso_info_t;
87 
88 
89 // ---------------------------------------------------------
90 //
91 // ---------------------------------------------------------
92 
93 // Constructs a new dso_info_t by either pulling an unused one from
94 // the free list or malloc-ing one. If there are any on the free
95 // list, will return a pointer to it, otherwise will malloc a new one.
98 
99 
100 // Allocates and initializes a dso_info_t
101 dso_info_t*
102 hpcrun_dso_make(const char* name, void** table,
103  struct fnbounds_file_header* fh,
104  void* startaddr, void* endaddr, unsigned long map_size);
105 
106 
107 // ---------------------------------------------------------
108 //
109 // ---------------------------------------------------------
110 
111 // Use to dump the free list
112 void
114 
115 
116 // Use to dump a single dso_info_t struct.
117 void
119 
120 
121 //***************************************************************************
122 //
123 //***************************************************************************
124 
125 typedef struct load_module_t
126 {
127  uint16_t id;
128  char* name;
132 
133 } load_module_t;
134 
135 
137 hpcrun_loadModule_new(const char* name);
138 
139 // used only to add a load module for the kernel
140 uint16_t
141 hpcrun_loadModule_add(const char* name);
142 
143 //***************************************************************************
144 //
145 //***************************************************************************
146 
147 typedef struct hpcrun_loadmap_t
148 {
149  uint16_t size; // implies the next load_module_t id (size + 1)
152 
154 
155 
156 // ---------------------------------------------------------
157 //
158 // ---------------------------------------------------------
159 void
161 
162 
163 void
165 
166 
167 int
169 
170 
171 // ---------------------------------------------------------
172 //
173 // ---------------------------------------------------------
174 
175 // Requests a new load map.
178 
179 
180 // Initializes the load map
181 extern void hpcrun_loadmap_init(hpcrun_loadmap_t* x);
182 
183 //
184 // debugging operation, print loadmap in reverse order
185 //
186 extern void hpcrun_loadmap_print(hpcrun_loadmap_t* loadmap);
187 
188 // ---------------------------------------------------------
189 //
190 // ---------------------------------------------------------
191 
192 // hpcrun_loadmap_findByAddr: Find the (currently mapped) load module
193 // that 'contains' the address range [begin, end]
195 hpcrun_loadmap_findByAddr(void* begin, void* end);
196 
197 
198 // hpcrun_loadmap_findByName: Find a load module by name.
200 hpcrun_loadmap_findByName(const char* name);
201 
202 // find a load module, given the (previously determined) id
204 hpcrun_loadmap_findById(uint16_t id);
205 
206 
207 // hpcrun_loadmap_findLoadName: Search loadmap for (full) name of
208 // entry that has "name" as its executable name
209 const char*
210 hpcrun_loadmap_findLoadName(const char* name);
211 
212 
213 // ---------------------------------------------------------
214 //
215 // ---------------------------------------------------------
216 
217 // hpcrun_loadmap_map: Add a load module based on 'dso' to the current
218 // load map, ensuring that dso's name appears exactly once in the
219 // load map. 'dso' is assumed to be non-NULL. Locates the new load
220 // module at the front of the load map.
223 
224 
225 // hpcrun_loadmap_unmap: Note that 'lm' has been unmapped but retain a
226 // reference to it within the load map.
227 void
229 
230 
231 //***************************************************************************
232 //
233 //***************************************************************************
234 
235 void
237 
240 
241 typedef void (*loadmap_notify_range_t)(void *start, void *end);
242 
243 typedef struct loadmap_notify_t {
248 
250 
251 //***************************************************************************
252 
253 #endif // LOADMAP_H
load_module_t * hpcrun_loadmap_findByName(const char *name)
Definition: loadmap.c:287
char * name
Definition: loadmap.h:74
void hpcrun_initLoadmap()
Definition: loadmap.c:489
load_module_t * hpcrun_loadmap_findByAddr(void *begin, void *end)
Definition: loadmap.c:261
void(* loadmap_notify_range_t)(void *start, void *end)
Definition: loadmap.h:241
int hpcrun_loadmap_isLocked()
void hpcrun_loadmap_init(hpcrun_loadmap_t *x)
Definition: loadmap.c:237
hpcrun_loadmap_t * hpcrun_getLoadmap()
Definition: loadmap.c:501
void hpcrun_dso_dump(dso_info_t *x)
Definition: loadmap.c:183
void hpcrun_loadmap_unlock()
void hpcrun_dsoList_dump(dso_info_t *dl_list)
Definition: loadmap.c:174
struct load_module_t load_module_t
load_module_t * hpcrun_loadmap_map(dso_info_t *dso)
Definition: loadmap.c:389
struct loadmap_notify_t * next
Definition: loadmap.h:246
hpcrun_loadmap_t * hpcrun_loadmap_new()
Definition: loadmap.c:221
uint16_t id
Definition: loadmap.h:127
char * name
Definition: loadmap.h:128
void hpcrun_loadmap_print(hpcrun_loadmap_t *loadmap)
Definition: loadmap.c:251
loadmap_notify_range_t map
Definition: loadmap.h:244
dso_info_t * dso_info
Definition: loadmap.h:129
uintptr_t start_to_ref_dist
Definition: loadmap.h:77
void hpcrun_loadmap_notify_register(loadmap_notify_t *n)
Definition: loadmap.c:74
struct load_module_t * next
Definition: loadmap.h:130
uint16_t hpcrun_loadModule_add(const char *name)
Definition: loadmap.c:476
int is_relocatable
Definition: loadmap.h:81
void * start_addr
Definition: loadmap.h:75
void * end_addr
Definition: loadmap.h:76
load_module_t * lm_head
Definition: loadmap.h:150
const char * hpcrun_loadmap_findLoadName(const char *name)
Definition: loadmap.c:315
load_module_t * hpcrun_loadModule_new(const char *name)
Definition: loadmap.c:196
void hpcrun_loadmap_lock()
dso_info_t * hpcrun_dso_make(const char *name, void **table, struct fnbounds_file_header *fh, void *startaddr, void *endaddr, unsigned long map_size)
Definition: loadmap.c:130
load_module_t * lm_end
Definition: loadmap.h:151
struct dso_info_t dso_info_t
load_module_t * hpcrun_loadmap_findById(uint16_t id)
Definition: loadmap.c:301
struct hpcrun_loadmap_t hpcrun_loadmap_t
void ** table
Definition: loadmap.h:78
struct loadmap_notify_t loadmap_notify_t
unsigned long nsymbols
Definition: loadmap.h:80
dso_info_t * hpcrun_dso_new()
Definition: loadmap.c:108
uint16_t size
Definition: loadmap.h:149
struct dso_info_t * next
Definition: loadmap.h:83
<!-- ********************************************************************--> n<!-- HPCToolkit Experiment DTD --> n<!-- Version 2.1 --> n<!-- ********************************************************************--> n<!ELEMENT HPCToolkitExperiment(Header,(SecCallPathProfile|SecFlatProfile) *)> n<!ATTLIST HPCToolkitExperiment\n version CDATA #REQUIRED > n n<!-- ******************************************************************--> n n<!-- Info/NV:flexible name-value pairs:(n) ame;(t) ype;(v) alue --> n<!ELEMENT Info(NV *)> n<!ATTLIST Info\n n CDATA #IMPLIED > n<!ELEMENT NV EMPTY > n<!ATTLIST NV\n n CDATA #REQUIRED\n t CDATA #IMPLIED\n v CDATA #REQUIRED > n n<!-- ******************************************************************--> n<!-- Header --> n<!-- ******************************************************************--> n<!ELEMENT Header(Info *)> n<!ATTLIST Header\n n CDATA #REQUIRED > n n<!-- ******************************************************************--> n<!-- Section Header --> n<!-- ******************************************************************--> n<!ELEMENT SecHeader(MetricTable?, MetricDBTable?, TraceDBTable?, LoadModuleTable?, FileTable?, ProcedureTable?, Info *)> n n<!-- MetricTable:--> n<!ELEMENT MetricTable(Metric) * > n n<!-- Metric:(i) d;(n) ame --> n<!--(v) alue-type:transient type of values --> n<!--(t) ype:persistent type of metric --> n<!-- fmt:format;show;--> n<!ELEMENT Metric(MetricFormula *, Info?)> n<!ATTLIST Metric\n i CDATA #REQUIRED\n n CDATA #REQUIRED\n es CDATA #IMPLIED\n em CDATA #IMPLIED\n ep CDATA #IMPLIED\n v(raw|final|derived-incr|derived) \"raw\\ t (inclusive|exclusive|nil) \nil\\ partner CDATA #IMPLIED\ fmt CDATA #IMPLIED\ show (1|0) \1\\ show-percent (1|0) \1> n n<!-- MetricFormula represents derived metrics: (t)ype; (frm): formula --> n<!ELEMENT MetricFormula (Info?)> n<!ATTLIST MetricFormula\ t (combine|finalize) \finalize\\ i CDATA #IMPLIED\ frm CDATA #REQUIRED> n n<!-- Metric data, used in sections: (n)ame [from Metric]; (v)alue --> n<!ELEMENT M EMPTY> n<!ATTLIST M\ n CDATA #REQUIRED\ v CDATA #REQUIRED> n n<!-- MetricDBTable: --> n<!ELEMENT MetricDBTable (MetricDB)*> n n<!-- MetricDB: (i)d; (n)ame --> n<!-- (t)ype: persistent type of metric --> n<!-- db-glob: file glob describing files in metric db --> n<!-- db-id: id within metric db --> n<!-- db-num-metrics: number of metrics in db --> n<!-- db-header-sz: size (in bytes) of a db file header --> n<!ELEMENT MetricDB EMPTY> n<!ATTLIST MetricDB\ i CDATA #REQUIRED\ n CDATA #REQUIRED\ t (inclusive|exclusive|nil) \nil\\ partner CDATA #IMPLIED\ db-glob CDATA #IMPLIED\ db-id CDATA #IMPLIED\ db-num-metrics CDATA #IMPLIED\ db-header-sz CDATA #IMPLIED> n n<!-- TraceDBTable: --> n<!ELEMENT TraceDBTable (TraceDB)> n n<!-- TraceDB: (i)d --> n<!-- db-min-time: min beginning time stamp (global) --> n<!-- db-max-time: max ending time stamp (global) --> n<!ELEMENT TraceDB EMPTY> n<!ATTLIST TraceDB\ i CDATA #REQUIRED\ db-glob CDATA #IMPLIED\ db-min-time CDATA #IMPLIED\ db-max-time CDATA #IMPLIED\ db-header-sz CDATA #IMPLIED> n n<!-- LoadModuleTable assigns a short name to a load module --> n<!ELEMENT LoadModuleTable (LoadModule)*> n n<!ELEMENT LoadModule (Info?)> n<!ATTLIST LoadModule\ i CDATA #REQUIRED\ n CDATA #REQUIRED> n n<!-- FileTable assigns a short name to a file --> n<!ELEMENT FileTable (File)*> n n<!ELEMENT File (Info?)> n<!ATTLIST File\ i CDATA #REQUIRED\ n CDATA #REQUIRED> n n<!-- ProcedureTable assigns a short name to a procedure --> n<!ELEMENT ProcedureTable (Procedure)*> n n<!-- Info/NV: flexible name-value pairs: (n)ame; (t)ype; (v)alue --> n<!-- f: family of the procedure (fake, root, ...)--> n<!ELEMENT Procedure (Info?)> n<!ATTLIST Procedure\ i CDATA #REQUIRED\ n CDATA #REQUIRED\ f CDATA #IMPLIED> n n<!-- ****************************************************************** --> n<!-- Section: Call path profile --> n<!-- ****************************************************************** --> n<!ELEMENT SecCallPathProfile (SecHeader, SecCallPathProfileData)> n<!ATTLIST SecCallPathProfile\ i CDATA #REQUIRED\ n CDATA #REQUIRED> n n<!ELEMENT SecCallPathProfileData (PF|M)*> n<!-- Procedure frame --> n<!-- (i)d: unique identifier for cross referencing --> n<!-- (s)tatic scope id --> n<!-- (n)ame: a string or an id in ProcedureTable --> n<!-- (lm) load module: a string or an id in LoadModuleTable --> n<!-- (f)ile name: a string or an id in LoadModuleTable --> n<!-- (l)ine range: \beg-end\ (inclusive range) --> n<!-- (a)lien: whether frame is alien to enclosing P --> n<!-- (str)uct: hpcstruct node id --> n<!-- (t)ype: hpcrun node type: memory access, variable declaration, ... --> n<!-- (v)ma-range-set: \{[beg-end), [beg-end)...}\ --> n<!ELEMENT PF (PF|Pr|L|C|S|M)*> n<!ATTLIST PF\ i CDATA #IMPLIED\ s CDATA #IMPLIED\ n CDATA #REQUIRED\ lm CDATA #IMPLIED\ f CDATA #IMPLIED\ l CDATA #IMPLIED\ str CDATA #IMPLIED\ v CDATA #IMPLIED> n<!-- Procedure (static): GOAL: replace with 'P' --> n<!ELEMENT Pr (Pr|L|C|S|M)*> n<!ATTLIST Pr\ i CDATA #IMPLIED\ s CDATA #IMPLIED\ n CDATA #REQUIRED\ lm CDATA #IMPLIED\ f CDATA #IMPLIED\ l CDATA #IMPLIED\ a (1|0) \0\\ str CDATA #IMPLIED\ v CDATA #IMPLIED> n<!-- Callsite (a special StatementRange) --> n<!ELEMENT C (PF|M)*> n<!ATTLIST C\ i CDATA #IMPLIED\ s CDATA #IMPLIED\ l CDATA #IMPLIED\ str CDATA #IMPLIED\ v CDATA #IMPLIED> n n<!-- ****************************************************************** --> n<!-- Section: Flat profile --> n<!-- ****************************************************************** --> n<!ELEMENT SecFlatProfile (SecHeader, SecFlatProfileData)> n<!ATTLIST SecFlatProfile\ i CDATA #REQUIRED\ n CDATA #REQUIRED> n n<!ELEMENT SecFlatProfileData (LM|M)*> n<!-- Load module: (i)d; (n)ame; (v)ma-range-set --> n<!ELEMENT LM (F|P|M)*> n<!ATTLIST LM\ i CDATA #IMPLIED\ n CDATA #REQUIRED\ v CDATA #IMPLIED> n<!-- File --> n<!ELEMENT F (P|L|S|M)*> n<!ATTLIST F\ i CDATA #IMPLIED\ n CDATA #REQUIRED> n<!-- Procedure (Note 1) --> n<!ELEMENT P (P|A|L|S|C|M)*> n<!ATTLIST P\ i CDATA #IMPLIED\ n CDATA #REQUIRED\ l CDATA #IMPLIED\ str CDATA #IMPLIED\ v CDATA #IMPLIED> n<!-- Alien (Note 1) --> n<!ELEMENT A (A|L|S|C|M)*> n<!ATTLIST A\ i CDATA #IMPLIED\ f CDATA #IMPLIED\ n CDATA #IMPLIED\ l CDATA #IMPLIED\ str CDATA #IMPLIED\ v CDATA #IMPLIED> n<!-- Loop (Note 1,2) --> n<!ELEMENT L (A|Pr|L|S|C|M)*> n<!ATTLIST L\ i CDATA #IMPLIED\ s CDATA #IMPLIED\ l CDATA #IMPLIED\ f CDATA #IMPLIED\ str CDATA #IMPLIED\ v CDATA #IMPLIED> n<!-- Statement (Note 2) --> n<!-- (it): trace record identifier --> n<!ELEMENT S (S|M)*> n<!ATTLIST S\ i CDATA #IMPLIED\ it CDATA #IMPLIED\ s CDATA #IMPLIED\ l CDATA #IMPLIED\ str CDATA #IMPLIED\ v CDATA #IMPLIED> n<!-- Note 1: Contained Cs may not contain PFs --> n<!-- Note 2: The 's' attribute is not used for flat profiles --> n
struct dso_info_t * prev
Definition: loadmap.h:84
struct load_module_t * prev
Definition: loadmap.h:131
void hpcrun_loadmap_unmap(load_module_t *lm)
Definition: loadmap.c:433
unsigned long map_size
Definition: loadmap.h:79
loadmap_notify_range_t unmap
Definition: loadmap.h:245