diff options
| author | Jan Kratochvil <jan.kratochvil@redhat.com> | 2019-12-21 11:12:17 +0100 |
|---|---|---|
| committer | Jan Kratochvil <jan.kratochvil@redhat.com> | 2019-12-21 11:12:17 +0100 |
| commit | df6879ec0227a8a5e5697e505201d0f4444f03a4 (patch) | |
| tree | f815307f4aa13a806498a5d0ebd22487c26935b5 | |
| parent | 4af68667088cca5342babd1be4a72731f472bf25 (diff) | |
| download | bcm5719-llvm-df6879ec0227a8a5e5697e505201d0f4444f03a4.tar.gz bcm5719-llvm-df6879ec0227a8a5e5697e505201d0f4444f03a4.zip | |
[lldb] Fix ARM32 inferior calls
echo -e '#include <unistd.h>\nint main(void){\nsync();return 0;}'|./bin/clang -g -x c -;./bin/lldb -o 'file ./a.out' -o 'b main' -o r -o 'p (void)sync()'
Actual:
error: Expression can't be run, because there is no JIT compiled function
Expected:
<nothing, sync() has been executed>
This patch has been checked by:
D71707: clang-tidy: new bugprone-pointer-cast-widening
https://reviews.llvm.org/D71707
Casting from 32-bit `void *` to `uint64_t` requires an intermediate `uintptr_t` cast otherwise the pointer gets sign-extended:
echo -e '#include <stdio.h>\n#include <stdint.h>\nint main(void){void *p=(void *)0x80000000;unsigned long long ull=(unsigned long long)p;unsigned long long ull2=(unsigned long
long)(uintptr_t)p;printf("p=%p ull=0x%llx ull2=0x%llx\\n",p,ull,ull2);return 0;}'|gcc -Wall -m32 -x c -;./a.out
<stdin>: In function ‘main’:
<stdin>:3:66: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
p=0x80000000 ull=0xffffffff80000000 ull2=0x80000000
With debug output:
Actual:
IRMemoryMap::WriteMemory (0xb6ff8640, 0xffffffffb6f82158, 0x112) went to [0xb6ff8640..0xb6ff86b3)
Code can be run in the target.
Found function, has local address 0xffffffffb6f84000 and remote address 0xffffffffffffffff
Couldn't disassemble function : Couldn't find code range for function _Z12$__lldb_exprPv
Sections:
[0xb6f84000+0x3c]->0xb6ff9020 (alignment 4, section ID 0, name .text)
...
HandleCommand, command did not succeed
error: Expression can't be run, because there is no JIT compiled function
Expected:
IRMemoryMap::WriteMemory (0xb6ff8640, 0xb6faa15c, 0x128) went to [0xb6ff8640..0xb6ff86c3)
IRExecutionUnit::GetRemoteAddressForLocal() found 0xb6fac000 in [0xb6fac000..0xb6fac040], and returned 0xb6ff9020 from [0xb6ff9020..0xb6ff9060].
Code can be run in the target.
Found function, has local address 0xb6fac000 and remote address 0xb6ff9020
Function's code range is [0xb6ff9020+0x40]
...
Function data has contents:
0xb6ff9020: 10 4c 2d e9 08 b0 8d e2 08 d0 4d e2 00 40 a0 e1
...
Function disassembly:
0xb6ff9020: 0xe92d4c10 push {r4, r10, r11, lr}
Differential revision: https://reviews.llvm.org/D71498
| -rw-r--r-- | lldb/source/Core/PluginManager.cpp | 2 | ||||
| -rw-r--r-- | lldb/source/Expression/IRExecutionUnit.cpp | 2 | ||||
| -rw-r--r-- | lldb/source/Expression/IRMemoryMap.cpp | 12 | ||||
| -rw-r--r-- | lldb/source/Host/common/HostInfoBase.cpp | 4 | ||||
| -rw-r--r-- | lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp | 2 | ||||
| -rw-r--r-- | lldb/source/Plugins/Process/POSIX/CrashReason.cpp | 8 |
6 files changed, 15 insertions, 15 deletions
diff --git a/lldb/source/Core/PluginManager.cpp b/lldb/source/Core/PluginManager.cpp index 80b64fb832f..e8bfef72437 100644 --- a/lldb/source/Core/PluginManager.cpp +++ b/lldb/source/Core/PluginManager.cpp @@ -86,7 +86,7 @@ static void SetPluginInfo(const FileSpec &plugin_file_spec, } template <typename FPtrTy> static FPtrTy CastToFPtr(void *VPtr) { - return reinterpret_cast<FPtrTy>(reinterpret_cast<intptr_t>(VPtr)); + return reinterpret_cast<FPtrTy>(VPtr); } static FileSystem::EnumerateDirectoryResult diff --git a/lldb/source/Expression/IRExecutionUnit.cpp b/lldb/source/Expression/IRExecutionUnit.cpp index bdf3c92a311..e033b90cfd8 100644 --- a/lldb/source/Expression/IRExecutionUnit.cpp +++ b/lldb/source/Expression/IRExecutionUnit.cpp @@ -348,7 +348,7 @@ void IRExecutionUnit::GetRunnableInfo(Status &error, lldb::addr_t &func_addr, return; } m_jitted_functions.push_back(JittedFunction( - function.getName().str().c_str(), external, (lldb::addr_t)fun_ptr)); + function.getName().str().c_str(), external, reinterpret_cast<uintptr_t>(fun_ptr))); } CommitAllocations(process_sp); diff --git a/lldb/source/Expression/IRMemoryMap.cpp b/lldb/source/Expression/IRMemoryMap.cpp index 5fdf452bf94..02a875ec833 100644 --- a/lldb/source/Expression/IRMemoryMap.cpp +++ b/lldb/source/Expression/IRMemoryMap.cpp @@ -328,9 +328,9 @@ lldb::addr_t IRMemoryMap::Malloc(size_t size, uint8_t alignment, case eAllocationPolicyMirror: process_sp = m_process_wp.lock(); LLDB_LOGF(log, - "IRMemoryMap::%s process_sp=0x%" PRIx64 + "IRMemoryMap::%s process_sp=0x%" PRIxPTR ", process_sp->CanJIT()=%s, process_sp->IsAlive()=%s", - __FUNCTION__, (lldb::addr_t)process_sp.get(), + __FUNCTION__, reinterpret_cast<uintptr_t>(process_sp.get()), process_sp && process_sp->CanJIT() ? "true" : "false", process_sp && process_sp->IsAlive() ? "true" : "false"); if (process_sp && process_sp->CanJIT() && process_sp->IsAlive()) { @@ -577,9 +577,9 @@ void IRMemoryMap::WriteMemory(lldb::addr_t process_address, if (lldb_private::Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)) { LLDB_LOGF(log, - "IRMemoryMap::WriteMemory (0x%" PRIx64 ", 0x%" PRIx64 + "IRMemoryMap::WriteMemory (0x%" PRIx64 ", 0x%" PRIxPTR ", 0x%" PRId64 ") went to [0x%" PRIx64 "..0x%" PRIx64 ")", - (uint64_t)process_address, (uint64_t)bytes, (uint64_t)size, + (uint64_t)process_address, reinterpret_cast<uintptr_t>(bytes), (uint64_t)size, (uint64_t)allocation.m_process_start, (uint64_t)allocation.m_process_start + (uint64_t)allocation.m_size); @@ -708,9 +708,9 @@ void IRMemoryMap::ReadMemory(uint8_t *bytes, lldb::addr_t process_address, if (lldb_private::Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)) { LLDB_LOGF(log, - "IRMemoryMap::ReadMemory (0x%" PRIx64 ", 0x%" PRIx64 + "IRMemoryMap::ReadMemory (0x%" PRIx64 ", 0x%" PRIxPTR ", 0x%" PRId64 ") came from [0x%" PRIx64 "..0x%" PRIx64 ")", - (uint64_t)process_address, (uint64_t)bytes, (uint64_t)size, + (uint64_t)process_address, reinterpret_cast<uintptr_t>(bytes), (uint64_t)size, (uint64_t)allocation.m_process_start, (uint64_t)allocation.m_process_start + (uint64_t)allocation.m_size); diff --git a/lldb/source/Host/common/HostInfoBase.cpp b/lldb/source/Host/common/HostInfoBase.cpp index c69f705fa60..0b24188d339 100644 --- a/lldb/source/Host/common/HostInfoBase.cpp +++ b/lldb/source/Host/common/HostInfoBase.cpp @@ -246,8 +246,8 @@ bool HostInfoBase::ComputeSharedLibraryDirectory(FileSpec &file_spec) { // On other posix systems, we will get .../lib(64|32)?/liblldb.so. FileSpec lldb_file_spec(Host::GetModuleFileSpecForHostAddress( - reinterpret_cast<void *>(reinterpret_cast<intptr_t>( - HostInfoBase::ComputeSharedLibraryDirectory)))); + reinterpret_cast<void *>( + HostInfoBase::ComputeSharedLibraryDirectory))); // This is necessary because when running the testsuite the shlib might be a // symbolic link inside the Python resource dir. diff --git a/lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp b/lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp index 4e871f7d6a4..103a7ee46f3 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp @@ -355,7 +355,7 @@ bool IRForTarget::CreateResultVariable(llvm::Function &llvm_function) { ConstantInt *new_constant_int = ConstantInt::get(llvm::Type::getInt64Ty(m_module->getContext()), - reinterpret_cast<uint64_t>(result_decl), false); + reinterpret_cast<uintptr_t>(result_decl), false); llvm::Metadata *values[2]; values[0] = ConstantAsMetadata::get(new_result_global); diff --git a/lldb/source/Plugins/Process/POSIX/CrashReason.cpp b/lldb/source/Plugins/Process/POSIX/CrashReason.cpp index 9678e48436e..b872269fdfe 100644 --- a/lldb/source/Plugins/Process/POSIX/CrashReason.cpp +++ b/lldb/source/Plugins/Process/POSIX/CrashReason.cpp @@ -136,15 +136,15 @@ std::string GetCrashReasonString(CrashReason reason, const siginfo_t &info) { #if defined(si_lower) && defined(si_upper) if (reason == CrashReason::eBoundViolation) { str = "signal SIGSEGV"; - AppendBounds(str, reinterpret_cast<lldb::addr_t>(info.si_lower), - reinterpret_cast<lldb::addr_t>(info.si_upper), - reinterpret_cast<lldb::addr_t>(info.si_addr)); + AppendBounds(str, reinterpret_cast<uintptr_t>(info.si_lower), + reinterpret_cast<uintptr_t>(info.si_upper), + reinterpret_cast<uintptr_t>(info.si_addr)); return str; } #endif return GetCrashReasonString(reason, - reinterpret_cast<lldb::addr_t>(info.si_addr)); + reinterpret_cast<uintptr_t>(info.si_addr)); } std::string GetCrashReasonString(CrashReason reason, lldb::addr_t fault_addr) { |

