Coverage Report

Created: 2022-01-18 06:27

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- JITLoaderGDB.cpp --------------------------------------------------===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
9
#include "JITLoaderGDB.h"
10
#include "Plugins/ObjectFile/Mach-O/ObjectFileMachO.h"
11
#include "lldb/Breakpoint/Breakpoint.h"
12
#include "lldb/Core/Module.h"
13
#include "lldb/Core/ModuleSpec.h"
14
#include "lldb/Core/PluginManager.h"
15
#include "lldb/Core/Section.h"
16
#include "lldb/Interpreter/OptionValueProperties.h"
17
#include "lldb/Symbol/ObjectFile.h"
18
#include "lldb/Symbol/Symbol.h"
19
#include "lldb/Symbol/SymbolContext.h"
20
#include "lldb/Symbol/SymbolVendor.h"
21
#include "lldb/Target/Process.h"
22
#include "lldb/Target/SectionLoadList.h"
23
#include "lldb/Target/Target.h"
24
#include "lldb/Utility/DataBufferHeap.h"
25
#include "lldb/Utility/LLDBAssert.h"
26
#include "lldb/Utility/Log.h"
27
#include "lldb/Utility/StreamString.h"
28
#include "llvm/Support/MathExtras.h"
29
30
#include <memory>
31
32
using namespace lldb;
33
using namespace lldb_private;
34
35
LLDB_PLUGIN_DEFINE(JITLoaderGDB)
36
37
// Debug Interface Structures
38
enum jit_actions_t { JIT_NOACTION = 0, JIT_REGISTER_FN, JIT_UNREGISTER_FN };
39
40
template <typename ptr_t> struct jit_code_entry {
41
  ptr_t next_entry;   // pointer
42
  ptr_t prev_entry;   // pointer
43
  ptr_t symfile_addr; // pointer
44
  uint64_t symfile_size;
45
};
46
47
template <typename ptr_t> struct jit_descriptor {
48
  uint32_t version;
49
  uint32_t action_flag; // Values are jit_action_t
50
  ptr_t relevant_entry; // pointer
51
  ptr_t first_entry;    // pointer
52
};
53
54
namespace {
55
56
enum EnableJITLoaderGDB {
57
  eEnableJITLoaderGDBDefault,
58
  eEnableJITLoaderGDBOn,
59
  eEnableJITLoaderGDBOff,
60
};
61
62
static constexpr OptionEnumValueElement g_enable_jit_loader_gdb_enumerators[] =
63
    {
64
        {
65
            eEnableJITLoaderGDBDefault,
66
            "default",
67
            "Enable JIT compilation interface for all platforms except macOS",
68
        },
69
        {
70
            eEnableJITLoaderGDBOn,
71
            "on",
72
            "Enable JIT compilation interface",
73
        },
74
        {
75
            eEnableJITLoaderGDBOff,
76
            "off",
77
            "Disable JIT compilation interface",
78
        },
79
};
80
81
#define LLDB_PROPERTIES_jitloadergdb
82
#include "JITLoaderGDBProperties.inc"
83
84
enum {
85
#define LLDB_PROPERTIES_jitloadergdb
86
#include "JITLoaderGDBPropertiesEnum.inc"
87
  ePropertyEnableJITBreakpoint
88
};
89
90
class PluginProperties : public Properties {
91
public:
92
9.33k
  static ConstString GetSettingName() {
93
9.33k
    return ConstString(JITLoaderGDB::GetPluginNameStatic());
94
9.33k
  }
95
96
3.39k
  PluginProperties() {
97
3.39k
    m_collection_sp = std::make_shared<OptionValueProperties>(GetSettingName());
98
3.39k
    m_collection_sp->Initialize(g_jitloadergdb_properties);
99
3.39k
  }
100
101
2.72k
  EnableJITLoaderGDB GetEnable() const {
102
2.72k
    return (EnableJITLoaderGDB)m_collection_sp->GetPropertyAtIndexAsEnumeration(
103
2.72k
        nullptr, ePropertyEnable,
104
2.72k
        g_jitloadergdb_properties[ePropertyEnable].default_uint_value);
105
2.72k
  }
106
};
107
108
8.66k
static PluginProperties &GetGlobalPluginProperties() {
109
8.66k
  static PluginProperties g_settings;
110
8.66k
  return g_settings;
111
8.66k
}
112
113
template <typename ptr_t>
114
bool ReadJITEntry(const addr_t from_addr, Process *process,
115
3
                  jit_code_entry<ptr_t> *entry) {
116
3
  lldbassert(from_addr % sizeof(ptr_t) == 0);
117
118
3
  ArchSpec::Core core = process->GetTarget().GetArchitecture().GetCore();
119
3
  bool i386_target = ArchSpec::kCore_x86_32_first <= core &&
120
3
                     core <= ArchSpec::kCore_x86_32_last;
121
3
  uint8_t uint64_align_bytes = i386_target ? 
40
: 8;
122
3
  const size_t data_byte_size =
123
3
      llvm::alignTo(sizeof(ptr_t) * 3, uint64_align_bytes) + sizeof(uint64_t);
124
125
3
  Status error;
126
3
  DataBufferHeap data(data_byte_size, 0);
127
3
  size_t bytes_read = process->ReadMemory(from_addr, data.GetBytes(),
128
3
                                          data.GetByteSize(), error);
129
3
  if (bytes_read != data_byte_size || !error.Success())
130
0
    return false;
131
132
3
  DataExtractor extractor(data.GetBytes(), data.GetByteSize(),
133
3
                          process->GetByteOrder(), sizeof(ptr_t));
134
3
  lldb::offset_t offset = 0;
135
3
  entry->next_entry = extractor.GetAddress(&offset);
136
3
  entry->prev_entry = extractor.GetAddress(&offset);
137
3
  entry->symfile_addr = extractor.GetAddress(&offset);
138
3
  offset = llvm::alignTo(offset, uint64_align_bytes);
139
3
  entry->symfile_size = extractor.GetU64(&offset);
140
141
3
  return true;
142
3
}
JITLoaderGDB.cpp:bool (anonymous namespace)::ReadJITEntry<unsigned long long>(unsigned long long, lldb_private::Process*, jit_code_entry<unsigned long long>*)
Line
Count
Source
115
3
                  jit_code_entry<ptr_t> *entry) {
116
3
  lldbassert(from_addr % sizeof(ptr_t) == 0);
117
118
3
  ArchSpec::Core core = process->GetTarget().GetArchitecture().GetCore();
119
3
  bool i386_target = ArchSpec::kCore_x86_32_first <= core &&
120
3
                     core <= ArchSpec::kCore_x86_32_last;
121
3
  uint8_t uint64_align_bytes = i386_target ? 
40
: 8;
122
3
  const size_t data_byte_size =
123
3
      llvm::alignTo(sizeof(ptr_t) * 3, uint64_align_bytes) + sizeof(uint64_t);
124
125
3
  Status error;
126
3
  DataBufferHeap data(data_byte_size, 0);
127
3
  size_t bytes_read = process->ReadMemory(from_addr, data.GetBytes(),
128
3
                                          data.GetByteSize(), error);
129
3
  if (bytes_read != data_byte_size || !error.Success())
130
0
    return false;
131
132
3
  DataExtractor extractor(data.GetBytes(), data.GetByteSize(),
133
3
                          process->GetByteOrder(), sizeof(ptr_t));
134
3
  lldb::offset_t offset = 0;
135
3
  entry->next_entry = extractor.GetAddress(&offset);
136
3
  entry->prev_entry = extractor.GetAddress(&offset);
137
3
  entry->symfile_addr = extractor.GetAddress(&offset);
138
3
  offset = llvm::alignTo(offset, uint64_align_bytes);
139
3
  entry->symfile_size = extractor.GetU64(&offset);
140
141
3
  return true;
142
3
}
Unexecuted instantiation: JITLoaderGDB.cpp:bool (anonymous namespace)::ReadJITEntry<unsigned int>(unsigned long long, lldb_private::Process*, jit_code_entry<unsigned int>*)
143
144
} // anonymous namespace end
145
146
JITLoaderGDB::JITLoaderGDB(lldb_private::Process *process)
147
    : JITLoader(process), m_jit_objects(),
