Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 28 additions & 13 deletions lldb/source/Host/freebsd/Host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
#include <sys/sysctl.h>
#include <sys/user.h>

#include <machine/elf.h>

#include <cstdio>
#include <dlfcn.h>
#include <execinfo.h>

#include "llvm/Object/ELF.h"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please group this together with the llvm header below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I totally fix the issue for i386 on x86_64 platform. Also includes this suggestion. Thanks!

#162890


#include "lldb/Host/FileSystem.h"
#include "lldb/Host/Host.h"
#include "lldb/Host/HostInfo.h"
#include "lldb/Utility/DataBufferHeap.h"
Expand Down Expand Up @@ -97,17 +98,33 @@ GetFreeBSDProcessArgs(const ProcessInstanceInfoMatch *match_info_ptr,
proc_args.AppendArgument(llvm::StringRef(cstr));
}

return true;
}

static bool GetFreeBSDProcessCPUType(ProcessInstanceInfo &process_info) {
if (process_info.ProcessIDIsValid()) {
process_info.GetArchitecture() =
HostInfo::GetArchitecture(HostInfo::eArchKindDefault);
auto buffer_sp = FileSystem::Instance().CreateDataBuffer(pathname, 0x20, 0);
if (!buffer_sp) {
process_info.Clear();
return true;
}
process_info.GetArchitecture().Clear();
return false;
uint8_t exe_class =
llvm::object::getElfArchType(
{reinterpret_cast<const char *>(buffer_sp->GetBytes()),
size_t(buffer_sp->GetByteSize())})
.first;

switch (exe_class) {
case llvm::ELF::ELFCLASS32:
process_info.SetArchitecture(
HostInfo::GetArchitecture(HostInfo::eArchKind32));
break;
case llvm::ELF::ELFCLASS64:
process_info.SetArchitecture(
HostInfo::GetArchitecture(HostInfo::eArchKind64));
break;
case llvm::ELF::ELFCLASSNONE:
process_info.SetArchitecture(
HostInfo::GetArchitecture(HostInfo::eArchKindDefault));
break;
}

return true;
}

static bool GetFreeBSDProcessUserAndGroup(ProcessInstanceInfo &process_info) {
Expand Down Expand Up @@ -214,7 +231,6 @@ uint32_t Host::FindProcessesImpl(const ProcessInstanceInfoMatch &match_info,
// Make sure our info matches before we go fetch the name and cpu type
if (match_info_noname.Matches(process_info) &&
GetFreeBSDProcessArgs(&match_info, process_info)) {
GetFreeBSDProcessCPUType(process_info);
if (match_info.Matches(process_info))
process_infos.push_back(process_info);
}
Expand All @@ -228,7 +244,6 @@ bool Host::GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &process_info) {

if (GetFreeBSDProcessArgs(NULL, process_info)) {
// should use libprocstat instead of going right into sysctl?
GetFreeBSDProcessCPUType(process_info);
GetFreeBSDProcessUserAndGroup(process_info);
return true;
}
Expand Down
Loading