Skip to content

Commit 836bd5e

Browse files
committed
Attach pre work
1 parent 588e1c5 commit 836bd5e

File tree

15 files changed

+159
-27
lines changed

15 files changed

+159
-27
lines changed

lldb/include/lldb/Core/ModuleSpec.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
#include "lldb/Utility/Iterable.h"
1717
#include "lldb/Utility/Stream.h"
1818
#include "lldb/Utility/UUID.h"
19-
19+
#include "lldb/Utility/LLDBLog.h"
20+
#include "lldb/Utility/Log.h"
2021
#include "llvm/Support/Chrono.h"
2122

2223
#include <mutex>
@@ -47,6 +48,7 @@ class ModuleSpec {
4748
llvm::SmallString<256> path_with_object;
4849
file_spec.GetPath(path_with_object);
4950
if (strstr(path_with_object.c_str(), "(") != nullptr) {
51+
LLDB_LOGF(GetLog(LLDBLog::Object), "ModuleSpec : %d %s",__LINE__,path_with_object.c_str());
5052
char *part;
5153
char *str = (char *)path_with_object.c_str();
5254
part = strtok(str, "()");
@@ -57,7 +59,10 @@ class ModuleSpec {
5759
m_object_name = ConstString(part);
5860
m_file = FileSpec(file_name);
5961
m_object_size = FileSystem::Instance().GetByteSize(m_file);
62+
LLDB_LOGF(GetLog(LLDBLog::Object), "ModuleSpec file & obj : %d %s %s",__LINE__,file_spec.GetFilename().AsCString(),m_object_name.AsCString());
63+
LLDB_LOGF(GetLog(LLDBLog::Object), "ModuleSpec FULL path : %d %s ",__LINE__,file_spec.GetPath().c_str());
6064
} else {
65+
LLDB_LOGF(GetLog(LLDBLog::Object), "ModuleSpec : %d %s",__LINE__,file_spec.GetFilename().AsCString());
6166
m_file = file_spec;
6267
m_object_size = FileSystem::Instance().GetByteSize(file_spec);
6368
}

lldb/source/Core/Module.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,31 +1535,40 @@ bool Module::SetLoadAddressByType(Target &target, lldb::addr_t value,
15351535
bool Module::MatchesModuleSpec(const ModuleSpec &module_ref) {
15361536
const UUID &uuid = module_ref.GetUUID();
15371537

1538+
Log *log(GetLog(LLDBLog::Object | LLDBLog::Modules));
15381539
if (uuid.IsValid()) {
15391540
// If the UUID matches, then nothing more needs to match...
15401541
return (uuid == GetUUID());
15411542
}
1542-
1543+
LLDB_LOGF(log,"MatchesModuleSpec %d",__LINE__);
15431544
const FileSpec &file_spec = module_ref.GetFileSpec();
15441545
if (!FileSpec::Match(file_spec, m_file) &&
15451546
!FileSpec::Match(file_spec, m_platform_file))
15461547
return false;
15471548

1549+
LLDB_LOGF(log,"MatchesModuleSpec %d",__LINE__);
15481550
const FileSpec &platform_file_spec = module_ref.GetPlatformFileSpec();
15491551
if (!FileSpec::Match(platform_file_spec, GetPlatformFileSpec()))
15501552
return false;
15511553

1554+
LLDB_LOGF(log,"MatchesModuleSpec %d",__LINE__);
15521555
const ArchSpec &arch = module_ref.GetArchitecture();
15531556
if (arch.IsValid()) {
15541557
if (!m_arch.IsCompatibleMatch(arch))
15551558
return false;
15561559
}
1557-
1560+
1561+
LLDB_LOGF(log,"MatchesModuleSpec %d",__LINE__);
15581562
ConstString object_name = module_ref.GetObjectName();
1563+
LLDB_LOGF(log,"MatchesModuleSpec object_name %s",GetObjectName().AsCString());
1564+
LLDB_LOGF(log,"MatchesModuleSpec module_ref %s", module_ref.GetObjectName().AsCString());
1565+
LLDB_LOGF(log,"MatchesModuleSpec O Get des: %d",GetObjectOffset());
1566+
LLDB_LOGF(log,"MatchesModuleSpec m Get des: %d", module_ref.GetObjectOffset());
15591567
if (object_name) {
15601568
if (object_name != GetObjectName())
15611569
return false;
15621570
}
1571+
LLDB_LOGF(log,"MatchesModuleSpec return true ");
15631572
return true;
15641573
}
15651574

lldb/source/Core/ModuleList.cpp

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,19 +251,42 @@ void ModuleList::Append(const ModuleSP &module_sp, bool notify) {
251251
void ModuleList::ReplaceEquivalent(
252252
const ModuleSP &module_sp,
253253
llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules) {
254+
Log *log(GetLog(LLDBLog::Object | LLDBLog::Modules));
255+
LLDB_LOGF(log,"ReplaceEquivalent module_sp %s",module_sp->GetObjectName().AsCString());
254256
if (module_sp) {
255257
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
256258

259+
//llvm::SmallString<256> path_with_object;
260+
261+
LLDB_LOGF(log," Before ReplaceEquivalent module_sp dis %s",module_sp->GetFileSpec().GetPath().c_str());
262+
263+
llvm::SmallString<128> path;
264+
module_sp->GetFileSpec().GetPath(path);
265+
llvm::SmallString<128> obj_name ;
266+
obj_name = module_sp->GetObjectName().AsCString();
267+
268+
llvm::SmallString<256> full_path;
269+
full_path = llvm::Twine(path + llvm::Twine("(") + llvm::Twine(obj_name) + llvm::Twine(")")).str();
270+
//std::string full_path = module_sp->GetFileSpec().GetPath().c_str() + "("
271+
// + module_sp->GetObjectName().AsCString() + ")";
272+
273+
//module_sp->GetFileSpec().SetPath(full_path);
274+
275+
276+
LLDB_LOGF(log,"After ReplaceEquivalent module_sp dis %s",module_sp->GetFileSpec().GetPath().c_str());
257277
// First remove any equivalent modules. Equivalent modules are modules
258278
// whose path, platform path and architecture match.
259279
ModuleSpec equivalent_module_spec(module_sp->GetFileSpec(),
260280
module_sp->GetArchitecture());
281+
LLDB_LOGF(log,"ReplaceEquivalent equivalent.module_sp %s",equivalent_module_spec.GetObjectName().AsCString());
261282
equivalent_module_spec.GetPlatformFileSpec() =
262283
module_sp->GetPlatformFileSpec();
263284

264285
size_t idx = 0;
265286
while (idx < m_modules.size()) {
287+
LLDB_LOGF(log,"ReplaceEquivalent index : %d",idx);
266288
ModuleSP test_module_sp(m_modules[idx]);
289+
LLDB_LOGF(log,"ReplaceEquivalent test_module_sp : %s",test_module_sp->GetObjectName().AsCString());
267290
if (test_module_sp->MatchesModuleSpec(equivalent_module_spec)) {
268291
if (old_modules)
269292
old_modules->push_back(test_module_sp);
@@ -795,6 +818,7 @@ ModuleList::GetSharedModule(const ModuleSpec &module_spec, ModuleSP &module_sp,
795818
shared_module_list.m_modules_mutex);
796819
char path[PATH_MAX];
797820

821+
Log *log = GetLog(LLDBLog::Modules);
798822
Status error;
799823

800824
module_sp.reset();
@@ -810,21 +834,22 @@ ModuleList::GetSharedModule(const ModuleSpec &module_spec, ModuleSP &module_sp,
810834
// function is actively working on it by doing an extra lock on the global
811835
// mutex list.
812836
if (!always_create) {
837+
LLDB_LOGF(log,"GetSharedModule %d",__LINE__);
813838
ModuleList matching_module_list;
814839
shared_module_list.FindModules(module_spec, matching_module_list);
815840
const size_t num_matching_modules = matching_module_list.GetSize();
816841

842+
LLDB_LOGF(log,"GetSharedModule %d %d",__LINE__,num_matching_modules);
817843
if (num_matching_modules > 0) {
818844
for (size_t module_idx = 0; module_idx < num_matching_modules;
819845
++module_idx) {
820846
module_sp = matching_module_list.GetModuleAtIndex(module_idx);
821847

822848
// Make sure the file for the module hasn't been modified
823849
if (module_sp->FileHasChanged()) {
824-
if (old_modules)
850+
if (old_modules)
825851
old_modules->push_back(module_sp);
826-
827-
Log *log = GetLog(LLDBLog::Modules);
852+
828853
if (log != nullptr)
829854
LLDB_LOGF(
830855
log, "%p '%s' module changed: removing from global module list",
@@ -850,9 +875,11 @@ ModuleList::GetSharedModule(const ModuleSpec &module_spec, ModuleSP &module_sp,
850875
// valid file path with an architecture that might not be in that file. By
851876
// getting the object file we can guarantee that the architecture matches
852877
if (module_sp->GetObjectFile()) {
878+
LLDB_LOGF(log,"GetSharedModule %d",__LINE__);
853879
// If we get in here we got the correct arch, now we just need to verify
854880
// the UUID if one was given
855881
if (uuid_ptr && *uuid_ptr != module_sp->GetUUID()) {
882+
LLDB_LOGF(log,"GetSharedModule %d",__LINE__);
856883
module_sp.reset();
857884
} else {
858885
if (module_sp->GetObjectFile() &&
@@ -863,7 +890,10 @@ ModuleList::GetSharedModule(const ModuleSpec &module_spec, ModuleSP &module_sp,
863890
if (did_create_ptr) {
864891
*did_create_ptr = true;
865892
}
866-
893+
if(module_sp)
894+
LLDB_LOGF(log," module File Name: %s",module_sp->GetFileSpec().GetFilename().AsCString());
895+
if(old_modules)
896+
LLDB_LOGF(log,"GetSharedModule %d",__LINE__);
867897
shared_module_list.ReplaceEquivalent(module_sp, old_modules);
868898
return error;
869899
}
@@ -901,6 +931,7 @@ ModuleList::GetSharedModule(const ModuleSpec &module_spec, ModuleSP &module_sp,
901931
if (did_create_ptr)
902932
*did_create_ptr = true;
903933

934+
LLDB_LOGF(log,"GetSharedModule %d",__LINE__);
904935
shared_module_list.ReplaceEquivalent(module_sp, old_modules);
905936
return Status();
906937
}
@@ -969,13 +1000,15 @@ ModuleList::GetSharedModule(const ModuleSpec &module_spec, ModuleSP &module_sp,
9691000
if (!matching_module_list.IsEmpty()) {
9701001
module_sp = matching_module_list.GetModuleAtIndex(0);
9711002

1003+
LLDB_LOGF(log,"GetSharedModule %d",__LINE__);
9721004
// If we didn't have a UUID in mind when looking for the object file,
9731005
// then we should make sure the modification time hasn't changed!
9741006
if (platform_module_spec.GetUUIDPtr() == nullptr) {
9751007
auto file_spec_mod_time = FileSystem::Instance().GetModificationTime(
9761008
located_binary_modulespec.GetFileSpec());
9771009
if (file_spec_mod_time != llvm::sys::TimePoint<>()) {
9781010
if (file_spec_mod_time != module_sp->GetModificationTime()) {
1011+
LLDB_LOGF(log,"GetSharedModule %d",__LINE__);
9791012
if (old_modules)
9801013
old_modules->push_back(module_sp);
9811014
shared_module_list.Remove(module_sp);
@@ -986,6 +1019,7 @@ ModuleList::GetSharedModule(const ModuleSpec &module_spec, ModuleSP &module_sp,
9861019
}
9871020

9881021
if (!module_sp) {
1022+
LLDB_LOGF(log,"GetSharedModule %d",__LINE__);
9891023
module_sp = std::make_shared<Module>(platform_module_spec);
9901024
// Make sure there are a module and an object file since we can specify a
9911025
// valid file path with an architecture that might not be in that file.
@@ -999,6 +1033,7 @@ ModuleList::GetSharedModule(const ModuleSpec &module_spec, ModuleSP &module_sp,
9991033
if (did_create_ptr)
10001034
*did_create_ptr = true;
10011035

1036+
LLDB_LOGF(log,"GetSharedModule %d",__LINE__);
10021037
shared_module_list.ReplaceEquivalent(module_sp, old_modules);
10031038
}
10041039
} else {

lldb/source/Core/Section.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include "lldb/Target/Target.h"
1515
#include "lldb/Utility/FileSpec.h"
1616
#include "lldb/Utility/VMRange.h"
17+
#include "lldb/Utility/LLDBLog.h"
18+
#include "lldb/Utility/Log.h"
1719

1820
#include <cinttypes>
1921
#include <limits>
@@ -259,9 +261,16 @@ bool Section::ResolveContainedAddress(addr_t offset, Address &so_addr,
259261
}
260262
so_addr.SetOffset(offset);
261263
so_addr.SetSection(const_cast<Section *>(this)->shared_from_this());
262-
263-
// Ensure that there are no orphaned (i.e., moduleless) sections.
264-
assert(GetModule().get());
264+
Log *log = GetLog(LLDBLog::DynamicLoader);
265+
//LLDB_LOGF(log,"Section::ResolveContainedAddress %s",GetModule().GetName());
266+
267+
//llvm::Module *module = GetModule();
268+
lldb::ModuleSP module = GetModule();
269+
//LLDB_LOGF(log,"Section::ResolveContainedAddress %s",module->GetSpecificationDescription().c_str());
270+
if(module.get() == NULL)
271+
LLDB_LOGF(log,"Section::issue with");
272+
// Ensure that there are no orphaned (i.e., moduleless) sections.
273+
// assert(GetModule().get());
265274
return true;
266275
}
267276

lldb/source/Plugins/DynamicLoader/AIX-DYLD/DynamicLoaderAIXDYLD.cpp

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <iostream>
2727
#include <fstream>
2828
#endif
29+
#include "/LLDB/hemang/lldb-for-aix/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.h"
2930

3031
/*#include "llvm/ADT/Triple.h"
3132
*/
@@ -89,7 +90,10 @@ void DynamicLoaderAIXDYLD::OnLoadModule(lldb::ModuleSP module_sp,
8990
}
9091

9192
void DynamicLoaderAIXDYLD::OnUnloadModule(lldb::addr_t module_addr) {
92-
Address resolved_addr;
93+
Log *log = GetLog(LLDBLog::DynamicLoader);
94+
LLDB_LOGF(log, "DynamicLoaderAIXDYLD::%s()", __FUNCTION__);
95+
96+
Address resolved_addr;
9397
if (!m_process->GetTarget().ResolveLoadAddress(module_addr, resolved_addr))
9498
return;
9599

@@ -150,7 +154,7 @@ void DynamicLoaderAIXDYLD::ResolveExecutableModule(
150154
ProcessInstanceInfo process_info;
151155
if (!m_process->GetProcessInfo(process_info)) {
152156
LLDB_LOGF(log,
153-
"DynamicLoaderPOSIXDYLD::%s - failed to get process info for "
157+
"DynamicLoaderAIXDYLD::%s - failed to get process info for "
154158
"pid %" PRIu64,
155159
__FUNCTION__, m_process->GetID());
156160
return;
@@ -201,15 +205,16 @@ void DynamicLoaderAIXDYLD::ResolveExecutableModule(
201205
true);
202206

203207
LLDB_LOGF(
204-
log, "DynamicLoaderPOSIXDYLD::%s - got executable by pid %" PRIu64 ": %s",
208+
log, "DynamicLoaderAIXDYLD::%s - got executable by pid %" PRIu64 ": %s",
205209
__FUNCTION__, m_process->GetID(),
206210
process_info.GetExecutableFile().GetPath().c_str());
207211

208212
ModuleSpec module_spec(process_info.GetExecutableFile(),
209213
process_info.GetArchitecture());
214+
210215
if (module_sp && module_sp->MatchesModuleSpec(module_spec))
211216
return;
212-
217+
LLDB_LOGF(log,"DynamicLoaderAIXDYLD::%s",__FUNCTION__);
213218
const auto executable_search_paths(Target::GetDefaultExecutableSearchPaths());
214219
auto error = platform_sp->ResolveExecutable(
215220
module_spec, module_sp,
@@ -222,21 +227,34 @@ void DynamicLoaderAIXDYLD::ResolveExecutableModule(
222227
"DynamicLoaderPOSIXDYLD::%s - failed to resolve executable "
223228
"with module spec \"%s\": %s",
224229
__FUNCTION__, stream.GetData(), error.AsCString());
230+
225231
return;
226232
}
227233

228234
target.SetExecutableModule(module_sp, eLoadDependentsNo);
229235
}
230236

231237
void DynamicLoaderAIXDYLD::DidAttach() {
232-
Log *log = GetLog(LLDBLog::DynamicLoader);
238+
Log *log = GetLog(LLDBLog::DynamicLoader);
233239
LLDB_LOGF(log, "DynamicLoaderAIXDYLD::%s()", __FUNCTION__);
234240

235241
ModuleSP executable = GetTargetExecutable();
236242
ResolveExecutableModule(executable);
237243

244+
Module *exe_mod = m_process->GetTarget().GetExecutableModulePointer();
245+
if (exe_mod) {
246+
exe_mod->GetPlatformFileSpec();
247+
LLDB_LOGF(log, "DynamicLoaderAIXDYLD::%s exe module executable path set",
248+
__FUNCTION__);
249+
} else {
250+
LLDB_LOGF(log,
251+
"DynamicLoaderAIXDYLD::%s cannot cache exe module path: null "
252+
"executable module pointer",
253+
__FUNCTION__);
254+
}
255+
238256
if (!executable.get())
239-
return;
257+
return;
240258
LLDB_LOGF(log, "DynamicLoaderAIXDYLD::%s()", __FUNCTION__);
241259

242260
// Try to fetch the load address of the file from the process, since there
@@ -245,6 +263,7 @@ void DynamicLoaderAIXDYLD::DidAttach() {
245263
if (load_addr == LLDB_INVALID_ADDRESS)
246264
return;
247265

266+
LLDB_LOGF(log,"DidAttach load_addr 0x%p",load_addr);
248267
// Request the process base address.
249268
lldb::addr_t image_base = m_process->GetImageInfoAddress();
250269
if (image_base == load_addr)
@@ -253,13 +272,25 @@ void DynamicLoaderAIXDYLD::DidAttach() {
253272
// Rebase the process's modules if there is a mismatch.
254273
UpdateLoadedSections(executable, LLDB_INVALID_ADDRESS, load_addr, false);
255274

275+
/*
276+
DYLDRendezvous m_rendezvous(m_process);
277+
if (!m_rendezvous.Resolve()) {
278+
LLDB_LOGF(log,
279+
"DynamicLoaderPOSIXDYLD::%s unable to resolve POSIX DYLD "
280+
"rendezvous address",
281+
__FUNCTION__);
282+
return;
283+
} */
284+
285+
256286
ModuleList module_list;
257287
module_list.Append(executable);
258288
m_process->GetTarget().ModulesDidLoad(module_list);
259289
auto error = m_process->LoadModules();
260290
LLDB_LOG_ERROR(log, std::move(error), "failed to load modules: {0}");
261291

262292
#if defined(_AIX)
293+
LLDB_LOGF(log, "DynamicLoaderAIXDYLD::%s() 289", __FUNCTION__);
263294
// Get struct ld_xinfo (FIXME)
264295
struct ld_xinfo ldinfo[64];
265296
Status status = m_process->GetLDXINFO(&(ldinfo[0]));
@@ -281,8 +312,10 @@ void DynamicLoaderAIXDYLD::DidAttach() {
281312
} else {
282313
sprintf(pathWithMember, "%s", pathName);
283314
}
315+
LLDB_LOGF(log, "DynamicLoaderAIXDYLD1::%s(), %s", __FUNCTION__,pathWithMember);
284316
FileSpec file(pathWithMember);
285317
ModuleSpec module_spec(file, m_process->GetTarget().GetArchitecture());
318+
LLDB_LOGF(log,"After dis %s",module_spec.GetFileSpec().GetPath().c_str());
286319
if (ModuleSP module_sp = m_process->GetTarget().GetOrCreateModule(module_spec, true /* notify */)) {
287320
UpdateLoadedSectionsByType(module_sp, LLDB_INVALID_ADDRESS, (lldb::addr_t)ptr->ldinfo_textorg, false, 1);
288321
UpdateLoadedSectionsByType(module_sp, LLDB_INVALID_ADDRESS, (lldb::addr_t)ptr->ldinfo_dataorg, false, 2);
@@ -309,6 +342,7 @@ void DynamicLoaderAIXDYLD::DidLaunch() {
309342
return;
310343

311344
lldb::addr_t load_addr = GetLoadAddress(executable);
345+
LLDB_LOGF(log,"DidLaunch load_addr 0x%p",load_addr);
312346
if (load_addr != LLDB_INVALID_ADDRESS) {
313347
// Update the loaded sections so that the breakpoints can be resolved.
314348
UpdateLoadedSections(executable, LLDB_INVALID_ADDRESS, load_addr, false);

lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,15 +354,14 @@ bool ObjectFileXCOFF::SetLoadAddress(Target &target, lldb::addr_t value,
354354

355355
bool ObjectFileXCOFF::SetLoadAddressByType(Target &target, lldb::addr_t value,
356356
bool value_is_offset, int type_id) {
357-
bool changed = false;
357+
bool changed = false;
358358
ModuleSP module_sp = GetModule();
359359
if (module_sp) {
360360
size_t num_loaded_sections = 0;
361361
SectionList *section_list = GetSectionList();
362362
if (section_list) {
363363
const size_t num_sections = section_list->GetSize();
364364
size_t sect_idx = 0;
365-
366365
for (sect_idx = 0; sect_idx < num_sections; ++sect_idx) {
367366
// Iterate through the object file sections to find all of the sections
368367
// that have SHF_ALLOC in their flag bits.

0 commit comments

Comments
 (0)