148
      m_jit_break_id(LLDB_INVALID_BREAK_ID),
149
118
      m_jit_descriptor_addr(LLDB_INVALID_ADDRESS) {}
150
151
118
JITLoaderGDB::~JITLoaderGDB() {
152
118
  if (LLDB_BREAK_ID_IS_VALID(m_jit_break_id))
153
6
    m_process->GetTarget().RemoveBreakpointByID(m_jit_break_id);
154
118
}
155
156
5.94k
void JITLoaderGDB::DebuggerInitialize(Debugger &debugger) {
157
5.94k
  if (!PluginManager::GetSettingForJITLoaderPlugin(
158
5.94k
          debugger, PluginProperties::GetSettingName())) {
159
5.94k
    const bool is_global_setting = true;
160
5.94k
    PluginManager::CreateSettingForJITLoaderPlugin(
161
5.94k
        debugger, GetGlobalPluginProperties().GetValueProperties(),
162
5.94k
        ConstString("Properties for the JIT LoaderGDB plug-in."),
163
5.94k
        is_global_setting);
164
5.94k
  }
165
5.94k
}
166
167
116
void JITLoaderGDB::DidAttach() {
168
116
  Target &target = m_process->GetTarget();
169
116
  ModuleList &module_list = target.GetImages();
170
116
  SetJITBreakpoint(module_list);
171
116
}
172
173
2
void JITLoaderGDB::DidLaunch() {
174
2
  Target &target = m_process->GetTarget();
175
2
  ModuleList &module_list = target.GetImages();
176
2
  SetJITBreakpoint(module_list);
177
2
}
178
179
85
void JITLoaderGDB::ModulesDidLoad(ModuleList &module_list) {
180
85
  if (!DidSetJITBreakpoint() && 
m_process->IsAlive()73
)
181
73
    SetJITBreakpoint(module_list);
182
85
}
183
184
// Setup the JIT Breakpoint
185
191
void JITLoaderGDB::SetJITBreakpoint(lldb_private::ModuleList &module_list) {
186
191
  if (DidSetJITBreakpoint())
187
6
    return;
188
189
185
  Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_JIT_LOADER));
