/// the address is currently not loaded.
//------------------------------------------------------------------
lldb::addr_t
- GetCallableLoadAddress (Target *target) const;
+ GetCallableLoadAddress (Target *target, bool is_indirect = false) const;
//------------------------------------------------------------------
/// Get the load address as an opcode load address.
bool
IsTrampoline () const;
+ bool
+ IsIndirect () const;
+
lldb::addr_t
GetByteSize () const;
lldb::addr_t
AllocateMemory (size_t size, uint32_t permissions, Error &error);
+
+ //------------------------------------------------------------------
+ /// Resolve dynamically loaded indirect functions.
+ ///
+ /// @param[in] address
+ /// The load address of the indirect function to resolve.
+ ///
+ /// @param[out] error
+ /// An error value in case the resolve fails.
+ ///
+ /// @return
+ /// The address of the resolved function.
+ /// LLDB_INVALID_ADDRESS if the resolution failed.
+ //------------------------------------------------------------------
+
+ virtual lldb::addr_t
+ ResolveIndirectFunction(const Address *address, Error &error)
+ {
+ error.SetErrorStringWithFormat("error: %s does not support indirect functions in the debug process", GetShortPluginName());
+ return LLDB_INVALID_ADDRESS;
+ }
+
virtual Error
GetMemoryRegionInfo (lldb::addr_t load_addr,
MemoryRegionInfo &range_info)
// return type, otherwise just pass in an invalid ClangASTType.
public:
ThreadPlanCallFunction (Thread &thread,
- Address &function,
+ const Address &function,
const ClangASTType &return_type,
lldb::addr_t arg,
bool stop_other_threads,
lldb::addr_t *cmd_arg = 0);
ThreadPlanCallFunction (Thread &thread,
- Address &function,
+ const Address &function,
const ClangASTType &return_type,
bool stop_other_threads,
bool unwind_on_error,
eSymbolTypeInvalid = 0,
eSymbolTypeAbsolute,
eSymbolTypeCode,
+ eSymbolTypeResolver,
eSymbolTypeData,
eSymbolTypeTrampoline,
eSymbolTypeRuntime,
}
addr_t
-Address::GetCallableLoadAddress (Target *target) const
+Address::GetCallableLoadAddress (Target *target, bool is_indirect) const
{
+ if (is_indirect && target) {
+ ProcessSP processSP = target->GetProcessSP();
+ Error error;
+ if (processSP.get())
+ return processSP->ResolveIndirectFunction(this, error);
+ }
+
addr_t code_addr = GetLoadAddress (target);
if (target)
if (symtab)
{
std::vector<uint32_t> symbol_indexes;
- symtab->FindAllSymbolsWithNameAndType (name, eSymbolTypeCode, Symtab::eDebugAny, Symtab::eVisibilityAny, symbol_indexes);
+ symtab->FindAllSymbolsWithNameAndType (name, eSymbolTypeAny, Symtab::eDebugAny, Symtab::eVisibilityAny, symbol_indexes);
const size_t num_matches = symbol_indexes.size();
if (num_matches)
{
for (size_t i=0; i<num_matches; i++)
{
sc.symbol = symtab->SymbolAtIndex(symbol_indexes[i]);
- sc_list.AppendIfUnique (sc, merge_symbol_into_function);
+ SymbolType sym_type = sc.symbol->GetType();
+ if (sc.symbol && (sym_type == eSymbolTypeCode ||
+ sym_type == eSymbolTypeResolver))
+ sc_list.AppendIfUnique (sc, merge_symbol_into_function);
}
}
}
if (symtab)
{
std::vector<uint32_t> symbol_indexes;
- symtab->AppendSymbolIndexesMatchingRegExAndType (regex, eSymbolTypeCode, Symtab::eDebugAny, Symtab::eVisibilityAny, symbol_indexes);
+ symtab->AppendSymbolIndexesMatchingRegExAndType (regex, eSymbolTypeAny, Symtab::eDebugAny, Symtab::eVisibilityAny, symbol_indexes);
const size_t num_matches = symbol_indexes.size();
if (num_matches)
{
for (size_t i=0; i<num_matches; i++)
{
sc.symbol = symtab->SymbolAtIndex(symbol_indexes[i]);
- sc_list.AppendIfUnique (sc, merge_symbol_into_function);
+ SymbolType sym_type = sc.symbol->GetType();
+ if (sc.symbol && (sym_type == eSymbolTypeCode ||
+ sym_type == eSymbolTypeResolver))
+ sc_list.AppendIfUnique (sc, merge_symbol_into_function);
}
}
}
SymbolContextList &sc_list
)
{
+ SymbolContextList temp_sc_list;
if (sym_ctx.module_sp)
- sym_ctx.module_sp->FindSymbolsWithNameAndType(name, eSymbolTypeCode, sc_list);
+ sym_ctx.module_sp->FindSymbolsWithNameAndType(name, eSymbolTypeAny, temp_sc_list);
- if (!sc_list.GetSize())
- sym_ctx.target_sp->GetImages().FindSymbolsWithNameAndType(name, eSymbolTypeCode, sc_list);
+ if (!sc_list.GetSize() && sym_ctx.target_sp)
+ sym_ctx.target_sp->GetImages().FindSymbolsWithNameAndType(name, eSymbolTypeAny, temp_sc_list);
+
+ unsigned temp_sc_list_size = temp_sc_list.GetSize();
+ for (unsigned i = 0; i < temp_sc_list_size; i++)
+ {
+ SymbolContext sym_ctx;
+ temp_sc_list.GetContextAtIndex(i, sym_ctx);
+ if (sym_ctx.symbol)
+ {
+ switch (sym_ctx.symbol->GetType())
+ {
+ case eSymbolTypeCode:
+ case eSymbolTypeResolver:
+ sc_list.Append(sym_ctx);
+ break;
+
+ default:
+ break;
+ }
+ }
+ }
}
bool
SymbolContextList sc_list;
FindCodeSymbolInContext(name, m_parser_vars->m_sym_ctx, sc_list);
-
+
if (!sc_list.GetSize())
{
// We occasionally get debug information in which a const function is reported
if (!sc_list.GetSize())
return false;
-
+
SymbolContext sym_ctx;
sc_list.GetContextAtIndex(0, sym_ctx);
-
+
const Address *func_so_addr = NULL;
-
+ bool is_indirect_function = false;
+
if (sym_ctx.function)
func_so_addr = &sym_ctx.function->GetAddressRange().GetBaseAddress();
- else if (sym_ctx.symbol)
+ else if (sym_ctx.symbol) {
func_so_addr = &sym_ctx.symbol->GetAddress();
- else
+ is_indirect_function = sym_ctx.symbol->IsIndirect();
+ } else
return false;
-
+
if (!func_so_addr || !func_so_addr->IsValid())
return false;
-
- func_addr = func_so_addr->GetCallableLoadAddress (target);
+
+ func_addr = func_so_addr->GetCallableLoadAddress (target, is_indirect_function);
return true;
}
case eSymbolTypeTrampoline:
symbol_load_addr = sym_address->GetCallableLoadAddress (&target);
break;
-
+
+ case eSymbolTypeResolver:
+ symbol_load_addr = sym_address->GetCallableLoadAddress (&target, true);
+ break;
+
case eSymbolTypeData:
case eSymbolTypeRuntime:
case eSymbolTypeVariable:
case eSymbolTypeCompiler:
case eSymbolTypeInstrumentation:
case eSymbolTypeUndefined:
+ case eSymbolTypeResolver:
break;
}
}
// only valid for Functions, not for Symbols
void *fun_opaque_type = NULL;
ASTContext *fun_ast_context = NULL;
-
+
+ bool is_indirect_function = false;
+
if (fun)
{
Type *fun_type = fun->GetType();
{
fun_address = &symbol->GetAddress();
fun_decl = context.AddGenericFunDecl();
+ is_indirect_function = symbol->IsIndirect();
}
else
{
Target *target = m_parser_vars->m_exe_ctx.GetTargetPtr();
- lldb::addr_t load_addr = fun_address->GetCallableLoadAddress(target);
+ lldb::addr_t load_addr = fun_address->GetCallableLoadAddress(target, is_indirect_function);
fun_location->SetValueType(Value::eValueTypeLoadAddress);
fun_location->GetScalar() = load_addr;
// STB_LOCAL symbols for the file, if it is present.
symbol_type = eSymbolTypeObjectFile;
break;
+
+ case STT_GNU_IFUNC:
+ // The symbol is associated with an indirect function. The actual
+ // function will be resolved if it is referenced.
+ symbol_type = eSymbolTypeResolver;
+ break;
}
}
return error;
}
+addr_t
+ProcessPOSIX::ResolveIndirectFunction(const Address *address, Error &error)
+{
+ addr_t function_addr = LLDB_INVALID_ADDRESS;
+ if (address == NULL) {
+ error.SetErrorStringWithFormat("unable to determine direct function call for NULL address");
+ } else if (!InferiorCall(this, address, function_addr)) {
+ function_addr = LLDB_INVALID_ADDRESS;
+ error.SetErrorStringWithFormat("unable to determine direct function call for indirect function with address %x", address);
+ }
+ return function_addr;
+}
+
size_t
ProcessPOSIX::GetSoftwareBreakpointTrapOpcode(BreakpointSite* bp_site)
{
virtual lldb_private::Error
DoDeallocateMemory(lldb::addr_t ptr);
+ virtual lldb::addr_t
+ ResolveIndirectFunction(const lldb_private::Address *address, lldb_private::Error &error);
+
virtual size_t
GetSoftwareBreakpointTrapOpcode(lldb_private::BreakpointSite* bp_site);
//===----------------------------------------------------------------------===//
#include "InferiorCallPOSIX.h"
+#include "lldb/Core/Address.h"
#include "lldb/Core/StreamFile.h"
#include "lldb/Core/ValueObject.h"
#include "lldb/Symbol/ClangASTContext.h"
if (allocated_addr == UINT32_MAX)
return false;
}
+ else if (process->GetAddressByteSize() == 8)
+ {
+ if (allocated_addr == UINT64_MAX)
+ return false;
+ }
return true;
}
}
return false;
}
+
+bool lldb_private::InferiorCall(Process *process, const Address *address, addr_t &returned_func) {
+ Thread *thread = process->GetThreadList().GetSelectedThread().get();
+ if (thread == NULL || address == NULL)
+ return false;
+
+ const bool stop_other_threads = true;
+ const bool unwind_on_error = true;
+ const bool ignore_breakpoints = true;
+ const bool try_all_threads = true;
+ const uint32_t timeout_usec = 500000;
+
+ ClangASTContext *clang_ast_context = process->GetTarget().GetScratchClangASTContext();
+ lldb::clang_type_t clang_void_ptr_type = clang_ast_context->GetVoidPtrType(false);
+ ThreadPlanCallFunction *call_function_thread_plan
+ = new ThreadPlanCallFunction (*thread,
+ *address,
+ ClangASTType (clang_ast_context->getASTContext(), clang_void_ptr_type),
+ stop_other_threads,
+ unwind_on_error,
+ ignore_breakpoints);
+ lldb::ThreadPlanSP call_plan_sp (call_function_thread_plan);
+ if (call_plan_sp)
+ {
+ StreamFile error_strm;
+ // This plan is a utility plan, so set it to discard itself when done.
+ call_plan_sp->SetIsMasterPlan (true);
+ call_plan_sp->SetOkayToDiscard(true);
+
+ StackFrame *frame = thread->GetStackFrameAtIndex (0).get();
+ if (frame)
+ {
+ ExecutionContext exe_ctx;
+ frame->CalculateExecutionContext (exe_ctx);
+ ExecutionResults result = process->RunThreadPlan (exe_ctx,
+ call_plan_sp,
+ stop_other_threads,
+ try_all_threads,
+ unwind_on_error,
+ ignore_breakpoints,
+ timeout_usec,
+ error_strm);
+ if (result == eExecutionCompleted)
+ {
+ returned_func = call_plan_sp->GetReturnValueObject()->GetValueAsUnsigned(LLDB_INVALID_ADDRESS);
+
+ if (process->GetAddressByteSize() == 4)
+ {
+ if (returned_func == UINT32_MAX)
+ return false;
+ }
+ else if (process->GetAddressByteSize() == 8)
+ {
+ if (returned_func == UINT64_MAX)
+ return false;
+ }
+ return true;
+ }
+ }
+ }
+
+ return false;
+}
bool InferiorCallMunmap(Process *proc, lldb::addr_t addr, lldb::addr_t length);
+bool InferiorCall(Process *proc, const Address *address, lldb::addr_t &returned_func);
+
} // namespace lldb_private
#endif // lldb_InferiorCallPOSIX_h_
return m_type == eSymbolTypeTrampoline;
}
+bool
+Symbol::IsIndirect () const
+{
+ return m_type == eSymbolTypeResolver;
+}
+
void
Symbol::GetDescription (Stream *s, lldb::DescriptionLevel level, Target *target) const
{
uint32_t
Symbol::GetPrologueByteSize ()
{
- if (m_type == eSymbolTypeCode)
+ if (m_type == eSymbolTypeCode || m_type == eSymbolTypeResolver)
{
if (!m_type_data_resolved)
{
}
ThreadPlanCallFunction::ThreadPlanCallFunction (Thread &thread,
- Address &function,
+ const Address &function,
const ClangASTType &return_type,
addr_t arg,
bool stop_other_threads,
ThreadPlanCallFunction::ThreadPlanCallFunction (Thread &thread,
- Address &function,
+ const Address &function,
const ClangASTType &return_type,
bool stop_other_threads,
bool unwind_on_error,
self.buildDsym()
self.static_method_commands()
- @expectedFailureLinux # bugzilla 14437
@dwarf_test
def test_with_dwarf_and_run_command(self):
"""Tests that C strings work as expected in expressions"""
self.expect("expression -- z[2]",
startstr = "(const char) $1 = 'x'")
+ # On Linux, the expression below will test GNU indirect function calls.
self.expect("expression -- (int)strlen(\"hello\")",
startstr = "(int) $2 = 5")