HPCToolkit
ip-normalized.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 ip_normalized_h
48 #define ip_normalized_h
49 
50 //************************* System Include Files ****************************
51 
52 //*************************** User Include Files ****************************
53 
54 #include <hpcrun/loadmap.h>
55 
57 
58 
59 //*************************** Forward Declarations **************************
60 
61 //***************************************************************************
62 
63 // ---------------------------------------------------------
64 // ip_normalized_t: A normalized instruction pointer. Since this is a
65 // small struct, it can be passed by value.
66 // ---------------------------------------------------------
67 
68 typedef struct ip_normalized_t {
69 
70  // ---------------------------------------------------------
71  // id of load module
72  // ---------------------------------------------------------
73  uint16_t lm_id;
74 
75  // ---------------------------------------------------------
76  // static instruction pointer address within the load module
77  // ---------------------------------------------------------
78  uintptr_t lm_ip;
79 
81 
82 
83 #define ip_normalized_NULL \
84  { .lm_id = HPCRUN_FMT_LMId_NULL, .lm_ip = HPCRUN_FMT_LMIp_NULL }
85 
87 
88 
89 // ---------------------------------------------------------
90 // comparison operations, mainly for cct sibling splay operations
91 // ---------------------------------------------------------
92 
93 static inline bool
95 {
96  return ( (a == b) || (a && b
97  && a->lm_id == b->lm_id
98  && a->lm_ip == b->lm_ip) );
99 }
100 
101 
102 static inline bool
104 {
105  if (a == b) {
106  return false;
107  }
108  if (! a) a = &ip_normalized_NULL_lval;
109  if (! b) b = &ip_normalized_NULL_lval;
110 
111  if (a->lm_id < b->lm_id) return true;
112  if (a->lm_id > b->lm_id) return false;
113  if (a->lm_ip < b->lm_ip) return true;
114  if (a->lm_ip > b->lm_ip) return false;
115  return false;
116 }
117 
118 
119 static inline bool
121 {
122  return ip_normalized_lt(b, a);
123 }
124 
125 
126 // Converts an ip into a normalized ip using 'lm'. If 'lm' is NULL
127 // the function attempts to find the load module that 'unnormalized_ip'
128 // belongs to. If no load module is found or the load module does not
129 // have a valid 'dso_info' field, ip_normalized_NULL is returned;
130 // otherwise, the properly normalized ip is returned.
132 hpcrun_normalize_ip(void* unnormalized_ip, load_module_t* lm);
133 
134 //***************************************************************************
135 
136 #endif // ip_normalized_h
struct ip_normalized_t ip_normalized_t
const ip_normalized_t ip_normalized_NULL_lval
Definition: ip-normalized.c:66
uintptr_t lm_ip
Definition: ip-normalized.h:78
static bool ip_normalized_lt(const ip_normalized_t *a, const ip_normalized_t *b)
static bool ip_normalized_gt(const ip_normalized_t *a, const ip_normalized_t *b)
static bool ip_normalized_eq(const ip_normalized_t *a, const ip_normalized_t *b)
Definition: ip-normalized.h:94
ip_normalized_t hpcrun_normalize_ip(void *unnormalized_ip, load_module_t *lm)
Definition: ip-normalized.c:70