190
185
  LLDB_LOGF(log, "JITLoaderGDB::%s looking for JIT register hook",
191
185
            __FUNCTION__);
192
193
185
  addr_t jit_addr = GetSymbolAddress(
194
185
      module_list, ConstString("__jit_debug_register_code"), eSymbolTypeAny);
195
185
  if (jit_addr == LLDB_INVALID_ADDRESS)
196
179
    return;
197
198
6
  m_jit_descriptor_addr = GetSymbolAddress(
199
6
      module_list, ConstString("__jit_debug_descriptor"), eSymbolTypeData);
200
6
  if (m_jit_descriptor_addr == LLDB_INVALID_ADDRESS) {
201
0
    LLDB_LOGF(log, "JITLoaderGDB::%s failed to find JIT descriptor address",
202
0
              __FUNCTION__);
203
0
    return;
204
0
  }
205
206
6
  LLDB_LOGF(log, "JITLoaderGDB::%s setting JIT breakpoint", __FUNCTION__);
207
208
6
  Breakpoint *bp =
209
6
      m_process->GetTarget().CreateBreakpoint(jit_addr, true, false).get();
210
6
  bp->SetCallback(JITDebugBreakpointHit, this, true);
211
6
  bp->SetBreakpointKind("jit-debug-register");
212
6
  m_jit_break_id = bp->GetID();
