forked from OSchip/llvm-project
Patch from Dragos Tatulea which was a modified version of a patch from
Joel Dillon that fixed 64 debugging for Linux. I also added a patch to fix up the ProcessLinux::DoLaunch() to be up to date. I wasn't able to verify it compiles, but it should b really close. llvm-svn: 143772
This commit is contained in:
parent
ce6733a542
commit
386ff18a4a
|
@ -87,10 +87,16 @@ ProcessLinux::ProcessLinux(Target& target, Listener &listener)
|
|||
m_in_limbo(false),
|
||||
m_exit_now(false)
|
||||
{
|
||||
|
||||
#if 0
|
||||
// FIXME: Putting this code in the ctor and saving the byte order in a
|
||||
// member variable is a hack to avoid const qual issues in GetByteOrder.
|
||||
ObjectFile *obj_file = GetTarget().GetExecutableModule()->GetObjectFile();
|
||||
m_byte_order = obj_file->GetByteOrder();
|
||||
#else
|
||||
// XXX: Will work only for local processes.
|
||||
m_byte_order = lldb::endian::InlHostByteOrder();
|
||||
#endif
|
||||
}
|
||||
|
||||
ProcessLinux::~ProcessLinux()
|
||||
|
@ -138,22 +144,47 @@ ProcessLinux::WillLaunch(Module* module)
|
|||
}
|
||||
|
||||
Error
|
||||
ProcessLinux::DoLaunch(Module *module,
|
||||
char const *argv[],
|
||||
char const *envp[],
|
||||
uint32_t launch_flags,
|
||||
const char *stdin_path,
|
||||
const char *stdout_path,
|
||||
const char *stderr_path,
|
||||
const char *working_directory)
|
||||
ProcessLinux::DoLaunch (Module *module,
|
||||
const ProcessLaunchInfo &launch_info)
|
||||
{
|
||||
Error error;
|
||||
assert(m_monitor == NULL);
|
||||
|
||||
SetPrivateState(eStateLaunching);
|
||||
m_monitor = new ProcessMonitor(this, module,
|
||||
argv, envp,
|
||||
stdin_path, stdout_path, stderr_path,
|
||||
|
||||
uint32_t launch_flags = launch_info.GetFlags().Get();
|
||||
const char *stdin_path = NULL;
|
||||
const char *stdout_path = NULL;
|
||||
const char *stderr_path = NULL;
|
||||
const char *working_dir = launch_info.GetWorkingDirectory();
|
||||
|
||||
const ProcessLaunchInfo::FileAction *file_action;
|
||||
file_action = launch_info.GetFileActionForFD (STDIN_FILENO);
|
||||
if (file_action)
|
||||
{
|
||||
if (file_action->GetAction () == ProcessLaunchInfo::FileAction::eFileActionOpen)
|
||||
stdin_path = file_action->GetPath();
|
||||
}
|
||||
file_action = launch_info.GetFileActionForFD (STDOUT_FILENO);
|
||||
if (file_action)
|
||||
{
|
||||
if (file_action->GetAction () == ProcessLaunchInfo::FileAction::eFileActionOpen)
|
||||
stdout_path = file_action->GetPath();
|
||||
}
|
||||
file_action = launch_info.GetFileActionForFD (STDERR_FILENO);
|
||||
if (file_action)
|
||||
{
|
||||
if (file_action->GetAction () == ProcessLaunchInfo::FileAction::eFileActionOpen)
|
||||
stderr_path = file_action->GetPath();
|
||||
}
|
||||
|
||||
m_monitor = new ProcessMonitor (this,
|
||||
module,
|
||||
launch_info.GetArguments().GetConstArgumentVector(),
|
||||
launch_info.GetEnvironmentEntries().GetConstArgumentVector(),
|
||||
stdin_path,
|
||||
stdout_path,
|
||||
stderr_path,
|
||||
error);
|
||||
|
||||
m_module = module;
|
||||
|
|
|
@ -67,14 +67,8 @@ public:
|
|||
DoAttachToProcessWithID(lldb::pid_t pid);
|
||||
|
||||
virtual lldb_private::Error
|
||||
DoLaunch(lldb_private::Module *module,
|
||||
char const *argv[],
|
||||
char const *envp[],
|
||||
uint32_t launch_flags,
|
||||
const char *stdin_path,
|
||||
const char *stdout_path,
|
||||
const char *stderr_path,
|
||||
const char *working_directory);
|
||||
DoLaunch (lldb_private::Module *exe_module,
|
||||
const lldb_private::ProcessLaunchInfo &launch_info);
|
||||
|
||||
virtual void
|
||||
DidLaunch();
|
||||
|
|
|
@ -34,6 +34,8 @@
|
|||
#include "ProcessMonitor.h"
|
||||
|
||||
|
||||
#define DEBUG_PTRACE_MAXBYTES 20
|
||||
|
||||
using namespace lldb_private;
|
||||
|
||||
// FIXME: this code is host-dependent with respect to types and
|
||||
|
@ -46,21 +48,91 @@ using namespace lldb_private;
|
|||
// avoid the additional indirection and checks.
|
||||
#ifndef LLDB_CONFIGURATION_BUILDANDINTEGRATION
|
||||
|
||||
static void
|
||||
DisplayBytes (lldb_private::StreamString &s, void *bytes, uint32_t count)
|
||||
{
|
||||
uint8_t *ptr = (uint8_t *)bytes;
|
||||
const uint32_t loop_count = std::min<uint32_t>(DEBUG_PTRACE_MAXBYTES, count);
|
||||
for(uint32_t i=0; i<loop_count; i++)
|
||||
{
|
||||
s.Printf ("[%x]", *ptr);
|
||||
ptr++;
|
||||
}
|
||||
}
|
||||
|
||||
static void PtraceDisplayBytes(__ptrace_request &req, void *data)
|
||||
{
|
||||
StreamString buf;
|
||||
LogSP verbose_log (ProcessLinuxLog::GetLogIfAllCategoriesSet (
|
||||
LINUX_LOG_PTRACE | LINUX_LOG_VERBOSE));
|
||||
|
||||
if (verbose_log)
|
||||
{
|
||||
switch(req)
|
||||
{
|
||||
case PTRACE_POKETEXT:
|
||||
{
|
||||
DisplayBytes(buf, &data, 8);
|
||||
verbose_log->Printf("PTRACE_POKETEXT %s", buf.GetData());
|
||||
break;
|
||||
}
|
||||
case PTRACE_POKEDATA:
|
||||
{
|
||||
DisplayBytes(buf, &data, 8);
|
||||
verbose_log->Printf("PTRACE_POKEDATA %s", buf.GetData());
|
||||
break;
|
||||
}
|
||||
case PTRACE_POKEUSER:
|
||||
{
|
||||
DisplayBytes(buf, &data, 8);
|
||||
verbose_log->Printf("PTRACE_POKEUSER %s", buf.GetData());
|
||||
break;
|
||||
}
|
||||
case PTRACE_SETREGS:
|
||||
{
|
||||
DisplayBytes(buf, data, sizeof(user_regs_struct));
|
||||
verbose_log->Printf("PTRACE_SETREGS %s", buf.GetData());
|
||||
break;
|
||||
}
|
||||
case PTRACE_SETFPREGS:
|
||||
{
|
||||
DisplayBytes(buf, data, sizeof(user_fpregs_struct));
|
||||
verbose_log->Printf("PTRACE_SETFPREGS %s", buf.GetData());
|
||||
break;
|
||||
}
|
||||
case PTRACE_SETSIGINFO:
|
||||
{
|
||||
DisplayBytes(buf, data, sizeof(siginfo_t));
|
||||
verbose_log->Printf("PTRACE_SETSIGINFO %s", buf.GetData());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Wrapper for ptrace to catch errors and log calls.
|
||||
extern long
|
||||
PtraceWrapper(__ptrace_request req, pid_t pid, void *addr, void *data,
|
||||
const char* reqName, const char* file, int line)
|
||||
{
|
||||
int result;
|
||||
long int result;
|
||||
|
||||
LogSP log (ProcessLinuxLog::GetLogIfAllCategoriesSet (LINUX_LOG_PTRACE));
|
||||
|
||||
if (log)
|
||||
log->Printf("ptrace(%s, %u, %p, %p) called from file %s line %d",
|
||||
reqName, pid, addr, data, file, line);
|
||||
|
||||
PtraceDisplayBytes(req, data);
|
||||
|
||||
errno = 0;
|
||||
result = ptrace(req, pid, addr, data);
|
||||
|
||||
PtraceDisplayBytes(req, data);
|
||||
|
||||
if (log && (result == -1 || errno != 0))
|
||||
{
|
||||
const char* str;
|
||||
|
@ -352,7 +424,7 @@ ReadRegOperation::Execute(ProcessMonitor *monitor)
|
|||
|
||||
// Set errno to zero so that we can detect a failed peek.
|
||||
errno = 0;
|
||||
uint32_t data = PTRACE(PTRACE_PEEKUSER, pid, (void*)m_offset, NULL);
|
||||
lldb::addr_t data = PTRACE(PTRACE_PEEKUSER, pid, (void*)m_offset, NULL);
|
||||
if (data == -1UL && errno)
|
||||
m_result = false;
|
||||
else
|
||||
|
|
Loading…
Reference in New Issue