HPCToolkit
x86-debug.c
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 //************************* System Include Files ****************************
48 
49 #include <xed-interface.h>
50 #include <stdint.h>
51 
52 //*************************** configuration ****************************
53 
54 #include <include/hpctoolkit-config.h>
55 
56 //*************************** User Include Files ****************************
57 
58 #include "x86-unwind-analysis.h"
59 #include "x86-build-intervals.h"
60 #include "x86-decoder.h"
61 #include "fnbounds_interface.h"
62 
63 static void
65 {
66  unwind_interval *u;
67  for(u = intervals.first; u; u = UWI_NEXT(u)) {
68  dump_ui_dbg(u);
69  }
70 }
71 
72 static void
73 x86_dump_intervals(void *addr, int noisy)
74 {
75  unwindr_info_t unwr_info;
76  if (!uw_recipe_map_lookup(addr, NATIVE_UNWINDER, &unwr_info))
77  EMSG("x86_dump_intervals: bounds of addr %p taken, but no bounds known", addr);
78  void * s = (void*)unwr_info.interval.start;
79  void * e = (void*)unwr_info.interval.end;
80 
82  intervals = x86_build_intervals(s, e - s, noisy);
83  x86_print_intervals(intervals);
84 }
85 
86 void
88 {
89  x86_dump_intervals(addr, 0);
90 }
91 
92 void
94 {
95  x86_dump_intervals(addr, 1);
96 }
97 
98 void
99 x86_dump_ins(void *ins)
100 {
101  xed_decoded_inst_t xedd;
102  xed_decoded_inst_t *xptr = &xedd;
103  xed_error_enum_t xed_error;
104  char inst_buf[1024];
105  char errbuf[2048];
106 
107  xed_decoded_inst_zero_set_mode(xptr, &x86_decoder_settings.xed_settings);
108  xed_error = xed_decode(xptr, (uint8_t*) ins, 15);
109 
110  if (xed_error == XED_ERROR_NONE) {
111  xed_decoded_inst_dump(xptr, inst_buf, sizeof(inst_buf));
112  sprintf(errbuf, "(%p, %d bytes, %s) %s \n" , ins,
113  xed_decoded_inst_get_length(xptr),
114  xed_iclass_enum_t2str(iclass(xptr)), inst_buf);
115  }
116  else {
117 #if defined(ENABLE_XOP) && defined (HOST_CPU_x86_64)
118  amd_decode_t decode_res;
119  adv_amd_decode(&decode_res, ins);
120  if (decode_res.success) {
121  if (decode_res.weak)
122  sprintf(errbuf, "(%p, %d bytes) weak AMD XOP \n", ins, (int) decode_res.len);
123  else
124  sprintf(errbuf, "(%p, %d bytes) robust AMD XOP \n", ins, (int) decode_res.len);
125  }
126  else
127 #endif // ENABLE_XOP and HOST_CPU_x86_64
128  sprintf(errbuf, "x86_dump_ins: xed decode error addr=%p, code = %d\n",
129  ins, (int) xed_error);
130  }
131  EMSG(errbuf);
132  fprintf(stderr, errbuf);
133  fflush(stderr);
134 }
bitree_uwi_t * first
xed_state_t xed_settings
Definition: x86-decoder.h:61
bool weak
Definition: amd-xop.h:9
void adv_amd_decode(amd_decode_t *stat, void *ins)
Definition: amd-xop.c:227
bool success
Definition: amd-xop.h:8
void dump_ui_dbg(unwind_interval *u)
uintptr_t end
Definition: interval_t.h:28
void x86_dump_ins(void *ins)
Definition: x86-debug.c:99
interval_t interval
Definition: unwindr_info.h:100
bool uw_recipe_map_lookup(void *addr, unwinder_t uw, unwindr_info_t *unwr_info)
void hpcrun_dump_intervals_noisy(void *addr)
Definition: x86-debug.c:93
#define EMSG
Definition: messages.h:70
xed_control_t x86_decoder_settings
Definition: x86-decoder.c:58
btuwi_status_t x86_build_intervals(void *ins, unsigned int len, int noisy)
static xed_decoded_inst_t xedd
Definition: x86ISAXed.cpp:92
#define iclass(xptr)
Definition: x86-decoder.h:69
#define UWI_NEXT(btuwi)
size_t len
Definition: amd-xop.h:10
static void x86_print_intervals(btuwi_status_t intervals)
Definition: x86-debug.c:64
static void x86_dump_intervals(void *addr, int noisy)
Definition: x86-debug.c:73
void hpcrun_dump_intervals(void *addr)
Definition: x86-debug.c:87
bitree_uwi_t unwind_interval
uintptr_t start
Definition: interval_t.h:27
cct_addr_t * addr
Definition: cct.c:130