213
214
6
  ReadJITDescriptor(true);
215
6
}
216
217
bool JITLoaderGDB::JITDebugBreakpointHit(void *baton,
218
                                         StoppointCallbackContext *context,
219
                                         user_id_t break_id,
220
3
                                         user_id_t break_loc_id) {
221
3
  Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_JIT_LOADER));
222
3
  LLDB_LOGF(log, "JITLoaderGDB::%s hit JIT breakpoint", __FUNCTION__);
223
3
  JITLoaderGDB *instance = static_cast<JITLoaderGDB *>(baton);
224
3
  return instance->ReadJITDescriptor(false);
225
3
}
226
227
static void updateSectionLoadAddress(const SectionList &section_list,
228
                                     Target &target, uint64_t symbolfile_addr,
229
                                     uint64_t symbolfile_size,
230
                                     uint64_t &vmaddrheuristic,
231
0
                                     uint64_t &min_addr, uint64_t &max_addr) {
232
0
  const uint32_t num_sections = section_list.GetSize();
233
0
  for (uint32_t i = 0; i < num_sections; ++i) {
234
0
    SectionSP section_sp(section_list.GetSectionAtIndex(i));
235
0
    if (section_sp) {
236
0
      if (section_sp->IsFake()) {
237
0
        uint64_t lower = (uint64_t)-1;
238
0
        uint64_t upper = 0;
239
0
        updateSectionLoadAddress(section_sp->GetChildren(), target,
240
0
                                 symbolfile_addr, symbolfile_size,
241
0
                                 vmaddrheuristic, lower, upper);
242
0
        if (lower < min_addr)
243
0
          min_addr = lower;
244
0
        if (upper > max_addr)
245
0
          max_addr = upper;
246
0
        const lldb::addr_t slide_amount = lower - section_sp->GetFileAddress();
247
0
        section_sp->Slide(slide_amount, false);
248
0
        section_sp->GetChildren().Slide(-slide_amount, false);
249
0
        section_sp->SetByteSize(upper - lower);
250
0
      } else {
251
0
        vmaddrheuristic += 2 << section_sp->GetLog2Align();
252
0
        uint64_t lower;
253
0
        if (section_sp->GetFileAddress() > vmaddrheuristic)
254
0
          lower = section_sp->GetFileAddress();
255
0
        else {
256
0
          lower = symbolfile_addr + section_sp->GetFileOffset();
257
0
          section_sp->SetFileAddress(symbolfile_addr +
258
0
                                     section_sp->GetFileOffset());
259
0
        }
260
0
        target.SetSectionLoadAddress(section_sp, lower, true);
261
0
        uint64_t upper = lower + section_sp->GetByteSize();
262
0
        if (lower < min_addr)
263
0
          min_addr = lower;
264
0
        if (upper > max_addr)
265
0
          max_addr = upper;
266
        // This is an upper bound, but a good enough heuristic
267
0
        vmaddrheuristic += section_sp->GetByteSize();
268
0
      }
269
0
    }
270
0
  }
271
0
}
272
273
9
bool JITLoaderGDB::ReadJITDescriptor(bool all_entries) {
274
9
  if (m_process->GetTarget().GetArchitecture().GetAddressByteSize() == 8)
275
9
    return ReadJITDescriptorImpl<uint64_t>(all_entries);
276
0
  else
277
0
    return ReadJITDescriptorImpl<uint32_t>(all_entries);
278
9
}
279
280
template <typename ptr_t>
281
9
bool JITLoaderGDB::ReadJITDescriptorImpl(bool all_entries) {
282
9
  if (m_jit_descriptor_addr == LLDB_INVALID_ADDRESS)
283
0
    return false;
284
285
9
  Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_JIT_LOADER));
286
9
  Target &target = m_process->GetTarget();
287
9
  ModuleList &module_list = target.GetImages();
288
289
9
  jit_descriptor<ptr_t> jit_desc;
290
9
  const size_t jit_desc_size = sizeof(jit_desc);
291
9
  Status error;
292
9
  size_t bytes_read = m_process->ReadMemory(m_jit_descriptor_addr, &jit_desc,
293
9
                                            jit_desc_size, error);
294
9
  if (bytes_read != jit_desc_size || !error.Success()) {
295
0
    LLDB_LOGF(log, "JITLoaderGDB::%s failed to read JIT descriptor",
296
0
              __FUNCTION__);
297
0
    return false;
298
0
  }
299
300
9
  jit_actions_t jit_action = (jit_actions_t)jit_desc.action_flag;
301
9
  addr_t jit_relevant_entry = (addr_t)jit_desc.relevant_entry;
302
9
  if (all_entries) {
303
6
    jit_action = JIT_REGISTER_FN;
304
6
    jit_relevant_entry = (addr_t)jit_desc.first_entry;
305
6
  }
306
307
12
  while (jit_relevant_entry != 0) {
308
3
    jit_code_entry<ptr_t> jit_entry;
309
3
    if (!ReadJITEntry(jit_relevant_entry, m_process, &jit_entry)) {
310
0
      LLDB_LOGF(log, "JITLoaderGDB::%s failed to read JIT entry at 0x%" PRIx64,
311
0
                __FUNCTION__, jit_relevant_entry);
312
0
      return false;
313
0
    }
314
315
3
    const addr_t &symbolfile_addr = (addr_t)jit_entry.symfile_addr;
316
3
    const size_t &symbolfile_size = (size_t)jit_entry.symfile_size;
317
3
    ModuleSP module_sp;
318
319
3
    if (jit_action == JIT_REGISTER_FN) {
320
3
      LLDB_LOGF(log,
321
3
                "JITLoaderGDB::%s registering JIT entry at 0x%" PRIx64
322
3
                " (%" PRIu64 " bytes)",
323
3
                __FUNCTION__, symbolfile_addr, (uint64_t)symbolfile_size);
324
325
3
      char jit_name[64];
326
3
      snprintf(jit_name, 64, "JIT(0x%" PRIx64 ")", symbolfile_addr);
327
3
      module_sp = m_process->ReadModuleFromMemory(
328
3
          FileSpec(jit_name), symbolfile_addr, symbolfile_size);
329
330
3
      if (module_sp && module_sp->GetObjectFile()) {
331
        // Object formats (like ELF) have no representation for a JIT type.
332
        // We will get it wrong, if we deduce it from the header.
333
3
        module_sp->GetObjectFile()->SetType(ObjectFile::eTypeJIT);
334
335
        // load the symbol table right away
336
3
        module_sp->GetObjectFile()->GetSymtab();
337
338
3
        m_jit_objects.insert(std::make_pair(symbolfile_addr, module_sp));
339
3
        if (auto image_object_file =
340
3
                llvm::dyn_cast<ObjectFileMachO>(module_sp->GetObjectFile())) {
341
0
          const SectionList *section_list = image_object_file->GetSectionList();
342
0
          if (section_list) {
343
0
            uint64_t vmaddrheuristic = 0;
344
0
            uint64_t lower = (uint64_t)-1;
345
0
            uint64_t upper = 0;
346
0
            updateSectionLoadAddress(*section_list, target, symbolfile_addr,
347
0
                                     symbolfile_size, vmaddrheuristic, lower,
348
0
                                     upper);
349
0
          }
350
3
        } else {
351
3
          bool changed = false;
352
3
          module_sp->SetLoadAddress(target, 0, true, changed);
353
3
        }
354
355
3
        module_list.AppendIfNeeded(module_sp);
356
357
3
        ModuleList module_list;
358
3
        module_list.Append(module_sp);
359
3
        target.ModulesDidLoad(module_list);
360
3
      } else {
361
0
        LLDB_LOGF(log,
362
0
                  "JITLoaderGDB::%s failed to load module for "
363
0
                  "JIT entry at 0x%" PRIx64,
364
0
                  __FUNCTION__, symbolfile_addr);
365
0
      }
366
3
    } else 
if (0
jit_action == JIT_UNREGISTER_FN0
) {
367
0
      LLDB_LOGF(log, "JITLoaderGDB::%s unregistering JIT entry at 0x%" PRIx64,
368
0
                __FUNCTION__, symbolfile_addr);
369
370
0
      JITObjectMap::iterator it = m_jit_objects.find(symbolfile_addr);
371
0
      if (it != m_jit_objects.end()) {
372
0
        module_sp = it->second;
373
0
        ObjectFile *image_object_file = module_sp->GetObjectFile();
374
0
        if (image_object_file) {
375
0
          const SectionList *section_list = image_object_file->GetSectionList();
376
0
          if (section_list) {
377
0
            const uint32_t num_sections = section_list->GetSize();
378
0
            for (uint32_t i = 0; i < num_sections; ++i) {
379
0
              SectionSP section_sp(section_list->GetSectionAtIndex(i));
380
0
              if (section_sp) {
381
0
                target.GetSectionLoadList().SetSectionUnloaded(section_sp);
382
0
              }
383
0
            }
384
0
          }
385
0
        }
386
0
        module_list.Remove(module_sp);
387
0
        m_jit_objects.erase(it);
388
0
      }
389
0
    } else if (jit_action == JIT_NOACTION) {
390
      // Nothing to do
391
0
    } else {
392
0
      assert(false && "Unknown jit action");
393
0
    }
394
395
3
    if (all_entries)
396
0
      jit_relevant_entry = (addr_t)jit_entry.next_entry;
397
3
    else
398
3
      jit_relevant_entry = 0;
399
3
  }
400
401
9
  return false; // Continue Running.
402
9
}
bool JITLoaderGDB::ReadJITDescriptorImpl<unsigned long long>(bool)
Line
Count
Source
281
9
bool JITLoaderGDB::ReadJITDescriptorImpl(bool all_entries) {
282
9
  if (m_jit_descriptor_addr == LLDB_INVALID_ADDRESS)
283
0
    return false;
284
285
9
  Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_JIT_LOADER));
286
9
  Target &target = m_process->GetTarget();
287
9
  ModuleList &module_list = target.GetImages();
288
289
9
  jit_descriptor<ptr_t> jit_desc;
290
9
  const size_t jit_desc_size = sizeof(jit_desc);
291
9
  Status error;
292
9
  size_t bytes_read = m_process->ReadMemory(m_jit_descriptor_addr, &jit_desc,
293
9
                                            jit_desc_size, error);
294
9
  if (bytes_read != jit_desc_size || !error.Success()) {
295
0
    LLDB_LOGF(log, "JITLoaderGDB::%s failed to read JIT descriptor",
296
0
              __FUNCTION__);
297
0
    return false;
298
0
  }
299
300
9
  jit_actions_t jit_action = (jit_actions_t)jit_desc.action_flag;
301
9
  addr_t jit_relevant_entry = (addr_t)jit_desc.relevant_entry;
302
9
  if (all_entries) {
303
6
    jit_action = JIT_REGISTER_FN;
304
6
    jit_relevant_entry = (addr_t)jit_desc.first_entry;
305
6
  }
306
307
12
  while (jit_relevant_entry != 0) {
308
3
    jit_code_entry<ptr_t> jit_entry;
309
3
    if (!ReadJITEntry(jit_relevant_entry, m_process, &jit_entry)) {
310
0
      LLDB_LOGF(log, "JITLoaderGDB::%s failed to read JIT entry at 0x%" PRIx64,
311
0
                __FUNCTION__, jit_relevant_entry);
312
0
      return false;
313
0
    }
314
315
3
    const addr_t &symbolfile_addr = (addr_t)jit_entry.symfile_addr;
316
3
    const size_t &symbolfile_size = (size_t)jit_entry.symfile_size;
317
3
    ModuleSP module_sp;
318
319
3
    if (jit_action == JIT_REGISTER_FN) {
320
3
      LLDB_LOGF(log,
321
3
                "JITLoaderGDB::%s registering JIT entry at 0x%" PRIx64
322
3
                " (%" PRIu64 " bytes)",
323
3
                __FUNCTION__, symbolfile_addr, (uint64_t)symbolfile_size);
324
325
3
      char jit_name[64];
326
3
      snprintf(jit_name, 64, "JIT(0x%" PRIx64 ")", symbolfile_addr);
327
3
      module_sp = m_process->ReadModuleFromMemory(
328
3
          FileSpec(jit_name), symbolfile_addr, symbolfile_size);
329
330
3
      if (module_sp && module_sp->GetObjectFile()) {
331
        // Object formats (like ELF) have no representation for a JIT type.
332
        // We will get it wrong, if we deduce it from the header.
333
3
        module_sp->GetObjectFile()->SetType(ObjectFile::eTypeJIT);
334
335
        // load the symbol table right away
336
3
        module_sp->GetObjectFile()->GetSymtab();
337
338
3
        m_jit_objects.insert(std::make_pair(symbolfile_addr, module_sp));
339
3
        if (auto image_object_file =
340
3
                llvm::dyn_cast<ObjectFileMachO>(module_sp->GetObjectFile())) {
341
0
          const SectionList *section_list = image_object_file->GetSectionList();
342
0
          if (section_list) {
343
0
            uint64_t vmaddrheuristic = 0;
344
0
            uint64_t lower = (uint64_t)-1;
345
0
            uint64_t upper = 0;
346
0
            updateSectionLoadAddress(*section_list, target, symbolfile_addr,
347
0
                                     symbolfile_size, vmaddrheuristic, lower,
348
0
                                     upper);
349
0
          }
350
3
        } else {
351
3
          bool changed = false;
352
3
          module_sp->SetLoadAddress(target, 0, true, changed);
353
3
        }
354
355
3
        module_list.AppendIfNeeded(module_sp);
356
357
3
        ModuleList module_list;
358
3
        module_list.Append(module_sp);
359
3
        target.ModulesDidLoad(module_list);
360
3
      } else {
361
0
        LLDB_LOGF(log,
362
0
                  "JITLoaderGDB::%s failed to load module for "
363
0
                  "JIT entry at 0x%" PRIx64,
364
0
                  __FUNCTION__, symbolfile_addr);
365
0
      }
366
3
    } else 
if (0
jit_action == JIT_UNREGISTER_FN0
) {
367
0
      LLDB_LOGF(log, "JITLoaderGDB::%s unregistering JIT entry at 0x%" PRIx64,
368
0
                __FUNCTION__, symbolfile_addr);
369
370
0
      JITObjectMap::iterator it = m_jit_objects.find(symbolfile_addr);
371
0
      if (it != m_jit_objects.end()) {
372
0
        module_sp = it->second;
373
0
        ObjectFile *image_object_file = module_sp->GetObjectFile();
374
0
        if (image_object_file) {
375
0
          const SectionList *section_list = image_object_file->GetSectionList();
376
0
          if (section_list) {
377
0
            const uint32_t num_sections = section_list->GetSize();
378
0
            for (uint32_t i = 0; i < num_sections; ++i) {
379
0
              SectionSP section_sp(section_list->GetSectionAtIndex(i));
380
0
              if (section_sp) {
381
0
                target.GetSectionLoadList().SetSectionUnloaded(section_sp);
382
0
              }
383
0
            }
384
0
          }
385
0
        }
386
0
        module_list.Remove(module_sp);
387
0
        m_jit_objects.erase(it);
388
0
      }
389
0
    } else if (jit_action == JIT_NOACTION) {
390
      // Nothing to do
391
0
    } else {
392
0
      assert(false && "Unknown jit action");
393
0
    }
394
395
3
    if (all_entries)
396
0
      jit_relevant_entry = (addr_t)jit_entry.next_entry;
397
3
    else
398
3
      jit_relevant_entry = 0;
399
3
  }
400
401
9
  return false; // Continue Running.
402
9
}
Unexecuted instantiation: bool JITLoaderGDB::ReadJITDescriptorImpl<unsigned int>(bool)
403
404
// PluginInterface protocol
405
2.72k
JITLoaderSP JITLoaderGDB::CreateInstance(Process *process, bool force) {
406
2.72k
  JITLoaderSP jit_loader_sp;
407
2.72k
  bool enable;
408
2.72k
  switch (GetGlobalPluginProperties().GetEnable()) {
409
6
    case EnableJITLoaderGDB::eEnableJITLoaderGDBOn:
410
6
      enable = true;
411
6
      break;
412
3
    case EnableJITLoaderGDB::eEnableJITLoaderGDBOff:
413
3
      enable = false;
414
3
      break;
415
2.71k
    case EnableJITLoaderGDB::eEnableJITLoaderGDBDefault:
416
2.71k
      ArchSpec arch(process->GetTarget().GetArchitecture());
417
2.71k
      enable = arch.GetTriple().getVendor() != llvm::Triple::Apple;
418
2.71k
      break;
419
2.72k
  }
420
2.72k
  if (enable)
421
118
    jit_loader_sp = std::make_shared<JITLoaderGDB>(process);
422
2.72k
  return jit_loader_sp;
423
2.72k
}
424
425
3.44k
llvm::StringRef JITLoaderGDB::GetPluginDescriptionStatic() {
426
3.44k
  return "JIT loader plug-in that watches for JIT events using the GDB "
427
3.44k
         "interface.";
428
3.44k
}
429
430
3.44k
void JITLoaderGDB::Initialize() {
431
3.44k
  PluginManager::RegisterPlugin(GetPluginNameStatic(),
432
3.44k
                                GetPluginDescriptionStatic(), CreateInstance,
433
3.44k
                                DebuggerInitialize);
434
3.44k
}
435
436
3.43k
void JITLoaderGDB::Terminate() {
437
3.43k
  PluginManager::UnregisterPlugin(CreateInstance);
438
3.43k
}
439
440
276
bool JITLoaderGDB::DidSetJITBreakpoint() const {
441
276
  return LLDB_BREAK_ID_IS_VALID(m_jit_break_id);
442
276
}
443
444
addr_t JITLoaderGDB::GetSymbolAddress(ModuleList &module_list,
445
                                      ConstString name,
446
191
                                      SymbolType symbol_type) const {
447
191
  SymbolContextList target_symbols;
448
191
  Target &target = m_process->GetTarget();
449
450
191
  module_list.FindSymbolsWithNameAndType(name, symbol_type, target_symbols);
451
191
  if (target_symbols.IsEmpty())
452
179
    return LLDB_INVALID_ADDRESS;
453
454
12
  SymbolContext sym_ctx;
455
12
  target_symbols.GetContextAtIndex(0, sym_ctx);
456
457
12
  const Address jit_descriptor_addr = sym_ctx.symbol->GetAddress();
458
12
  if (!jit_descriptor_addr.IsValid())
459
0
    return LLDB_INVALID_ADDRESS;
460
461
12
  const addr_t jit_addr = jit_descriptor_addr.GetLoadAddress(&target);
462
12
  return jit_addr;
463
12
}