[Lldb-commits] [lldb] r280751 - *** This commit represents a complete reformatting of the LLDB source code
Kate Stone via lldb-commits
lldb-commits at lists.llvm.org
Tue Sep 6 13:58:36 PDT 2016
Modified: lldb/trunk/source/Plugins/ABI/SysV-mips/ABISysV_mips.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ABI/SysV-mips/ABISysV_mips.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ABI/SysV-mips/ABISysV_mips.cpp (original)
+++ lldb/trunk/source/Plugins/ABI/SysV-mips/ABISysV_mips.cpp Tue Sep 6 15:57:50 2016
@@ -25,696 +25,1055 @@
#include "lldb/Core/RegisterValue.h"
#include "lldb/Core/Value.h"
#include "lldb/Core/ValueObjectConstResult.h"
-#include "lldb/Core/ValueObjectRegister.h"
#include "lldb/Core/ValueObjectMemory.h"
+#include "lldb/Core/ValueObjectRegister.h"
#include "lldb/Symbol/UnwindPlan.h"
-#include "lldb/Target/Target.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/RegisterContext.h"
#include "lldb/Target/StackFrame.h"
+#include "lldb/Target/Target.h"
#include "lldb/Target/Thread.h"
using namespace lldb;
using namespace lldb_private;
-enum dwarf_regnums
-{
- dwarf_r0 = 0,
- dwarf_r1,
- dwarf_r2,
- dwarf_r3,
- dwarf_r4,
- dwarf_r5,
- dwarf_r6,
- dwarf_r7,
- dwarf_r8,
- dwarf_r9,
- dwarf_r10,
- dwarf_r11,
- dwarf_r12,
- dwarf_r13,
- dwarf_r14,
- dwarf_r15,
- dwarf_r16,
- dwarf_r17,
- dwarf_r18,
- dwarf_r19,
- dwarf_r20,
- dwarf_r21,
- dwarf_r22,
- dwarf_r23,
- dwarf_r24,
- dwarf_r25,
- dwarf_r26,
- dwarf_r27,
- dwarf_r28,
- dwarf_r29,
- dwarf_r30,
- dwarf_r31,
- dwarf_sr,
- dwarf_lo,
- dwarf_hi,
- dwarf_bad,
- dwarf_cause,
- dwarf_pc
+enum dwarf_regnums {
+ dwarf_r0 = 0,
+ dwarf_r1,
+ dwarf_r2,
+ dwarf_r3,
+ dwarf_r4,
+ dwarf_r5,
+ dwarf_r6,
+ dwarf_r7,
+ dwarf_r8,
+ dwarf_r9,
+ dwarf_r10,
+ dwarf_r11,
+ dwarf_r12,
+ dwarf_r13,
+ dwarf_r14,
+ dwarf_r15,
+ dwarf_r16,
+ dwarf_r17,
+ dwarf_r18,
+ dwarf_r19,
+ dwarf_r20,
+ dwarf_r21,
+ dwarf_r22,
+ dwarf_r23,
+ dwarf_r24,
+ dwarf_r25,
+ dwarf_r26,
+ dwarf_r27,
+ dwarf_r28,
+ dwarf_r29,
+ dwarf_r30,
+ dwarf_r31,
+ dwarf_sr,
+ dwarf_lo,
+ dwarf_hi,
+ dwarf_bad,
+ dwarf_cause,
+ dwarf_pc
};
-static const RegisterInfo
-g_register_infos[] =
-{
- // NAME ALT SZ OFF ENCODING FORMAT EH_FRAME DWARF GENERIC PROCESS PLUGINS LLDB NATIVE VALUE REGS INVALIDATE REGS
- // ======== ====== == === ============= =========== ============ ============== ============ ================= =================== ========== =================
- { "r0" , "zero", 4, 0, eEncodingUint, eFormatHex, { dwarf_r0, dwarf_r0, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r1" , "AT", 4, 0, eEncodingUint, eFormatHex, { dwarf_r1, dwarf_r1, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r2" , "v0", 4, 0, eEncodingUint, eFormatHex, { dwarf_r2, dwarf_r2, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r3" , "v1", 4, 0, eEncodingUint, eFormatHex, { dwarf_r3, dwarf_r3, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r4" , "arg1", 4, 0, eEncodingUint, eFormatHex, { dwarf_r4, dwarf_r4, LLDB_REGNUM_GENERIC_ARG1, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r5" , "arg2", 4, 0, eEncodingUint, eFormatHex, { dwarf_r5, dwarf_r5, LLDB_REGNUM_GENERIC_ARG2, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r6" , "arg3", 4, 0, eEncodingUint, eFormatHex, { dwarf_r6, dwarf_r6, LLDB_REGNUM_GENERIC_ARG3, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r7" , "arg4", 4, 0, eEncodingUint, eFormatHex, { dwarf_r7, dwarf_r7, LLDB_REGNUM_GENERIC_ARG4, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r8" , "arg5", 4, 0, eEncodingUint, eFormatHex, { dwarf_r8, dwarf_r8, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r9" , "arg6", 4, 0, eEncodingUint, eFormatHex, { dwarf_r9, dwarf_r9, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r10" , "arg7", 4, 0, eEncodingUint, eFormatHex, { dwarf_r10, dwarf_r10, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r11" , "arg8", 4, 0, eEncodingUint, eFormatHex, { dwarf_r11, dwarf_r11, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r12" , nullptr,4, 0, eEncodingUint, eFormatHex, { dwarf_r12, dwarf_r12, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r13" , nullptr,4, 0, eEncodingUint, eFormatHex, { dwarf_r13, dwarf_r13, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r14" , nullptr,4, 0, eEncodingUint, eFormatHex, { dwarf_r14, dwarf_r14, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r15" , nullptr,4, 0, eEncodingUint, eFormatHex, { dwarf_r15, dwarf_r15, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r16" , nullptr,4, 0, eEncodingUint, eFormatHex, { dwarf_r16, dwarf_r16, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r17" , nullptr,4, 0, eEncodingUint, eFormatHex, { dwarf_r17, dwarf_r17, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r18" , nullptr,4, 0, eEncodingUint, eFormatHex, { dwarf_r18, dwarf_r18, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r19" , nullptr,4, 0, eEncodingUint, eFormatHex, { dwarf_r19, dwarf_r19, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r20" , nullptr,4, 0, eEncodingUint, eFormatHex, { dwarf_r20, dwarf_r20, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r21" , nullptr,4, 0, eEncodingUint, eFormatHex, { dwarf_r21, dwarf_r21, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r22" , nullptr,4, 0, eEncodingUint, eFormatHex, { dwarf_r22, dwarf_r22, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r23" , nullptr,4, 0, eEncodingUint, eFormatHex, { dwarf_r23, dwarf_r23, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r24" , nullptr,4, 0, eEncodingUint, eFormatHex, { dwarf_r24, dwarf_r24, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r25" , nullptr,4, 0, eEncodingUint, eFormatHex, { dwarf_r25, dwarf_r25, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r26" , nullptr,4, 0, eEncodingUint, eFormatHex, { dwarf_r26, dwarf_r26, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r27" , nullptr,4, 0, eEncodingUint, eFormatHex, { dwarf_r27, dwarf_r27, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r28" , "gp", 4, 0, eEncodingUint, eFormatHex, { dwarf_r28, dwarf_r28, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r29" , "sp", 4, 0, eEncodingUint, eFormatHex, { dwarf_r29, dwarf_r29, LLDB_REGNUM_GENERIC_SP, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r30" , "fp", 4, 0, eEncodingUint, eFormatHex, { dwarf_r30, dwarf_r30, LLDB_REGNUM_GENERIC_FP, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r31" , "ra", 4, 0, eEncodingUint, eFormatHex, { dwarf_r31, dwarf_r31, LLDB_REGNUM_GENERIC_RA, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "sr" , nullptr,4, 0, eEncodingUint, eFormatHex, { dwarf_sr, dwarf_sr, LLDB_REGNUM_GENERIC_FLAGS, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "lo" , nullptr,4, 0, eEncodingUint, eFormatHex, { dwarf_lo, dwarf_lo, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "hi" , nullptr,4, 0, eEncodingUint, eFormatHex, { dwarf_hi, dwarf_hi, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "bad" , nullptr,4, 0, eEncodingUint, eFormatHex, { dwarf_bad, dwarf_bad, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "cause" , nullptr,4, 0, eEncodingUint, eFormatHex, { dwarf_cause, dwarf_cause, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "pc" , nullptr,4, 0, eEncodingUint, eFormatHex, { dwarf_pc, dwarf_pc, LLDB_REGNUM_GENERIC_PC, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
+static const RegisterInfo g_register_infos[] = {
+ // NAME ALT SZ OFF ENCODING FORMAT EH_FRAME
+ // DWARF GENERIC PROCESS PLUGINS
+ // LLDB NATIVE VALUE REGS INVALIDATE REGS
+ // ======== ====== == === ============= =========== ============
+ // ============== ============ =================
+ // =================== ========== =================
+ {"r0",
+ "zero",
+ 4,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r0, dwarf_r0, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r1",
+ "AT",
+ 4,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r1, dwarf_r1, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r2",
+ "v0",
+ 4,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r2, dwarf_r2, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r3",
+ "v1",
+ 4,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r3, dwarf_r3, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r4",
+ "arg1",
+ 4,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r4, dwarf_r4, LLDB_REGNUM_GENERIC_ARG1, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r5",
+ "arg2",
+ 4,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r5, dwarf_r5, LLDB_REGNUM_GENERIC_ARG2, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r6",
+ "arg3",
+ 4,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r6, dwarf_r6, LLDB_REGNUM_GENERIC_ARG3, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r7",
+ "arg4",
+ 4,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r7, dwarf_r7, LLDB_REGNUM_GENERIC_ARG4, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r8",
+ "arg5",
+ 4,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r8, dwarf_r8, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r9",
+ "arg6",
+ 4,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r9, dwarf_r9, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r10",
+ "arg7",
+ 4,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r10, dwarf_r10, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r11",
+ "arg8",
+ 4,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r11, dwarf_r11, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r12",
+ nullptr,
+ 4,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r12, dwarf_r12, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r13",
+ nullptr,
+ 4,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r13, dwarf_r13, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r14",
+ nullptr,
+ 4,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r14, dwarf_r14, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r15",
+ nullptr,
+ 4,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r15, dwarf_r15, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r16",
+ nullptr,
+ 4,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r16, dwarf_r16, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r17",
+ nullptr,
+ 4,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r17, dwarf_r17, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r18",
+ nullptr,
+ 4,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r18, dwarf_r18, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r19",
+ nullptr,
+ 4,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r19, dwarf_r19, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r20",
+ nullptr,
+ 4,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r20, dwarf_r20, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r21",
+ nullptr,
+ 4,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r21, dwarf_r21, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r22",
+ nullptr,
+ 4,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r22, dwarf_r22, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r23",
+ nullptr,
+ 4,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r23, dwarf_r23, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r24",
+ nullptr,
+ 4,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r24, dwarf_r24, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r25",
+ nullptr,
+ 4,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r25, dwarf_r25, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r26",
+ nullptr,
+ 4,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r26, dwarf_r26, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r27",
+ nullptr,
+ 4,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r27, dwarf_r27, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r28",
+ "gp",
+ 4,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r28, dwarf_r28, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r29",
+ "sp",
+ 4,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r29, dwarf_r29, LLDB_REGNUM_GENERIC_SP, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r30",
+ "fp",
+ 4,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r30, dwarf_r30, LLDB_REGNUM_GENERIC_FP, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r31",
+ "ra",
+ 4,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r31, dwarf_r31, LLDB_REGNUM_GENERIC_RA, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"sr",
+ nullptr,
+ 4,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_sr, dwarf_sr, LLDB_REGNUM_GENERIC_FLAGS, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"lo",
+ nullptr,
+ 4,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_lo, dwarf_lo, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"hi",
+ nullptr,
+ 4,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_hi, dwarf_hi, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"bad",
+ nullptr,
+ 4,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_bad, dwarf_bad, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"cause",
+ nullptr,
+ 4,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_cause, dwarf_cause, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"pc",
+ nullptr,
+ 4,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_pc, dwarf_pc, LLDB_REGNUM_GENERIC_PC, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
};
-static const uint32_t k_num_register_infos = llvm::array_lengthof(g_register_infos);
+static const uint32_t k_num_register_infos =
+ llvm::array_lengthof(g_register_infos);
const lldb_private::RegisterInfo *
-ABISysV_mips::GetRegisterInfoArray (uint32_t &count)
-{
- count = k_num_register_infos;
- return g_register_infos;
+ABISysV_mips::GetRegisterInfoArray(uint32_t &count) {
+ count = k_num_register_infos;
+ return g_register_infos;
}
-size_t
-ABISysV_mips::GetRedZoneSize () const
-{
- return 0;
-}
+size_t ABISysV_mips::GetRedZoneSize() const { return 0; }
//------------------------------------------------------------------
// Static Functions
//------------------------------------------------------------------
ABISP
-ABISysV_mips::CreateInstance (const ArchSpec &arch)
-{
- static ABISP g_abi_sp;
- const llvm::Triple::ArchType arch_type = arch.GetTriple().getArch();
- if ((arch_type == llvm::Triple::mips) ||
- (arch_type == llvm::Triple::mipsel))
- {
- if (!g_abi_sp)
- g_abi_sp.reset (new ABISysV_mips);
- return g_abi_sp;
- }
- return ABISP();
+ABISysV_mips::CreateInstance(const ArchSpec &arch) {
+ static ABISP g_abi_sp;
+ const llvm::Triple::ArchType arch_type = arch.GetTriple().getArch();
+ if ((arch_type == llvm::Triple::mips) ||
+ (arch_type == llvm::Triple::mipsel)) {
+ if (!g_abi_sp)
+ g_abi_sp.reset(new ABISysV_mips);
+ return g_abi_sp;
+ }
+ return ABISP();
}
-bool
-ABISysV_mips::PrepareTrivialCall (Thread &thread,
- addr_t sp,
- addr_t func_addr,
- addr_t return_addr,
- llvm::ArrayRef<addr_t> args) const
-{
- Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
+bool ABISysV_mips::PrepareTrivialCall(Thread &thread, addr_t sp,
+ addr_t func_addr, addr_t return_addr,
+ llvm::ArrayRef<addr_t> args) const {
+ Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
+
+ if (log) {
+ StreamString s;
+ s.Printf("ABISysV_mips::PrepareTrivialCall (tid = 0x%" PRIx64
+ ", sp = 0x%" PRIx64 ", func_addr = 0x%" PRIx64
+ ", return_addr = 0x%" PRIx64,
+ thread.GetID(), (uint64_t)sp, (uint64_t)func_addr,
+ (uint64_t)return_addr);
+
+ for (size_t i = 0; i < args.size(); ++i)
+ s.Printf(", arg%zd = 0x%" PRIx64, i + 1, args[i]);
+ s.PutCString(")");
+ log->PutCString(s.GetString().c_str());
+ }
- if (log)
- {
- StreamString s;
- s.Printf("ABISysV_mips::PrepareTrivialCall (tid = 0x%" PRIx64 ", sp = 0x%" PRIx64 ", func_addr = 0x%" PRIx64 ", return_addr = 0x%" PRIx64,
- thread.GetID(),
- (uint64_t)sp,
- (uint64_t)func_addr,
- (uint64_t)return_addr);
-
- for (size_t i = 0; i < args.size(); ++i)
- s.Printf (", arg%zd = 0x%" PRIx64, i + 1, args[i]);
- s.PutCString (")");
- log->PutCString(s.GetString().c_str());
- }
+ RegisterContext *reg_ctx = thread.GetRegisterContext().get();
+ if (!reg_ctx)
+ return false;
- RegisterContext *reg_ctx = thread.GetRegisterContext().get();
- if (!reg_ctx)
- return false;
+ const RegisterInfo *reg_info = nullptr;
- const RegisterInfo *reg_info = nullptr;
+ RegisterValue reg_value;
- RegisterValue reg_value;
+ // Argument registers
+ const char *reg_names[] = {"r4", "r5", "r6", "r7"};
- // Argument registers
- const char *reg_names[] = { "r4", "r5", "r6", "r7" };
+ llvm::ArrayRef<addr_t>::iterator ai = args.begin(), ae = args.end();
- llvm::ArrayRef<addr_t>::iterator ai = args.begin(), ae = args.end();
+ // Write arguments to registers
+ for (size_t i = 0; i < llvm::array_lengthof(reg_names); ++i) {
+ if (ai == ae)
+ break;
- // Write arguments to registers
- for (size_t i = 0; i < llvm::array_lengthof(reg_names); ++i)
- {
- if (ai == ae)
- break;
+ reg_info = reg_ctx->GetRegisterInfo(eRegisterKindGeneric,
+ LLDB_REGNUM_GENERIC_ARG1 + i);
+ if (log)
+ log->Printf("About to write arg%zd (0x%" PRIx64 ") into %s", i + 1,
+ args[i], reg_info->name);
- reg_info = reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG1 + i);
- if (log)
- log->Printf("About to write arg%zd (0x%" PRIx64 ") into %s", i + 1, args[i], reg_info->name);
+ if (!reg_ctx->WriteRegisterFromUnsigned(reg_info, args[i]))
+ return false;
- if (!reg_ctx->WriteRegisterFromUnsigned(reg_info, args[i]))
- return false;
+ ++ai;
+ }
- ++ai;
+ // If we have more than 4 arguments --Spill onto the stack
+ if (ai != ae) {
+ // No of arguments to go on stack
+ size_t num_stack_regs = args.size();
+
+ // Allocate needed space for args on the stack
+ sp -= (num_stack_regs * 4);
+
+ // Keep the stack 8 byte aligned
+ sp &= ~(8ull - 1ull);
+
+ // just using arg1 to get the right size
+ const RegisterInfo *reg_info = reg_ctx->GetRegisterInfo(
+ eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG1);
+
+ addr_t arg_pos = sp + 16;
+
+ size_t i = 4;
+ for (; ai != ae; ++ai) {
+ reg_value.SetUInt32(*ai);
+ if (log)
+ log->Printf("About to write arg%zd (0x%" PRIx64 ") at 0x%" PRIx64 "",
+ i + 1, args[i], arg_pos);
+
+ if (reg_ctx
+ ->WriteRegisterValueToMemory(reg_info, arg_pos,
+ reg_info->byte_size, reg_value)
+ .Fail())
+ return false;
+ arg_pos += reg_info->byte_size;
+ i++;
}
+ }
- // If we have more than 4 arguments --Spill onto the stack
- if (ai != ae)
- {
- // No of arguments to go on stack
- size_t num_stack_regs = args.size();
-
- // Allocate needed space for args on the stack
- sp -= (num_stack_regs * 4);
-
- // Keep the stack 8 byte aligned
- sp &= ~(8ull-1ull);
-
- // just using arg1 to get the right size
- const RegisterInfo *reg_info = reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG1);
-
- addr_t arg_pos = sp+16;
-
- size_t i = 4;
- for (; ai != ae; ++ai)
- {
- reg_value.SetUInt32(*ai);
- if (log)
- log->Printf("About to write arg%zd (0x%" PRIx64 ") at 0x%" PRIx64 "", i+1, args[i], arg_pos);
-
- if (reg_ctx->WriteRegisterValueToMemory(reg_info, arg_pos, reg_info->byte_size, reg_value).Fail())
- return false;
- arg_pos += reg_info->byte_size;
- i++;
- }
- }
+ Error error;
+ const RegisterInfo *pc_reg_info =
+ reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_PC);
+ const RegisterInfo *sp_reg_info =
+ reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_SP);
+ const RegisterInfo *ra_reg_info =
+ reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_RA);
+ const RegisterInfo *r25_info = reg_ctx->GetRegisterInfoByName("r25", 0);
+ const RegisterInfo *r0_info = reg_ctx->GetRegisterInfoByName("zero", 0);
+
+ if (log)
+ log->Printf("Writing R0: 0x%" PRIx64, (uint64_t)0);
+
+ /* Write r0 with 0, in case we are stopped in syscall,
+ * such setting prevents automatic decrement of the PC.
+ * This clears the bug 23659 for MIPS.
+ */
+ if (!reg_ctx->WriteRegisterFromUnsigned(r0_info, (uint64_t)0))
+ return false;
- Error error;
- const RegisterInfo *pc_reg_info = reg_ctx->GetRegisterInfo (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_PC);
- const RegisterInfo *sp_reg_info = reg_ctx->GetRegisterInfo (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_SP);
- const RegisterInfo *ra_reg_info = reg_ctx->GetRegisterInfo (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_RA);
- const RegisterInfo *r25_info = reg_ctx->GetRegisterInfoByName("r25", 0);
- const RegisterInfo *r0_info = reg_ctx->GetRegisterInfoByName("zero", 0);
+ if (log)
+ log->Printf("Writing SP: 0x%" PRIx64, (uint64_t)sp);
- if (log)
- log->Printf("Writing R0: 0x%" PRIx64, (uint64_t)0);
+ // Set "sp" to the requested value
+ if (!reg_ctx->WriteRegisterFromUnsigned(sp_reg_info, sp))
+ return false;
- /* Write r0 with 0, in case we are stopped in syscall,
- * such setting prevents automatic decrement of the PC.
- * This clears the bug 23659 for MIPS.
- */
- if (!reg_ctx->WriteRegisterFromUnsigned (r0_info, (uint64_t)0))
- return false;
+ if (log)
+ log->Printf("Writing RA: 0x%" PRIx64, (uint64_t)return_addr);
- if (log)
- log->Printf("Writing SP: 0x%" PRIx64, (uint64_t)sp);
+ // Set "ra" to the return address
+ if (!reg_ctx->WriteRegisterFromUnsigned(ra_reg_info, return_addr))
+ return false;
- // Set "sp" to the requested value
- if (!reg_ctx->WriteRegisterFromUnsigned (sp_reg_info, sp))
- return false;
+ if (log)
+ log->Printf("Writing PC: 0x%" PRIx64, (uint64_t)func_addr);
- if (log)
- log->Printf("Writing RA: 0x%" PRIx64, (uint64_t)return_addr);
+ // Set pc to the address of the called function.
+ if (!reg_ctx->WriteRegisterFromUnsigned(pc_reg_info, func_addr))
+ return false;
- // Set "ra" to the return address
- if (!reg_ctx->WriteRegisterFromUnsigned (ra_reg_info, return_addr))
- return false;
+ if (log)
+ log->Printf("Writing r25: 0x%" PRIx64, (uint64_t)func_addr);
- if (log)
- log->Printf("Writing PC: 0x%" PRIx64, (uint64_t)func_addr);
+ // All callers of position independent functions must place the address of the
+ // called function in t9 (r25)
+ if (!reg_ctx->WriteRegisterFromUnsigned(r25_info, func_addr))
+ return false;
- // Set pc to the address of the called function.
- if (!reg_ctx->WriteRegisterFromUnsigned (pc_reg_info, func_addr))
- return false;
-
- if (log)
- log->Printf("Writing r25: 0x%" PRIx64, (uint64_t)func_addr);
-
- // All callers of position independent functions must place the address of the called function in t9 (r25)
- if (!reg_ctx->WriteRegisterFromUnsigned (r25_info, func_addr))
- return false;
-
- return true;
+ return true;
}
-bool
-ABISysV_mips::GetArgumentValues (Thread &thread, ValueList &values) const
-{
- return false;
+bool ABISysV_mips::GetArgumentValues(Thread &thread, ValueList &values) const {
+ return false;
}
-Error
-ABISysV_mips::SetReturnValueObject(lldb::StackFrameSP &frame_sp, lldb::ValueObjectSP &new_value_sp)
-{
- Error error;
- if (!new_value_sp)
- {
- error.SetErrorString("Empty value object for return value.");
- return error;
- }
+Error ABISysV_mips::SetReturnValueObject(lldb::StackFrameSP &frame_sp,
+ lldb::ValueObjectSP &new_value_sp) {
+ Error error;
+ if (!new_value_sp) {
+ error.SetErrorString("Empty value object for return value.");
+ return error;
+ }
- CompilerType compiler_type = new_value_sp->GetCompilerType();
- if (!compiler_type)
- {
- error.SetErrorString ("Null clang type for return value.");
- return error;
- }
+ CompilerType compiler_type = new_value_sp->GetCompilerType();
+ if (!compiler_type) {
+ error.SetErrorString("Null clang type for return value.");
+ return error;
+ }
- Thread *thread = frame_sp->GetThread().get();
+ Thread *thread = frame_sp->GetThread().get();
- bool is_signed;
- uint32_t count;
- bool is_complex;
-
- RegisterContext *reg_ctx = thread->GetRegisterContext().get();
-
- bool set_it_simple = false;
- if (compiler_type.IsIntegerOrEnumerationType (is_signed) || compiler_type.IsPointerType())
- {
- DataExtractor data;
- Error data_error;
- size_t num_bytes = new_value_sp->GetData(data, data_error);
- if (data_error.Fail())
- {
- error.SetErrorStringWithFormat("Couldn't convert return value to raw data: %s", data_error.AsCString());
- return error;
- }
+ bool is_signed;
+ uint32_t count;
+ bool is_complex;
+
+ RegisterContext *reg_ctx = thread->GetRegisterContext().get();
+
+ bool set_it_simple = false;
+ if (compiler_type.IsIntegerOrEnumerationType(is_signed) ||
+ compiler_type.IsPointerType()) {
+ DataExtractor data;
+ Error data_error;
+ size_t num_bytes = new_value_sp->GetData(data, data_error);
+ if (data_error.Fail()) {
+ error.SetErrorStringWithFormat(
+ "Couldn't convert return value to raw data: %s",
+ data_error.AsCString());
+ return error;
+ }
- lldb::offset_t offset = 0;
- if (num_bytes <= 8)
- {
- const RegisterInfo *r2_info = reg_ctx->GetRegisterInfoByName("r2", 0);
- if (num_bytes <= 4)
- {
- uint32_t raw_value = data.GetMaxU32(&offset, num_bytes);
-
- if (reg_ctx->WriteRegisterFromUnsigned (r2_info, raw_value))
- set_it_simple = true;
- }
- else
- {
- uint32_t raw_value = data.GetMaxU32(&offset, 4);
-
- if (reg_ctx->WriteRegisterFromUnsigned (r2_info, raw_value))
- {
- const RegisterInfo *r3_info = reg_ctx->GetRegisterInfoByName("r3", 0);
- uint32_t raw_value = data.GetMaxU32(&offset, num_bytes - offset);
-
- if (reg_ctx->WriteRegisterFromUnsigned (r3_info, raw_value))
- set_it_simple = true;
- }
- }
- }
- else
- {
- error.SetErrorString("We don't support returning longer than 64 bit integer values at present.");
+ lldb::offset_t offset = 0;
+ if (num_bytes <= 8) {
+ const RegisterInfo *r2_info = reg_ctx->GetRegisterInfoByName("r2", 0);
+ if (num_bytes <= 4) {
+ uint32_t raw_value = data.GetMaxU32(&offset, num_bytes);
+
+ if (reg_ctx->WriteRegisterFromUnsigned(r2_info, raw_value))
+ set_it_simple = true;
+ } else {
+ uint32_t raw_value = data.GetMaxU32(&offset, 4);
+
+ if (reg_ctx->WriteRegisterFromUnsigned(r2_info, raw_value)) {
+ const RegisterInfo *r3_info = reg_ctx->GetRegisterInfoByName("r3", 0);
+ uint32_t raw_value = data.GetMaxU32(&offset, num_bytes - offset);
+
+ if (reg_ctx->WriteRegisterFromUnsigned(r3_info, raw_value))
+ set_it_simple = true;
}
+ }
+ } else {
+ error.SetErrorString("We don't support returning longer than 64 bit "
+ "integer values at present.");
}
- else if (compiler_type.IsFloatingPointType (count, is_complex))
- {
- if (is_complex)
- error.SetErrorString ("We don't support returning complex values at present");
- else
- error.SetErrorString ("We don't support returning float values at present");
- }
-
- if (!set_it_simple)
- error.SetErrorString ("We only support setting simple integer return types at present.");
+ } else if (compiler_type.IsFloatingPointType(count, is_complex)) {
+ if (is_complex)
+ error.SetErrorString(
+ "We don't support returning complex values at present");
+ else
+ error.SetErrorString(
+ "We don't support returning float values at present");
+ }
+
+ if (!set_it_simple)
+ error.SetErrorString(
+ "We only support setting simple integer return types at present.");
- return error;
+ return error;
}
-ValueObjectSP
-ABISysV_mips::GetReturnValueObjectSimple (Thread &thread, CompilerType &return_compiler_type) const
-{
- ValueObjectSP return_valobj_sp;
- return return_valobj_sp;
+ValueObjectSP ABISysV_mips::GetReturnValueObjectSimple(
+ Thread &thread, CompilerType &return_compiler_type) const {
+ ValueObjectSP return_valobj_sp;
+ return return_valobj_sp;
}
-ValueObjectSP
-ABISysV_mips::GetReturnValueObjectImpl (Thread &thread, CompilerType &return_compiler_type) const
-{
- ValueObjectSP return_valobj_sp;
- Value value;
+ValueObjectSP ABISysV_mips::GetReturnValueObjectImpl(
+ Thread &thread, CompilerType &return_compiler_type) const {
+ ValueObjectSP return_valobj_sp;
+ Value value;
- if (!return_compiler_type)
- return return_valobj_sp;
+ if (!return_compiler_type)
+ return return_valobj_sp;
- ExecutionContext exe_ctx (thread.shared_from_this());
- if (exe_ctx.GetTargetPtr() == nullptr || exe_ctx.GetProcessPtr() == nullptr)
- return return_valobj_sp;
+ ExecutionContext exe_ctx(thread.shared_from_this());
+ if (exe_ctx.GetTargetPtr() == nullptr || exe_ctx.GetProcessPtr() == nullptr)
+ return return_valobj_sp;
- Target *target = exe_ctx.GetTargetPtr();
- const ArchSpec target_arch = target->GetArchitecture();
- ByteOrder target_byte_order = target_arch.GetByteOrder();
- value.SetCompilerType(return_compiler_type);
- uint32_t fp_flag = target_arch.GetFlags() & lldb_private::ArchSpec::eMIPS_ABI_FP_mask;
+ Target *target = exe_ctx.GetTargetPtr();
+ const ArchSpec target_arch = target->GetArchitecture();
+ ByteOrder target_byte_order = target_arch.GetByteOrder();
+ value.SetCompilerType(return_compiler_type);
+ uint32_t fp_flag =
+ target_arch.GetFlags() & lldb_private::ArchSpec::eMIPS_ABI_FP_mask;
- RegisterContext *reg_ctx = thread.GetRegisterContext().get();
- if (!reg_ctx)
- return return_valobj_sp;
-
- bool is_signed = false;
- bool is_complex = false;
- uint32_t count = 0;
-
- // In MIPS register "r2" (v0) holds the integer function return values
- const RegisterInfo *r2_reg_info = reg_ctx->GetRegisterInfoByName("r2", 0);
- size_t bit_width = return_compiler_type.GetBitSize(&thread);
- if (return_compiler_type.IsIntegerOrEnumerationType (is_signed))
- {
- switch (bit_width)
- {
- default:
- return return_valobj_sp;
- case 64:
- {
- const RegisterInfo *r3_reg_info = reg_ctx->GetRegisterInfoByName("r3", 0);
- uint64_t raw_value;
- raw_value = reg_ctx->ReadRegisterAsUnsigned(r2_reg_info, 0) & UINT32_MAX;
- raw_value |= ((uint64_t)(reg_ctx->ReadRegisterAsUnsigned(r3_reg_info, 0) & UINT32_MAX)) << 32;
- if (is_signed)
- value.GetScalar() = (int64_t)raw_value;
- else
- value.GetScalar() = (uint64_t)raw_value;
- }
- break;
- case 32:
- if (is_signed)
- value.GetScalar() = (int32_t)(reg_ctx->ReadRegisterAsUnsigned(r2_reg_info, 0) & UINT32_MAX);
- else
- value.GetScalar() = (uint32_t)(reg_ctx->ReadRegisterAsUnsigned(r2_reg_info, 0) & UINT32_MAX);
- break;
- case 16:
- if (is_signed)
- value.GetScalar() = (int16_t)(reg_ctx->ReadRegisterAsUnsigned(r2_reg_info, 0) & UINT16_MAX);
- else
- value.GetScalar() = (uint16_t)(reg_ctx->ReadRegisterAsUnsigned(r2_reg_info, 0) & UINT16_MAX);
- break;
- case 8:
- if (is_signed)
- value.GetScalar() = (int8_t)(reg_ctx->ReadRegisterAsUnsigned(r2_reg_info, 0) & UINT8_MAX);
- else
- value.GetScalar() = (uint8_t)(reg_ctx->ReadRegisterAsUnsigned(r2_reg_info, 0) & UINT8_MAX);
- break;
- }
- }
- else if (return_compiler_type.IsPointerType ())
- {
- uint32_t ptr = thread.GetRegisterContext()->ReadRegisterAsUnsigned(r2_reg_info, 0) & UINT32_MAX;
- value.GetScalar() = ptr;
+ RegisterContext *reg_ctx = thread.GetRegisterContext().get();
+ if (!reg_ctx)
+ return return_valobj_sp;
+
+ bool is_signed = false;
+ bool is_complex = false;
+ uint32_t count = 0;
+
+ // In MIPS register "r2" (v0) holds the integer function return values
+ const RegisterInfo *r2_reg_info = reg_ctx->GetRegisterInfoByName("r2", 0);
+ size_t bit_width = return_compiler_type.GetBitSize(&thread);
+ if (return_compiler_type.IsIntegerOrEnumerationType(is_signed)) {
+ switch (bit_width) {
+ default:
+ return return_valobj_sp;
+ case 64: {
+ const RegisterInfo *r3_reg_info = reg_ctx->GetRegisterInfoByName("r3", 0);
+ uint64_t raw_value;
+ raw_value = reg_ctx->ReadRegisterAsUnsigned(r2_reg_info, 0) & UINT32_MAX;
+ raw_value |= ((uint64_t)(reg_ctx->ReadRegisterAsUnsigned(r3_reg_info, 0) &
+ UINT32_MAX))
+ << 32;
+ if (is_signed)
+ value.GetScalar() = (int64_t)raw_value;
+ else
+ value.GetScalar() = (uint64_t)raw_value;
+ } break;
+ case 32:
+ if (is_signed)
+ value.GetScalar() = (int32_t)(
+ reg_ctx->ReadRegisterAsUnsigned(r2_reg_info, 0) & UINT32_MAX);
+ else
+ value.GetScalar() = (uint32_t)(
+ reg_ctx->ReadRegisterAsUnsigned(r2_reg_info, 0) & UINT32_MAX);
+ break;
+ case 16:
+ if (is_signed)
+ value.GetScalar() = (int16_t)(
+ reg_ctx->ReadRegisterAsUnsigned(r2_reg_info, 0) & UINT16_MAX);
+ else
+ value.GetScalar() = (uint16_t)(
+ reg_ctx->ReadRegisterAsUnsigned(r2_reg_info, 0) & UINT16_MAX);
+ break;
+ case 8:
+ if (is_signed)
+ value.GetScalar() = (int8_t)(
+ reg_ctx->ReadRegisterAsUnsigned(r2_reg_info, 0) & UINT8_MAX);
+ else
+ value.GetScalar() = (uint8_t)(
+ reg_ctx->ReadRegisterAsUnsigned(r2_reg_info, 0) & UINT8_MAX);
+ break;
}
- else if (return_compiler_type.IsAggregateType ())
- {
- // Structure/Vector is always passed in memory and pointer to that memory is passed in r2.
- uint64_t mem_address = reg_ctx->ReadRegisterAsUnsigned(reg_ctx->GetRegisterInfoByName("r2", 0), 0);
- // We have got the address. Create a memory object out of it
- return_valobj_sp = ValueObjectMemory::Create(&thread,
- "",
- Address(mem_address, nullptr),
- return_compiler_type);
+ } else if (return_compiler_type.IsPointerType()) {
+ uint32_t ptr =
+ thread.GetRegisterContext()->ReadRegisterAsUnsigned(r2_reg_info, 0) &
+ UINT32_MAX;
+ value.GetScalar() = ptr;
+ } else if (return_compiler_type.IsAggregateType()) {
+ // Structure/Vector is always passed in memory and pointer to that memory is
+ // passed in r2.
+ uint64_t mem_address = reg_ctx->ReadRegisterAsUnsigned(
+ reg_ctx->GetRegisterInfoByName("r2", 0), 0);
+ // We have got the address. Create a memory object out of it
+ return_valobj_sp = ValueObjectMemory::Create(
+ &thread, "", Address(mem_address, nullptr), return_compiler_type);
+ return return_valobj_sp;
+ } else if (return_compiler_type.IsFloatingPointType(count, is_complex)) {
+ if (IsSoftFloat(fp_flag)) {
+ uint64_t raw_value = reg_ctx->ReadRegisterAsUnsigned(r2_reg_info, 0);
+ if (count != 1 && is_complex)
+ return return_valobj_sp;
+ switch (bit_width) {
+ default:
return return_valobj_sp;
+ case 32:
+ static_assert(sizeof(float) == sizeof(uint32_t), "");
+ value.GetScalar() = *((float *)(&raw_value));
+ break;
+ case 64:
+ static_assert(sizeof(double) == sizeof(uint64_t), "");
+ const RegisterInfo *r3_reg_info =
+ reg_ctx->GetRegisterInfoByName("r3", 0);
+ if (target_byte_order == eByteOrderLittle)
+ raw_value =
+ ((reg_ctx->ReadRegisterAsUnsigned(r3_reg_info, 0)) << 32) |
+ raw_value;
+ else
+ raw_value = (raw_value << 32) |
+ reg_ctx->ReadRegisterAsUnsigned(r3_reg_info, 0);
+ value.GetScalar() = *((double *)(&raw_value));
+ break;
+ }
}
- else if (return_compiler_type.IsFloatingPointType (count, is_complex))
- {
- if (IsSoftFloat (fp_flag))
- {
- uint64_t raw_value = reg_ctx->ReadRegisterAsUnsigned(r2_reg_info, 0);
- if (count != 1 && is_complex)
- return return_valobj_sp;
- switch (bit_width)
- {
- default:
- return return_valobj_sp;
- case 32:
- static_assert(sizeof(float) == sizeof(uint32_t), "");
- value.GetScalar() = *((float *)(&raw_value));
- break;
- case 64:
- static_assert(sizeof(double) == sizeof(uint64_t), "");
- const RegisterInfo *r3_reg_info = reg_ctx->GetRegisterInfoByName("r3", 0);
- if (target_byte_order == eByteOrderLittle)
- raw_value = ((reg_ctx->ReadRegisterAsUnsigned(r3_reg_info, 0)) << 32) | raw_value;
- else
- raw_value = (raw_value << 32) | reg_ctx->ReadRegisterAsUnsigned(r3_reg_info, 0);
- value.GetScalar() = *((double *)(&raw_value));
- break;
- }
+
+ else {
+ const RegisterInfo *f0_info = reg_ctx->GetRegisterInfoByName("f0", 0);
+ RegisterValue f0_value;
+ DataExtractor f0_data;
+ reg_ctx->ReadRegister(f0_info, f0_value);
+ f0_value.GetData(f0_data);
+ lldb::offset_t offset = 0;
+
+ if (count == 1 && !is_complex) {
+ switch (bit_width) {
+ default:
+ return return_valobj_sp;
+ case 64: {
+ static_assert(sizeof(double) == sizeof(uint64_t), "");
+ const RegisterInfo *f1_info = reg_ctx->GetRegisterInfoByName("f1", 0);
+ RegisterValue f1_value;
+ DataExtractor f1_data;
+ reg_ctx->ReadRegister(f1_info, f1_value);
+ DataExtractor *copy_from_extractor = nullptr;
+ DataBufferSP data_sp(new DataBufferHeap(8, 0));
+ DataExtractor return_ext(
+ data_sp, target_byte_order,
+ target->GetArchitecture().GetAddressByteSize());
+
+ if (target_byte_order == eByteOrderLittle) {
+ copy_from_extractor = &f0_data;
+ copy_from_extractor->CopyByteOrderedData(
+ offset, 4, data_sp->GetBytes(), 4, target_byte_order);
+ f1_value.GetData(f1_data);
+ copy_from_extractor = &f1_data;
+ copy_from_extractor->CopyByteOrderedData(
+ offset, 4, data_sp->GetBytes() + 4, 4, target_byte_order);
+ } else {
+ copy_from_extractor = &f0_data;
+ copy_from_extractor->CopyByteOrderedData(
+ offset, 4, data_sp->GetBytes() + 4, 4, target_byte_order);
+ f1_value.GetData(f1_data);
+ copy_from_extractor = &f1_data;
+ copy_from_extractor->CopyByteOrderedData(
+ offset, 4, data_sp->GetBytes(), 4, target_byte_order);
+ }
+ value.GetScalar() = (double)return_ext.GetDouble(&offset);
+ break;
}
-
- else
- {
- const RegisterInfo *f0_info = reg_ctx->GetRegisterInfoByName("f0", 0);
- RegisterValue f0_value;
- DataExtractor f0_data;
- reg_ctx->ReadRegister (f0_info, f0_value);
- f0_value.GetData(f0_data);
- lldb::offset_t offset = 0;
-
- if (count == 1 && !is_complex)
- {
- switch (bit_width)
- {
- default:
- return return_valobj_sp;
- case 64:
- {
- static_assert(sizeof(double) == sizeof(uint64_t), "");
- const RegisterInfo *f1_info = reg_ctx->GetRegisterInfoByName("f1", 0);
- RegisterValue f1_value;
- DataExtractor f1_data;
- reg_ctx->ReadRegister (f1_info, f1_value);
- DataExtractor *copy_from_extractor = nullptr;
- DataBufferSP data_sp (new DataBufferHeap(8, 0));
- DataExtractor return_ext (data_sp,
- target_byte_order,
- target->GetArchitecture().GetAddressByteSize());
-
- if (target_byte_order == eByteOrderLittle)
- {
- copy_from_extractor = &f0_data;
- copy_from_extractor->CopyByteOrderedData (offset,
- 4,
- data_sp->GetBytes(),
- 4,
- target_byte_order);
- f1_value.GetData(f1_data);
- copy_from_extractor = &f1_data;
- copy_from_extractor->CopyByteOrderedData (offset,
- 4,
- data_sp->GetBytes() + 4,
- 4,
- target_byte_order);
- }
- else
- {
- copy_from_extractor = &f0_data;
- copy_from_extractor->CopyByteOrderedData (offset,
- 4,
- data_sp->GetBytes() + 4,
- 4,
- target_byte_order);
- f1_value.GetData(f1_data);
- copy_from_extractor = &f1_data;
- copy_from_extractor->CopyByteOrderedData (offset,
- 4,
- data_sp->GetBytes(),
- 4,
- target_byte_order);
- }
- value.GetScalar() = (double) return_ext.GetDouble(&offset);
- break;
- }
- case 32:
- {
- static_assert(sizeof(float) == sizeof(uint32_t), "");
- value.GetScalar() = (float) f0_data.GetFloat(&offset);
- break;
- }
- }
- }
- else
- {
- // not handled yet
- return return_valobj_sp;
- }
+ case 32: {
+ static_assert(sizeof(float) == sizeof(uint32_t), "");
+ value.GetScalar() = (float)f0_data.GetFloat(&offset);
+ break;
}
- }
- else
- {
+ }
+ } else {
// not handled yet
return return_valobj_sp;
+ }
}
-
- // If we get here, we have a valid Value, so make our ValueObject out of it:
-
- return_valobj_sp = ValueObjectConstResult::Create(thread.GetStackFrameAtIndex(0).get(),
- value,
- ConstString(""));
+ } else {
+ // not handled yet
return return_valobj_sp;
+ }
+
+ // If we get here, we have a valid Value, so make our ValueObject out of it:
+
+ return_valobj_sp = ValueObjectConstResult::Create(
+ thread.GetStackFrameAtIndex(0).get(), value, ConstString(""));
+ return return_valobj_sp;
}
-bool
-ABISysV_mips::CreateFunctionEntryUnwindPlan (UnwindPlan &unwind_plan)
-{
- unwind_plan.Clear();
- unwind_plan.SetRegisterKind (eRegisterKindDWARF);
-
- UnwindPlan::RowSP row(new UnwindPlan::Row);
-
- // Our Call Frame Address is the stack pointer value
- row->GetCFAValue().SetIsRegisterPlusOffset(dwarf_r29, 0);
-
- // The previous PC is in the RA
- row->SetRegisterLocationToRegister(dwarf_pc, dwarf_r31, true);
- unwind_plan.AppendRow (row);
-
- // All other registers are the same.
-
- unwind_plan.SetSourceName ("mips at-func-entry default");
- unwind_plan.SetSourcedFromCompiler (eLazyBoolNo);
- unwind_plan.SetReturnAddressRegister(dwarf_r31);
- return true;
-}
-
-bool
-ABISysV_mips::CreateDefaultUnwindPlan (UnwindPlan &unwind_plan)
-{
- unwind_plan.Clear();
- unwind_plan.SetRegisterKind (eRegisterKindDWARF);
-
- UnwindPlan::RowSP row(new UnwindPlan::Row);
-
- row->GetCFAValue().SetIsRegisterPlusOffset(dwarf_r29, 0);
-
- row->SetRegisterLocationToRegister(dwarf_pc, dwarf_r31, true);
-
- unwind_plan.AppendRow (row);
- unwind_plan.SetSourceName ("mips default unwind plan");
- unwind_plan.SetSourcedFromCompiler (eLazyBoolNo);
- unwind_plan.SetUnwindPlanValidAtAllInstructions (eLazyBoolNo);
- return true;
-}
-
-bool
-ABISysV_mips::RegisterIsVolatile (const RegisterInfo *reg_info)
-{
- return !RegisterIsCalleeSaved (reg_info);
-}
-
-bool
-ABISysV_mips::IsSoftFloat(uint32_t fp_flags) const
-{
- return (fp_flags == lldb_private::ArchSpec::eMIPS_ABI_FP_SOFT);
-}
-
-bool
-ABISysV_mips::RegisterIsCalleeSaved (const RegisterInfo *reg_info)
-{
- if (reg_info)
- {
- // Preserved registers are :
- // r16-r23, r28, r29, r30, r31
- const char *name = reg_info->name;
-
- if (name[0] == 'r')
- {
- switch (name[1])
- {
- case '1':
- if (name[2] == '6' || name[2] == '7' || name[2] == '8' || name[2] == '9') // r16-r19
- return name[3] == '\0';
- break;
- case '2':
- if (name[2] == '0' || name[2] == '1' || name[2] == '2' || name[2] == '3' // r20-r23
- || name[2] == '8' || name[2] == '9') // r28 and r29
- return name[3] == '\0';
- break;
- case '3':
- if (name[2] == '0' || name[2] == '1') // r30 and r31
- return name[3] == '\0';
- break;
- }
-
- if (name[0] == 'g' && name[1] == 'p' && name[2] == '\0') // gp (r28)
- return true;
- if (name[0] == 's' && name[1] == 'p' && name[2] == '\0') // sp (r29)
- return true;
- if (name[0] == 'f' && name[1] == 'p' && name[2] == '\0') // fp (r30)
- return true;
- if (name[0] == 'r' && name[1] == 'a' && name[2] == '\0') // ra (r31)
- return true;
- }
+bool ABISysV_mips::CreateFunctionEntryUnwindPlan(UnwindPlan &unwind_plan) {
+ unwind_plan.Clear();
+ unwind_plan.SetRegisterKind(eRegisterKindDWARF);
+
+ UnwindPlan::RowSP row(new UnwindPlan::Row);
+
+ // Our Call Frame Address is the stack pointer value
+ row->GetCFAValue().SetIsRegisterPlusOffset(dwarf_r29, 0);
+
+ // The previous PC is in the RA
+ row->SetRegisterLocationToRegister(dwarf_pc, dwarf_r31, true);
+ unwind_plan.AppendRow(row);
+
+ // All other registers are the same.
+
+ unwind_plan.SetSourceName("mips at-func-entry default");
+ unwind_plan.SetSourcedFromCompiler(eLazyBoolNo);
+ unwind_plan.SetReturnAddressRegister(dwarf_r31);
+ return true;
+}
+
+bool ABISysV_mips::CreateDefaultUnwindPlan(UnwindPlan &unwind_plan) {
+ unwind_plan.Clear();
+ unwind_plan.SetRegisterKind(eRegisterKindDWARF);
+
+ UnwindPlan::RowSP row(new UnwindPlan::Row);
+
+ row->GetCFAValue().SetIsRegisterPlusOffset(dwarf_r29, 0);
+
+ row->SetRegisterLocationToRegister(dwarf_pc, dwarf_r31, true);
+
+ unwind_plan.AppendRow(row);
+ unwind_plan.SetSourceName("mips default unwind plan");
+ unwind_plan.SetSourcedFromCompiler(eLazyBoolNo);
+ unwind_plan.SetUnwindPlanValidAtAllInstructions(eLazyBoolNo);
+ return true;
+}
+
+bool ABISysV_mips::RegisterIsVolatile(const RegisterInfo *reg_info) {
+ return !RegisterIsCalleeSaved(reg_info);
+}
+
+bool ABISysV_mips::IsSoftFloat(uint32_t fp_flags) const {
+ return (fp_flags == lldb_private::ArchSpec::eMIPS_ABI_FP_SOFT);
+}
+
+bool ABISysV_mips::RegisterIsCalleeSaved(const RegisterInfo *reg_info) {
+ if (reg_info) {
+ // Preserved registers are :
+ // r16-r23, r28, r29, r30, r31
+ const char *name = reg_info->name;
+
+ if (name[0] == 'r') {
+ switch (name[1]) {
+ case '1':
+ if (name[2] == '6' || name[2] == '7' || name[2] == '8' ||
+ name[2] == '9') // r16-r19
+ return name[3] == '\0';
+ break;
+ case '2':
+ if (name[2] == '0' || name[2] == '1' || name[2] == '2' ||
+ name[2] == '3' // r20-r23
+ || name[2] == '8' || name[2] == '9') // r28 and r29
+ return name[3] == '\0';
+ break;
+ case '3':
+ if (name[2] == '0' || name[2] == '1') // r30 and r31
+ return name[3] == '\0';
+ break;
+ }
+
+ if (name[0] == 'g' && name[1] == 'p' && name[2] == '\0') // gp (r28)
+ return true;
+ if (name[0] == 's' && name[1] == 'p' && name[2] == '\0') // sp (r29)
+ return true;
+ if (name[0] == 'f' && name[1] == 'p' && name[2] == '\0') // fp (r30)
+ return true;
+ if (name[0] == 'r' && name[1] == 'a' && name[2] == '\0') // ra (r31)
+ return true;
}
- return false;
+ }
+ return false;
}
-void
-ABISysV_mips::Initialize()
-{
- PluginManager::RegisterPlugin (GetPluginNameStatic(),
- "System V ABI for mips targets",
- CreateInstance);
-}
-
-void
-ABISysV_mips::Terminate()
-{
- PluginManager::UnregisterPlugin (CreateInstance);
-}
-
-lldb_private::ConstString
-ABISysV_mips::GetPluginNameStatic()
-{
- static ConstString g_name("sysv-mips");
- return g_name;
+void ABISysV_mips::Initialize() {
+ PluginManager::RegisterPlugin(
+ GetPluginNameStatic(), "System V ABI for mips targets", CreateInstance);
+}
+
+void ABISysV_mips::Terminate() {
+ PluginManager::UnregisterPlugin(CreateInstance);
+}
+
+lldb_private::ConstString ABISysV_mips::GetPluginNameStatic() {
+ static ConstString g_name("sysv-mips");
+ return g_name;
}
//------------------------------------------------------------------
// PluginInterface protocol
//------------------------------------------------------------------
-lldb_private::ConstString
-ABISysV_mips::GetPluginName()
-{
- return GetPluginNameStatic();
+lldb_private::ConstString ABISysV_mips::GetPluginName() {
+ return GetPluginNameStatic();
}
-uint32_t
-ABISysV_mips::GetPluginVersion()
-{
- return 1;
-}
+uint32_t ABISysV_mips::GetPluginVersion() { return 1; }
Modified: lldb/trunk/source/Plugins/ABI/SysV-mips/ABISysV_mips.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ABI/SysV-mips/ABISysV_mips.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ABI/SysV-mips/ABISysV_mips.h (original)
+++ lldb/trunk/source/Plugins/ABI/SysV-mips/ABISysV_mips.h Tue Sep 6 15:57:50 2016
@@ -14,113 +14,91 @@
// C++ Includes
// Other libraries and framework includes
// Project includes
-#include "lldb/lldb-private.h"
#include "lldb/Target/ABI.h"
+#include "lldb/lldb-private.h"
-class ABISysV_mips :
- public lldb_private::ABI
-{
+class ABISysV_mips : public lldb_private::ABI {
public:
- ~ABISysV_mips() override = default;
+ ~ABISysV_mips() override = default;
+
+ size_t GetRedZoneSize() const override;
+
+ bool PrepareTrivialCall(lldb_private::Thread &thread, lldb::addr_t sp,
+ lldb::addr_t functionAddress,
+ lldb::addr_t returnAddress,
+ llvm::ArrayRef<lldb::addr_t> args) const override;
+
+ bool GetArgumentValues(lldb_private::Thread &thread,
+ lldb_private::ValueList &values) const override;
+
+ lldb_private::Error
+ SetReturnValueObject(lldb::StackFrameSP &frame_sp,
+ lldb::ValueObjectSP &new_value) override;
+
+ lldb::ValueObjectSP
+ GetReturnValueObjectImpl(lldb_private::Thread &thread,
+ lldb_private::CompilerType &type) const override;
+
+ bool
+ CreateFunctionEntryUnwindPlan(lldb_private::UnwindPlan &unwind_plan) override;
+
+ bool CreateDefaultUnwindPlan(lldb_private::UnwindPlan &unwind_plan) override;
+
+ bool RegisterIsVolatile(const lldb_private::RegisterInfo *reg_info) override;
+
+ bool IsSoftFloat(uint32_t fp_flag) const;
+
+ bool CallFrameAddressIsValid(lldb::addr_t cfa) override {
+ // Make sure the stack call frame addresses are 8 byte aligned
+ if (cfa & (8ull - 1ull))
+ return false; // Not 8 byte aligned
+ if (cfa == 0)
+ return false; // Zero is not a valid stack address
+ return true;
+ }
+
+ bool CodeAddressIsValid(lldb::addr_t pc) override {
+ // Just make sure the address is a valid 32 bit address. Bit zero
+ // might be set due to MicroMIPS function calls, so don't enforce alignment.
+ return (pc <= UINT32_MAX);
+ }
+
+ const lldb_private::RegisterInfo *
+ GetRegisterInfoArray(uint32_t &count) override;
+
+ //------------------------------------------------------------------
+ // Static Functions
+ //------------------------------------------------------------------
+
+ static void Initialize();
+
+ static void Terminate();
+
+ static lldb::ABISP CreateInstance(const lldb_private::ArchSpec &arch);
- size_t
- GetRedZoneSize() const override;
+ static lldb_private::ConstString GetPluginNameStatic();
- bool
- PrepareTrivialCall(lldb_private::Thread &thread,
- lldb::addr_t sp,
- lldb::addr_t functionAddress,
- lldb::addr_t returnAddress,
- llvm::ArrayRef<lldb::addr_t> args) const override;
-
- bool
- GetArgumentValues(lldb_private::Thread &thread,
- lldb_private::ValueList &values) const override;
-
- lldb_private::Error
- SetReturnValueObject(lldb::StackFrameSP &frame_sp, lldb::ValueObjectSP &new_value) override;
-
- lldb::ValueObjectSP
- GetReturnValueObjectImpl(lldb_private::Thread &thread,
- lldb_private::CompilerType &type) const override;
-
- bool
- CreateFunctionEntryUnwindPlan(lldb_private::UnwindPlan &unwind_plan) override;
-
- bool
- CreateDefaultUnwindPlan(lldb_private::UnwindPlan &unwind_plan) override;
-
- bool
- RegisterIsVolatile(const lldb_private::RegisterInfo *reg_info) override;
-
- bool
- IsSoftFloat(uint32_t fp_flag) const;
-
- bool
- CallFrameAddressIsValid(lldb::addr_t cfa) override
- {
- // Make sure the stack call frame addresses are 8 byte aligned
- if (cfa & (8ull - 1ull))
- return false; // Not 8 byte aligned
- if (cfa == 0)
- return false; // Zero is not a valid stack address
- return true;
- }
-
- bool
- CodeAddressIsValid(lldb::addr_t pc) override
- {
- // Just make sure the address is a valid 32 bit address. Bit zero
- // might be set due to MicroMIPS function calls, so don't enforce alignment.
- return (pc <= UINT32_MAX);
- }
-
- const lldb_private::RegisterInfo *
- GetRegisterInfoArray(uint32_t &count) override;
-
- //------------------------------------------------------------------
- // Static Functions
- //------------------------------------------------------------------
-
- static void
- Initialize();
-
- static void
- Terminate();
-
- static lldb::ABISP
- CreateInstance (const lldb_private::ArchSpec &arch);
-
- static lldb_private::ConstString
- GetPluginNameStatic();
-
- //------------------------------------------------------------------
- // PluginInterface protocol
- //------------------------------------------------------------------
+ //------------------------------------------------------------------
+ // PluginInterface protocol
+ //------------------------------------------------------------------
- lldb_private::ConstString
- GetPluginName() override;
+ lldb_private::ConstString GetPluginName() override;
- uint32_t
- GetPluginVersion() override;
+ uint32_t GetPluginVersion() override;
protected:
- void
- CreateRegisterMapIfNeeded ();
+ void CreateRegisterMapIfNeeded();
- lldb::ValueObjectSP
- GetReturnValueObjectSimple(lldb_private::Thread &thread,
- lldb_private::CompilerType &ast_type) const;
+ lldb::ValueObjectSP
+ GetReturnValueObjectSimple(lldb_private::Thread &thread,
+ lldb_private::CompilerType &ast_type) const;
- bool
- RegisterIsCalleeSaved (const lldb_private::RegisterInfo *reg_info);
+ bool RegisterIsCalleeSaved(const lldb_private::RegisterInfo *reg_info);
private:
- ABISysV_mips() :
- lldb_private::ABI()
- {
- // Call CreateInstance instead.
- }
+ ABISysV_mips() : lldb_private::ABI() {
+ // Call CreateInstance instead.
+ }
};
#endif // liblldb_ABISysV_mips_h_
Modified: lldb/trunk/source/Plugins/ABI/SysV-mips64/ABISysV_mips64.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ABI/SysV-mips64/ABISysV_mips64.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ABI/SysV-mips64/ABISysV_mips64.cpp (original)
+++ lldb/trunk/source/Plugins/ABI/SysV-mips64/ABISysV_mips64.cpp Tue Sep 6 15:57:50 2016
@@ -25,871 +25,1192 @@
#include "lldb/Core/RegisterValue.h"
#include "lldb/Core/Value.h"
#include "lldb/Core/ValueObjectConstResult.h"
-#include "lldb/Core/ValueObjectRegister.h"
#include "lldb/Core/ValueObjectMemory.h"
+#include "lldb/Core/ValueObjectRegister.h"
#include "lldb/Symbol/UnwindPlan.h"
-#include "lldb/Target/Target.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/RegisterContext.h"
#include "lldb/Target/StackFrame.h"
+#include "lldb/Target/Target.h"
#include "lldb/Target/Thread.h"
using namespace lldb;
using namespace lldb_private;
-enum dwarf_regnums
-{
- dwarf_r0 = 0,
- dwarf_r1,
- dwarf_r2,
- dwarf_r3,
- dwarf_r4,
- dwarf_r5,
- dwarf_r6,
- dwarf_r7,
- dwarf_r8,
- dwarf_r9,
- dwarf_r10,
- dwarf_r11,
- dwarf_r12,
- dwarf_r13,
- dwarf_r14,
- dwarf_r15,
- dwarf_r16,
- dwarf_r17,
- dwarf_r18,
- dwarf_r19,
- dwarf_r20,
- dwarf_r21,
- dwarf_r22,
- dwarf_r23,
- dwarf_r24,
- dwarf_r25,
- dwarf_r26,
- dwarf_r27,
- dwarf_r28,
- dwarf_r29,
- dwarf_r30,
- dwarf_r31,
- dwarf_sr,
- dwarf_lo,
- dwarf_hi,
- dwarf_bad,
- dwarf_cause,
- dwarf_pc
+enum dwarf_regnums {
+ dwarf_r0 = 0,
+ dwarf_r1,
+ dwarf_r2,
+ dwarf_r3,
+ dwarf_r4,
+ dwarf_r5,
+ dwarf_r6,
+ dwarf_r7,
+ dwarf_r8,
+ dwarf_r9,
+ dwarf_r10,
+ dwarf_r11,
+ dwarf_r12,
+ dwarf_r13,
+ dwarf_r14,
+ dwarf_r15,
+ dwarf_r16,
+ dwarf_r17,
+ dwarf_r18,
+ dwarf_r19,
+ dwarf_r20,
+ dwarf_r21,
+ dwarf_r22,
+ dwarf_r23,
+ dwarf_r24,
+ dwarf_r25,
+ dwarf_r26,
+ dwarf_r27,
+ dwarf_r28,
+ dwarf_r29,
+ dwarf_r30,
+ dwarf_r31,
+ dwarf_sr,
+ dwarf_lo,
+ dwarf_hi,
+ dwarf_bad,
+ dwarf_cause,
+ dwarf_pc
};
-static const RegisterInfo
-g_register_infos_mips64[] =
-{
- // NAME ALT SZ OFF ENCODING FORMAT EH_FRAME DWARF GENERIC PROCESS PLUGIN LLDB NATIVE
- // ======== ====== == === ============= ========== ============= ================= ==================== ================= ====================
- { "r0" , "zero", 8, 0, eEncodingUint, eFormatHex, { dwarf_r0, dwarf_r0, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r1" , "AT", 8, 0, eEncodingUint, eFormatHex, { dwarf_r1, dwarf_r1, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r2" , "v0", 8, 0, eEncodingUint, eFormatHex, { dwarf_r2, dwarf_r2, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r3" , "v1", 8, 0, eEncodingUint, eFormatHex, { dwarf_r3, dwarf_r3, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r4" , "arg1", 8, 0, eEncodingUint, eFormatHex, { dwarf_r4, dwarf_r4, LLDB_REGNUM_GENERIC_ARG1, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r5" , "arg2", 8, 0, eEncodingUint, eFormatHex, { dwarf_r5, dwarf_r5, LLDB_REGNUM_GENERIC_ARG2, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r6" , "arg3", 8, 0, eEncodingUint, eFormatHex, { dwarf_r6, dwarf_r6, LLDB_REGNUM_GENERIC_ARG3, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r7" , "arg4", 8, 0, eEncodingUint, eFormatHex, { dwarf_r7, dwarf_r7, LLDB_REGNUM_GENERIC_ARG4, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r8" , "arg5", 8, 0, eEncodingUint, eFormatHex, { dwarf_r8, dwarf_r8, LLDB_REGNUM_GENERIC_ARG5, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r9" , "arg6", 8, 0, eEncodingUint, eFormatHex, { dwarf_r9, dwarf_r9, LLDB_REGNUM_GENERIC_ARG6, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r10" , "arg7", 8, 0, eEncodingUint, eFormatHex, { dwarf_r10, dwarf_r10, LLDB_REGNUM_GENERIC_ARG7, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r11" , "arg8", 8, 0, eEncodingUint, eFormatHex, { dwarf_r11, dwarf_r11, LLDB_REGNUM_GENERIC_ARG8, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r12" , nullptr,8, 0, eEncodingUint, eFormatHex, { dwarf_r12, dwarf_r12, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r13" , nullptr,8, 0, eEncodingUint, eFormatHex, { dwarf_r13, dwarf_r13, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r14" , nullptr,8, 0, eEncodingUint, eFormatHex, { dwarf_r14, dwarf_r14, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r15" , nullptr,8, 0, eEncodingUint, eFormatHex, { dwarf_r15, dwarf_r15, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r16" , nullptr,8, 0, eEncodingUint, eFormatHex, { dwarf_r16, dwarf_r16, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r17" , nullptr,8, 0, eEncodingUint, eFormatHex, { dwarf_r17, dwarf_r17, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r18" , nullptr,8, 0, eEncodingUint, eFormatHex, { dwarf_r18, dwarf_r18, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r19" , nullptr,8, 0, eEncodingUint, eFormatHex, { dwarf_r19, dwarf_r19, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r20" , nullptr,8, 0, eEncodingUint, eFormatHex, { dwarf_r20, dwarf_r20, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r21" , nullptr,8, 0, eEncodingUint, eFormatHex, { dwarf_r21, dwarf_r21, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r22" , nullptr,8, 0, eEncodingUint, eFormatHex, { dwarf_r22, dwarf_r22, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r23" , nullptr,8, 0, eEncodingUint, eFormatHex, { dwarf_r23, dwarf_r23, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r24" , nullptr,8, 0, eEncodingUint, eFormatHex, { dwarf_r24, dwarf_r24, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r25" , nullptr,8, 0, eEncodingUint, eFormatHex, { dwarf_r25, dwarf_r25, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r26" , nullptr,8, 0, eEncodingUint, eFormatHex, { dwarf_r26, dwarf_r26, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r27" , nullptr,8, 0, eEncodingUint, eFormatHex, { dwarf_r27, dwarf_r27, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r28" , "gp", 8, 0, eEncodingUint, eFormatHex, { dwarf_r28, dwarf_r28, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r29" , "sp", 8, 0, eEncodingUint, eFormatHex, { dwarf_r29, dwarf_r29, LLDB_REGNUM_GENERIC_SP, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r30" , "fp", 8, 0, eEncodingUint, eFormatHex, { dwarf_r30, dwarf_r30, LLDB_REGNUM_GENERIC_FP, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r31" , "ra", 8, 0, eEncodingUint, eFormatHex, { dwarf_r31, dwarf_r31, LLDB_REGNUM_GENERIC_RA, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "sr" , nullptr,4, 0, eEncodingUint, eFormatHex, { dwarf_sr, dwarf_sr, LLDB_REGNUM_GENERIC_FLAGS, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "lo" , nullptr,8, 0, eEncodingUint, eFormatHex, { dwarf_lo, dwarf_lo, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "hi" , nullptr,8, 0, eEncodingUint, eFormatHex, { dwarf_hi, dwarf_hi, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "bad" , nullptr,8, 0, eEncodingUint, eFormatHex, { dwarf_bad, dwarf_bad, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "cause" , nullptr,8, 0, eEncodingUint, eFormatHex, { dwarf_cause, dwarf_cause, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "pc" , nullptr,8, 0, eEncodingUint, eFormatHex, { dwarf_pc, dwarf_pc, LLDB_REGNUM_GENERIC_PC, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
+static const RegisterInfo g_register_infos_mips64[] = {
+ // NAME ALT SZ OFF ENCODING FORMAT EH_FRAME
+ // DWARF GENERIC PROCESS PLUGIN
+ // LLDB NATIVE
+ // ======== ====== == === ============= ========== =============
+ // ================= ==================== =================
+ // ====================
+ {"r0",
+ "zero",
+ 8,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r0, dwarf_r0, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r1",
+ "AT",
+ 8,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r1, dwarf_r1, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r2",
+ "v0",
+ 8,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r2, dwarf_r2, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r3",
+ "v1",
+ 8,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r3, dwarf_r3, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r4",
+ "arg1",
+ 8,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r4, dwarf_r4, LLDB_REGNUM_GENERIC_ARG1, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r5",
+ "arg2",
+ 8,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r5, dwarf_r5, LLDB_REGNUM_GENERIC_ARG2, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r6",
+ "arg3",
+ 8,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r6, dwarf_r6, LLDB_REGNUM_GENERIC_ARG3, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r7",
+ "arg4",
+ 8,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r7, dwarf_r7, LLDB_REGNUM_GENERIC_ARG4, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r8",
+ "arg5",
+ 8,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r8, dwarf_r8, LLDB_REGNUM_GENERIC_ARG5, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r9",
+ "arg6",
+ 8,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r9, dwarf_r9, LLDB_REGNUM_GENERIC_ARG6, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r10",
+ "arg7",
+ 8,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r10, dwarf_r10, LLDB_REGNUM_GENERIC_ARG7, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r11",
+ "arg8",
+ 8,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r11, dwarf_r11, LLDB_REGNUM_GENERIC_ARG8, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r12",
+ nullptr,
+ 8,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r12, dwarf_r12, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r13",
+ nullptr,
+ 8,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r13, dwarf_r13, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r14",
+ nullptr,
+ 8,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r14, dwarf_r14, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r15",
+ nullptr,
+ 8,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r15, dwarf_r15, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r16",
+ nullptr,
+ 8,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r16, dwarf_r16, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r17",
+ nullptr,
+ 8,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r17, dwarf_r17, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r18",
+ nullptr,
+ 8,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r18, dwarf_r18, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r19",
+ nullptr,
+ 8,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r19, dwarf_r19, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r20",
+ nullptr,
+ 8,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r20, dwarf_r20, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r21",
+ nullptr,
+ 8,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r21, dwarf_r21, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r22",
+ nullptr,
+ 8,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r22, dwarf_r22, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r23",
+ nullptr,
+ 8,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r23, dwarf_r23, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r24",
+ nullptr,
+ 8,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r24, dwarf_r24, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r25",
+ nullptr,
+ 8,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r25, dwarf_r25, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r26",
+ nullptr,
+ 8,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r26, dwarf_r26, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r27",
+ nullptr,
+ 8,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r27, dwarf_r27, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r28",
+ "gp",
+ 8,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r28, dwarf_r28, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r29",
+ "sp",
+ 8,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r29, dwarf_r29, LLDB_REGNUM_GENERIC_SP, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r30",
+ "fp",
+ 8,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r30, dwarf_r30, LLDB_REGNUM_GENERIC_FP, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r31",
+ "ra",
+ 8,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r31, dwarf_r31, LLDB_REGNUM_GENERIC_RA, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"sr",
+ nullptr,
+ 4,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_sr, dwarf_sr, LLDB_REGNUM_GENERIC_FLAGS, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"lo",
+ nullptr,
+ 8,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_lo, dwarf_lo, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"hi",
+ nullptr,
+ 8,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_hi, dwarf_hi, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"bad",
+ nullptr,
+ 8,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_bad, dwarf_bad, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"cause",
+ nullptr,
+ 8,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_cause, dwarf_cause, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"pc",
+ nullptr,
+ 8,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_pc, dwarf_pc, LLDB_REGNUM_GENERIC_PC, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
};
-static const uint32_t k_num_register_infos = llvm::array_lengthof(g_register_infos_mips64);
+static const uint32_t k_num_register_infos =
+ llvm::array_lengthof(g_register_infos_mips64);
const lldb_private::RegisterInfo *
-ABISysV_mips64::GetRegisterInfoArray (uint32_t &count)
-{
- count = k_num_register_infos;
- return g_register_infos_mips64;
+ABISysV_mips64::GetRegisterInfoArray(uint32_t &count) {
+ count = k_num_register_infos;
+ return g_register_infos_mips64;
}
-size_t
-ABISysV_mips64::GetRedZoneSize () const
-{
- return 0;
-}
+size_t ABISysV_mips64::GetRedZoneSize() const { return 0; }
//------------------------------------------------------------------
// Static Functions
//------------------------------------------------------------------
ABISP
-ABISysV_mips64::CreateInstance (const ArchSpec &arch)
-{
- static ABISP g_abi_sp;
- const llvm::Triple::ArchType arch_type = arch.GetTriple().getArch();
- if ((arch_type == llvm::Triple::mips64) ||
- (arch_type == llvm::Triple::mips64el))
- {
- if (!g_abi_sp)
- g_abi_sp.reset (new ABISysV_mips64);
- return g_abi_sp;
- }
- return ABISP();
+ABISysV_mips64::CreateInstance(const ArchSpec &arch) {
+ static ABISP g_abi_sp;
+ const llvm::Triple::ArchType arch_type = arch.GetTriple().getArch();
+ if ((arch_type == llvm::Triple::mips64) ||
+ (arch_type == llvm::Triple::mips64el)) {
+ if (!g_abi_sp)
+ g_abi_sp.reset(new ABISysV_mips64);
+ return g_abi_sp;
+ }
+ return ABISP();
}
-bool
-ABISysV_mips64::PrepareTrivialCall (Thread &thread,
- addr_t sp,
- addr_t func_addr,
- addr_t return_addr,
- llvm::ArrayRef<addr_t> args) const
-{
- Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
-
- if (log)
- {
- StreamString s;
- s.Printf("ABISysV_mips64::PrepareTrivialCall (tid = 0x%" PRIx64 ", sp = 0x%" PRIx64 ", func_addr = 0x%" PRIx64 ", return_addr = 0x%" PRIx64,
- thread.GetID(),
- (uint64_t)sp,
- (uint64_t)func_addr,
- (uint64_t)return_addr);
-
- for (size_t i = 0; i < args.size(); ++i)
- s.Printf (", arg%zd = 0x%" PRIx64, i + 1, args[i]);
- s.PutCString (")");
- log->PutCString(s.GetString().c_str());
- }
-
- RegisterContext *reg_ctx = thread.GetRegisterContext().get();
- if (!reg_ctx)
- return false;
-
- const RegisterInfo *reg_info = nullptr;
-
- if (args.size() > 8) // TODO handle more than 8 arguments
- return false;
+bool ABISysV_mips64::PrepareTrivialCall(Thread &thread, addr_t sp,
+ addr_t func_addr, addr_t return_addr,
+ llvm::ArrayRef<addr_t> args) const {
+ Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
+
+ if (log) {
+ StreamString s;
+ s.Printf("ABISysV_mips64::PrepareTrivialCall (tid = 0x%" PRIx64
+ ", sp = 0x%" PRIx64 ", func_addr = 0x%" PRIx64
+ ", return_addr = 0x%" PRIx64,
+ thread.GetID(), (uint64_t)sp, (uint64_t)func_addr,
+ (uint64_t)return_addr);
for (size_t i = 0; i < args.size(); ++i)
- {
- reg_info = reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG1 + i);
- if (log)
- log->Printf("About to write arg%zd (0x%" PRIx64 ") into %s", i + 1, args[i], reg_info->name);
- if (!reg_ctx->WriteRegisterFromUnsigned(reg_info, args[i]))
- return false;
- }
+ s.Printf(", arg%zd = 0x%" PRIx64, i + 1, args[i]);
+ s.PutCString(")");
+ log->PutCString(s.GetString().c_str());
+ }
- // First, align the SP
-
- if (log)
- log->Printf("16-byte aligning SP: 0x%" PRIx64 " to 0x%" PRIx64, (uint64_t)sp, (uint64_t)(sp & ~0xfull));
+ RegisterContext *reg_ctx = thread.GetRegisterContext().get();
+ if (!reg_ctx)
+ return false;
- sp &= ~(0xfull); // 16-byte alignment
+ const RegisterInfo *reg_info = nullptr;
- Error error;
- const RegisterInfo *pc_reg_info = reg_ctx->GetRegisterInfo (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_PC);
- const RegisterInfo *sp_reg_info = reg_ctx->GetRegisterInfo (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_SP);
- const RegisterInfo *ra_reg_info = reg_ctx->GetRegisterInfo (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_RA);
- const RegisterInfo *r25_info = reg_ctx->GetRegisterInfoByName("r25", 0);
- const RegisterInfo *r0_info = reg_ctx->GetRegisterInfoByName("zero", 0);
+ if (args.size() > 8) // TODO handle more than 8 arguments
+ return false;
+ for (size_t i = 0; i < args.size(); ++i) {
+ reg_info = reg_ctx->GetRegisterInfo(eRegisterKindGeneric,
+ LLDB_REGNUM_GENERIC_ARG1 + i);
if (log)
- log->Printf("Writing R0: 0x%" PRIx64, (uint64_t)0);
-
- /* Write r0 with 0, in case we are stopped in syscall,
- * such setting prevents automatic decrement of the PC.
- * This clears the bug 23659 for MIPS.
- */
- if (!reg_ctx->WriteRegisterFromUnsigned (r0_info, (uint64_t)0))
- return false;
+ log->Printf("About to write arg%zd (0x%" PRIx64 ") into %s", i + 1,
+ args[i], reg_info->name);
+ if (!reg_ctx->WriteRegisterFromUnsigned(reg_info, args[i]))
+ return false;
+ }
+
+ // First, align the SP
+
+ if (log)
+ log->Printf("16-byte aligning SP: 0x%" PRIx64 " to 0x%" PRIx64,
+ (uint64_t)sp, (uint64_t)(sp & ~0xfull));
+
+ sp &= ~(0xfull); // 16-byte alignment
+
+ Error error;
+ const RegisterInfo *pc_reg_info =
+ reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_PC);
+ const RegisterInfo *sp_reg_info =
+ reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_SP);
+ const RegisterInfo *ra_reg_info =
+ reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_RA);
+ const RegisterInfo *r25_info = reg_ctx->GetRegisterInfoByName("r25", 0);
+ const RegisterInfo *r0_info = reg_ctx->GetRegisterInfoByName("zero", 0);
+
+ if (log)
+ log->Printf("Writing R0: 0x%" PRIx64, (uint64_t)0);
+
+ /* Write r0 with 0, in case we are stopped in syscall,
+ * such setting prevents automatic decrement of the PC.
+ * This clears the bug 23659 for MIPS.
+ */
+ if (!reg_ctx->WriteRegisterFromUnsigned(r0_info, (uint64_t)0))
+ return false;
- if (log)
- log->Printf("Writing SP: 0x%" PRIx64, (uint64_t)sp);
+ if (log)
+ log->Printf("Writing SP: 0x%" PRIx64, (uint64_t)sp);
- // Set "sp" to the requested value
- if (!reg_ctx->WriteRegisterFromUnsigned (sp_reg_info, sp))
- return false;
+ // Set "sp" to the requested value
+ if (!reg_ctx->WriteRegisterFromUnsigned(sp_reg_info, sp))
+ return false;
- if (log)
- log->Printf("Writing RA: 0x%" PRIx64, (uint64_t)return_addr);
+ if (log)
+ log->Printf("Writing RA: 0x%" PRIx64, (uint64_t)return_addr);
- // Set "ra" to the return address
- if (!reg_ctx->WriteRegisterFromUnsigned (ra_reg_info, return_addr))
- return false;
+ // Set "ra" to the return address
+ if (!reg_ctx->WriteRegisterFromUnsigned(ra_reg_info, return_addr))
+ return false;
- if (log)
- log->Printf("Writing PC: 0x%" PRIx64, (uint64_t)func_addr);
+ if (log)
+ log->Printf("Writing PC: 0x%" PRIx64, (uint64_t)func_addr);
- // Set pc to the address of the called function.
- if (!reg_ctx->WriteRegisterFromUnsigned (pc_reg_info, func_addr))
- return false;
+ // Set pc to the address of the called function.
+ if (!reg_ctx->WriteRegisterFromUnsigned(pc_reg_info, func_addr))
+ return false;
- if (log)
- log->Printf("Writing r25: 0x%" PRIx64, (uint64_t)func_addr);
+ if (log)
+ log->Printf("Writing r25: 0x%" PRIx64, (uint64_t)func_addr);
- // All callers of position independent functions must place the address of the called function in t9 (r25)
- if (!reg_ctx->WriteRegisterFromUnsigned (r25_info, func_addr))
- return false;
+ // All callers of position independent functions must place the address of the
+ // called function in t9 (r25)
+ if (!reg_ctx->WriteRegisterFromUnsigned(r25_info, func_addr))
+ return false;
- return true;
+ return true;
}
-bool
-ABISysV_mips64::GetArgumentValues (Thread &thread, ValueList &values) const
-{
- return false;
+bool ABISysV_mips64::GetArgumentValues(Thread &thread,
+ ValueList &values) const {
+ return false;
}
-Error
-ABISysV_mips64::SetReturnValueObject(lldb::StackFrameSP &frame_sp, lldb::ValueObjectSP &new_value_sp)
-{
- Error error;
- if (!new_value_sp)
- {
- error.SetErrorString("Empty value object for return value.");
- return error;
- }
+Error ABISysV_mips64::SetReturnValueObject(lldb::StackFrameSP &frame_sp,
+ lldb::ValueObjectSP &new_value_sp) {
+ Error error;
+ if (!new_value_sp) {
+ error.SetErrorString("Empty value object for return value.");
+ return error;
+ }
- CompilerType compiler_type = new_value_sp->GetCompilerType();
- if (!compiler_type)
- {
- error.SetErrorString ("Null clang type for return value.");
- return error;
- }
+ CompilerType compiler_type = new_value_sp->GetCompilerType();
+ if (!compiler_type) {
+ error.SetErrorString("Null clang type for return value.");
+ return error;
+ }
- Thread *thread = frame_sp->GetThread().get();
+ Thread *thread = frame_sp->GetThread().get();
- RegisterContext *reg_ctx = thread->GetRegisterContext().get();
+ RegisterContext *reg_ctx = thread->GetRegisterContext().get();
- if (!reg_ctx)
- error.SetErrorString("no registers are available");
-
- DataExtractor data;
- Error data_error;
- size_t num_bytes = new_value_sp->GetData(data, data_error);
- if (data_error.Fail())
- {
- error.SetErrorStringWithFormat("Couldn't convert return value to raw data: %s", data_error.AsCString());
- return error;
- }
+ if (!reg_ctx)
+ error.SetErrorString("no registers are available");
- const uint32_t type_flags = compiler_type.GetTypeInfo(nullptr);
-
- if (type_flags & eTypeIsScalar ||
- type_flags & eTypeIsPointer)
- {
- if (type_flags & eTypeIsInteger ||
- type_flags & eTypeIsPointer )
- {
- lldb::offset_t offset = 0;
-
- if (num_bytes <= 16)
- {
- const RegisterInfo *r2_info = reg_ctx->GetRegisterInfoByName("r2", 0);
- if (num_bytes <= 8)
- {
- uint64_t raw_value = data.GetMaxU64(&offset, num_bytes);
-
- if (!reg_ctx->WriteRegisterFromUnsigned (r2_info, raw_value))
- error.SetErrorString ("failed to write register r2");
- }
- else
- {
- uint64_t raw_value = data.GetMaxU64(&offset, 8);
- if (reg_ctx->WriteRegisterFromUnsigned (r2_info, raw_value))
- {
- const RegisterInfo *r3_info = reg_ctx->GetRegisterInfoByName("r3", 0);
- raw_value = data.GetMaxU64(&offset, num_bytes - offset);
-
- if (!reg_ctx->WriteRegisterFromUnsigned (r3_info, raw_value))
- error.SetErrorString ("failed to write register r3");
- }
- else
- error.SetErrorString ("failed to write register r2");
- }
- }
- else
- {
- error.SetErrorString("We don't support returning longer than 128 bit integer values at present.");
- }
- }
- else if (type_flags & eTypeIsFloat)
- {
- error.SetErrorString("TODO: Handle Float Types.");
+ DataExtractor data;
+ Error data_error;
+ size_t num_bytes = new_value_sp->GetData(data, data_error);
+ if (data_error.Fail()) {
+ error.SetErrorStringWithFormat(
+ "Couldn't convert return value to raw data: %s",
+ data_error.AsCString());
+ return error;
+ }
+
+ const uint32_t type_flags = compiler_type.GetTypeInfo(nullptr);
+
+ if (type_flags & eTypeIsScalar || type_flags & eTypeIsPointer) {
+ if (type_flags & eTypeIsInteger || type_flags & eTypeIsPointer) {
+ lldb::offset_t offset = 0;
+
+ if (num_bytes <= 16) {
+ const RegisterInfo *r2_info = reg_ctx->GetRegisterInfoByName("r2", 0);
+ if (num_bytes <= 8) {
+ uint64_t raw_value = data.GetMaxU64(&offset, num_bytes);
+
+ if (!reg_ctx->WriteRegisterFromUnsigned(r2_info, raw_value))
+ error.SetErrorString("failed to write register r2");
+ } else {
+ uint64_t raw_value = data.GetMaxU64(&offset, 8);
+ if (reg_ctx->WriteRegisterFromUnsigned(r2_info, raw_value)) {
+ const RegisterInfo *r3_info =
+ reg_ctx->GetRegisterInfoByName("r3", 0);
+ raw_value = data.GetMaxU64(&offset, num_bytes - offset);
+
+ if (!reg_ctx->WriteRegisterFromUnsigned(r3_info, raw_value))
+ error.SetErrorString("failed to write register r3");
+ } else
+ error.SetErrorString("failed to write register r2");
}
+ } else {
+ error.SetErrorString("We don't support returning longer than 128 bit "
+ "integer values at present.");
+ }
+ } else if (type_flags & eTypeIsFloat) {
+ error.SetErrorString("TODO: Handle Float Types.");
}
- else if (type_flags & eTypeIsVector)
- {
- error.SetErrorString("returning vector values are not supported");
- }
+ } else if (type_flags & eTypeIsVector) {
+ error.SetErrorString("returning vector values are not supported");
+ }
- return error;
+ return error;
}
-ValueObjectSP
-ABISysV_mips64::GetReturnValueObjectSimple (Thread &thread, CompilerType &return_compiler_type) const
-{
- ValueObjectSP return_valobj_sp;
- return return_valobj_sp;
+ValueObjectSP ABISysV_mips64::GetReturnValueObjectSimple(
+ Thread &thread, CompilerType &return_compiler_type) const {
+ ValueObjectSP return_valobj_sp;
+ return return_valobj_sp;
}
-ValueObjectSP
-ABISysV_mips64::GetReturnValueObjectImpl (Thread &thread, CompilerType &return_compiler_type) const
-{
- ValueObjectSP return_valobj_sp;
- Value value;
- Error error;
-
- ExecutionContext exe_ctx (thread.shared_from_this());
- if (exe_ctx.GetTargetPtr() == nullptr || exe_ctx.GetProcessPtr() == nullptr)
- return return_valobj_sp;
-
- value.SetCompilerType(return_compiler_type);
-
- RegisterContext *reg_ctx = thread.GetRegisterContext().get();
- if (!reg_ctx)
- return return_valobj_sp;
-
- Target *target = exe_ctx.GetTargetPtr();
- const ArchSpec target_arch = target->GetArchitecture();
- ByteOrder target_byte_order = target_arch.GetByteOrder();
- const size_t byte_size = return_compiler_type.GetByteSize(nullptr);
- const uint32_t type_flags = return_compiler_type.GetTypeInfo(nullptr);
- uint32_t fp_flag = target_arch.GetFlags () & lldb_private::ArchSpec::eMIPS_ABI_FP_mask;
-
- const RegisterInfo *r2_info = reg_ctx->GetRegisterInfoByName("r2", 0);
- const RegisterInfo *r3_info = reg_ctx->GetRegisterInfoByName("r3", 0);
-
- if (type_flags & eTypeIsScalar ||
- type_flags & eTypeIsPointer)
- {
- value.SetValueType(Value::eValueTypeScalar);
-
- bool success = false;
- if (type_flags & eTypeIsInteger ||
- type_flags & eTypeIsPointer)
- {
- // Extract the register context so we can read arguments from registers
- // In MIPS register "r2" (v0) holds the integer function return values
-
- uint64_t raw_value = reg_ctx->ReadRegisterAsUnsigned(r2_info, 0);
-
- const bool is_signed = (type_flags & eTypeIsSigned) != 0;
- switch (byte_size)
- {
- default:
- break;
-
- case sizeof(uint64_t):
- if (is_signed)
- value.GetScalar() = (int64_t)(raw_value);
- else
- value.GetScalar() = (uint64_t)(raw_value);
- success = true;
- break;
-
- case sizeof(uint32_t):
- if (is_signed)
- value.GetScalar() = (int32_t)(raw_value & UINT32_MAX);
- else
- value.GetScalar() = (uint32_t)(raw_value & UINT32_MAX);
- success = true;
- break;
-
- case sizeof(uint16_t):
- if (is_signed)
- value.GetScalar() = (int16_t)(raw_value & UINT16_MAX);
- else
- value.GetScalar() = (uint16_t)(raw_value & UINT16_MAX);
- success = true;
- break;
-
- case sizeof(uint8_t):
- if (is_signed)
- value.GetScalar() = (int8_t)(raw_value & UINT8_MAX);
- else
- value.GetScalar() = (uint8_t)(raw_value & UINT8_MAX);
- success = true;
- break;
- }
+ValueObjectSP ABISysV_mips64::GetReturnValueObjectImpl(
+ Thread &thread, CompilerType &return_compiler_type) const {
+ ValueObjectSP return_valobj_sp;
+ Value value;
+ Error error;
+
+ ExecutionContext exe_ctx(thread.shared_from_this());
+ if (exe_ctx.GetTargetPtr() == nullptr || exe_ctx.GetProcessPtr() == nullptr)
+ return return_valobj_sp;
+
+ value.SetCompilerType(return_compiler_type);
+
+ RegisterContext *reg_ctx = thread.GetRegisterContext().get();
+ if (!reg_ctx)
+ return return_valobj_sp;
+
+ Target *target = exe_ctx.GetTargetPtr();
+ const ArchSpec target_arch = target->GetArchitecture();
+ ByteOrder target_byte_order = target_arch.GetByteOrder();
+ const size_t byte_size = return_compiler_type.GetByteSize(nullptr);
+ const uint32_t type_flags = return_compiler_type.GetTypeInfo(nullptr);
+ uint32_t fp_flag =
+ target_arch.GetFlags() & lldb_private::ArchSpec::eMIPS_ABI_FP_mask;
+
+ const RegisterInfo *r2_info = reg_ctx->GetRegisterInfoByName("r2", 0);
+ const RegisterInfo *r3_info = reg_ctx->GetRegisterInfoByName("r3", 0);
+
+ if (type_flags & eTypeIsScalar || type_flags & eTypeIsPointer) {
+ value.SetValueType(Value::eValueTypeScalar);
+
+ bool success = false;
+ if (type_flags & eTypeIsInteger || type_flags & eTypeIsPointer) {
+ // Extract the register context so we can read arguments from registers
+ // In MIPS register "r2" (v0) holds the integer function return values
+
+ uint64_t raw_value = reg_ctx->ReadRegisterAsUnsigned(r2_info, 0);
+
+ const bool is_signed = (type_flags & eTypeIsSigned) != 0;
+ switch (byte_size) {
+ default:
+ break;
+
+ case sizeof(uint64_t):
+ if (is_signed)
+ value.GetScalar() = (int64_t)(raw_value);
+ else
+ value.GetScalar() = (uint64_t)(raw_value);
+ success = true;
+ break;
+
+ case sizeof(uint32_t):
+ if (is_signed)
+ value.GetScalar() = (int32_t)(raw_value & UINT32_MAX);
+ else
+ value.GetScalar() = (uint32_t)(raw_value & UINT32_MAX);
+ success = true;
+ break;
+
+ case sizeof(uint16_t):
+ if (is_signed)
+ value.GetScalar() = (int16_t)(raw_value & UINT16_MAX);
+ else
+ value.GetScalar() = (uint16_t)(raw_value & UINT16_MAX);
+ success = true;
+ break;
+
+ case sizeof(uint8_t):
+ if (is_signed)
+ value.GetScalar() = (int8_t)(raw_value & UINT8_MAX);
+ else
+ value.GetScalar() = (uint8_t)(raw_value & UINT8_MAX);
+ success = true;
+ break;
+ }
+ } else if (type_flags & eTypeIsFloat) {
+ if (type_flags & eTypeIsComplex) {
+ // Don't handle complex yet.
+ } else if (IsSoftFloat(fp_flag)) {
+ uint64_t raw_value = reg_ctx->ReadRegisterAsUnsigned(r2_info, 0);
+ switch (byte_size) {
+ case 4:
+ value.GetScalar() = *((float *)(&raw_value));
+ success = true;
+ break;
+ case 8:
+ value.GetScalar() = *((double *)(&raw_value));
+ success = true;
+ break;
+ case 16:
+ uint64_t result[2];
+ if (target_byte_order == eByteOrderLittle) {
+ result[0] = raw_value;
+ result[1] = reg_ctx->ReadRegisterAsUnsigned(r3_info, 0);
+ value.GetScalar() = *((long double *)(result));
+ } else {
+ result[0] = reg_ctx->ReadRegisterAsUnsigned(r3_info, 0);
+ result[1] = raw_value;
+ value.GetScalar() = *((long double *)(result));
+ }
+ success = true;
+ break;
}
- else if (type_flags & eTypeIsFloat)
- {
- if (type_flags & eTypeIsComplex)
- {
- // Don't handle complex yet.
- }
- else if (IsSoftFloat(fp_flag))
- {
- uint64_t raw_value = reg_ctx->ReadRegisterAsUnsigned(r2_info, 0);
- switch (byte_size)
- {
- case 4:
- value.GetScalar() = *((float *)(&raw_value));
- success = true;
- break;
- case 8:
- value.GetScalar() = *((double *)(&raw_value));
- success = true;
- break;
- case 16:
- uint64_t result[2];
- if (target_byte_order == eByteOrderLittle)
- {
- result[0] = raw_value;
- result[1] = reg_ctx->ReadRegisterAsUnsigned(r3_info, 0);
- value.GetScalar() = *((long double *)(result));
- }
- else
- {
- result[0] = reg_ctx->ReadRegisterAsUnsigned(r3_info, 0);
- result[1] = raw_value;
- value.GetScalar() = *((long double *)(result));
- }
- success = true;
- break;
- }
+ } else {
+ if (byte_size <= sizeof(long double)) {
+ const RegisterInfo *f0_info = reg_ctx->GetRegisterInfoByName("f0", 0);
+
+ RegisterValue f0_value;
+ DataExtractor f0_data;
+
+ reg_ctx->ReadRegister(f0_info, f0_value);
+
+ f0_value.GetData(f0_data);
+
+ lldb::offset_t offset = 0;
+ if (byte_size == sizeof(float)) {
+ value.GetScalar() = (float)f0_data.GetFloat(&offset);
+ success = true;
+ } else if (byte_size == sizeof(double)) {
+ value.GetScalar() = (double)f0_data.GetDouble(&offset);
+ success = true;
+ } else if (byte_size == sizeof(long double)) {
+ const RegisterInfo *f2_info =
+ reg_ctx->GetRegisterInfoByName("f2", 0);
+ RegisterValue f2_value;
+ DataExtractor f2_data;
+ reg_ctx->ReadRegister(f2_info, f2_value);
+ DataExtractor *copy_from_extractor = nullptr;
+ DataBufferSP data_sp(new DataBufferHeap(16, 0));
+ DataExtractor return_ext(
+ data_sp, target_byte_order,
+ target->GetArchitecture().GetAddressByteSize());
+
+ if (target_byte_order == eByteOrderLittle) {
+ copy_from_extractor = &f0_data;
+ copy_from_extractor->CopyByteOrderedData(
+ 0, 8, data_sp->GetBytes(), byte_size - 8, target_byte_order);
+ f2_value.GetData(f2_data);
+ copy_from_extractor = &f2_data;
+ copy_from_extractor->CopyByteOrderedData(
+ 0, 8, data_sp->GetBytes() + 8, byte_size - 8,
+ target_byte_order);
+ } else {
+ copy_from_extractor = &f0_data;
+ copy_from_extractor->CopyByteOrderedData(
+ 0, 8, data_sp->GetBytes() + 8, byte_size - 8,
+ target_byte_order);
+ f2_value.GetData(f2_data);
+ copy_from_extractor = &f2_data;
+ copy_from_extractor->CopyByteOrderedData(
+ 0, 8, data_sp->GetBytes(), byte_size - 8, target_byte_order);
}
- else
- {
- if (byte_size <= sizeof(long double))
- {
- const RegisterInfo *f0_info = reg_ctx->GetRegisterInfoByName("f0", 0);
-
- RegisterValue f0_value;
- DataExtractor f0_data;
-
- reg_ctx->ReadRegister (f0_info, f0_value);
-
-
- f0_value.GetData(f0_data);
-
-
- lldb::offset_t offset = 0;
- if (byte_size == sizeof(float))
- {
- value.GetScalar() = (float) f0_data.GetFloat(&offset);
- success = true;
- }
- else if (byte_size == sizeof(double))
- {
- value.GetScalar() = (double) f0_data.GetDouble(&offset);
- success = true;
- }
- else if (byte_size == sizeof(long double))
- {
- const RegisterInfo *f2_info = reg_ctx->GetRegisterInfoByName("f2", 0);
- RegisterValue f2_value;
- DataExtractor f2_data;
- reg_ctx->ReadRegister (f2_info, f2_value);
- DataExtractor *copy_from_extractor = nullptr;
- DataBufferSP data_sp (new DataBufferHeap(16, 0));
- DataExtractor return_ext (data_sp,
- target_byte_order,
- target->GetArchitecture().GetAddressByteSize());
-
- if (target_byte_order == eByteOrderLittle)
- {
- copy_from_extractor = &f0_data;
- copy_from_extractor->CopyByteOrderedData (0,
- 8,
- data_sp->GetBytes(),
- byte_size - 8,
- target_byte_order);
- f2_value.GetData(f2_data);
- copy_from_extractor = &f2_data;
- copy_from_extractor->CopyByteOrderedData (0,
- 8,
- data_sp->GetBytes() + 8,
- byte_size - 8,
- target_byte_order);
- }
- else
- {
- copy_from_extractor = &f0_data;
- copy_from_extractor->CopyByteOrderedData (0,
- 8,
- data_sp->GetBytes() + 8,
- byte_size - 8,
- target_byte_order);
- f2_value.GetData(f2_data);
- copy_from_extractor = &f2_data;
- copy_from_extractor->CopyByteOrderedData (0,
- 8,
- data_sp->GetBytes(),
- byte_size - 8,
- target_byte_order);
- }
-
- return_valobj_sp = ValueObjectConstResult::Create (&thread,
- return_compiler_type,
- ConstString(""),
- return_ext);
- return return_valobj_sp;
- }
- }
- }
- }
- if (success)
- return_valobj_sp = ValueObjectConstResult::Create (thread.GetStackFrameAtIndex(0).get(),
- value,
- ConstString(""));
+ return_valobj_sp = ValueObjectConstResult::Create(
+ &thread, return_compiler_type, ConstString(""), return_ext);
+ return return_valobj_sp;
+ }
+ }
+ }
}
- else if (type_flags & eTypeIsStructUnion ||
- type_flags & eTypeIsClass ||
- type_flags & eTypeIsVector)
- {
- // Any structure of up to 16 bytes in size is returned in the registers.
- if (byte_size <= 16)
- {
- DataBufferSP data_sp (new DataBufferHeap(16, 0));
- DataExtractor return_ext (data_sp,
- target_byte_order,
- target->GetArchitecture().GetAddressByteSize());
-
- RegisterValue r2_value, r3_value, f0_value, f1_value, f2_value;
-
- uint32_t integer_bytes = 0; // Tracks how much bytes of r2 and r3 registers we've consumed so far
- bool use_fp_regs = 0; // True if return values are in FP return registers.
- bool found_non_fp_field = 0; // True if we found any non floating point field in structure.
- bool use_r2 = 0; // True if return values are in r2 register.
- bool use_r3 = 0; // True if return values are in r3 register.
- bool sucess = 0; // True if the result is copied into our data buffer
- std::string name;
- bool is_complex;
- uint32_t count;
- const uint32_t num_children = return_compiler_type.GetNumFields ();
-
- // A structure consisting of one or two FP values (and nothing else) will be
- // returned in the two FP return-value registers i.e fp0 and fp2.
- if (num_children <= 2)
- {
- uint64_t field_bit_offset = 0;
-
- // Check if this structure contains only floating point fields
- for (uint32_t idx = 0; idx < num_children; idx++)
- {
- CompilerType field_compiler_type = return_compiler_type.GetFieldAtIndex(idx, name, &field_bit_offset, nullptr, nullptr);
-
- if (field_compiler_type.IsFloatingPointType (count, is_complex))
- use_fp_regs = 1;
- else
- found_non_fp_field = 1;
- }
- if (use_fp_regs && !found_non_fp_field)
- {
- // We have one or two FP-only values in this structure. Get it from f0/f2 registers.
- DataExtractor f0_data, f1_data, f2_data;
- const RegisterInfo *f0_info = reg_ctx->GetRegisterInfoByName("f0", 0);
- const RegisterInfo *f1_info = reg_ctx->GetRegisterInfoByName("f1", 0);
- const RegisterInfo *f2_info = reg_ctx->GetRegisterInfoByName("f2", 0);
-
- reg_ctx->ReadRegister (f0_info, f0_value);
- reg_ctx->ReadRegister (f2_info, f2_value);
-
- f0_value.GetData(f0_data);
- f2_value.GetData(f2_data);
-
- for (uint32_t idx = 0; idx < num_children; idx++)
- {
- CompilerType field_compiler_type = return_compiler_type.GetFieldAtIndex(idx, name, &field_bit_offset, nullptr, nullptr);
- const size_t field_byte_width = field_compiler_type.GetByteSize(nullptr);
-
- DataExtractor *copy_from_extractor = nullptr;
-
- if (idx == 0)
- {
- if (field_byte_width == 16) // This case is for long double type.
- {
- // If structure contains long double type, then it is returned in fp0/fp1 registers.
- reg_ctx->ReadRegister (f1_info, f1_value);
- f1_value.GetData(f1_data);
-
- if (target_byte_order == eByteOrderLittle)
- {
- f0_data.Append(f1_data);
- copy_from_extractor = &f0_data;
- }
- else
- {
- f1_data.Append(f0_data);
- copy_from_extractor = &f1_data;
- }
- }
- else
- copy_from_extractor = &f0_data; // This is in f0, copy from register to our result structure
- }
- else
- copy_from_extractor = &f2_data; // This is in f2, copy from register to our result structure
-
- // Sanity check to avoid crash
- if (!copy_from_extractor || field_byte_width > copy_from_extractor->GetByteSize())
- return return_valobj_sp;
-
- // copy the register contents into our data buffer
- copy_from_extractor->CopyByteOrderedData (0,
- field_byte_width,
- data_sp->GetBytes() + (field_bit_offset/8),
- field_byte_width,
- target_byte_order);
- }
-
- // The result is in our data buffer. Create a variable object out of it
- return_valobj_sp = ValueObjectConstResult::Create (&thread,
- return_compiler_type,
- ConstString(""),
- return_ext);
+ if (success)
+ return_valobj_sp = ValueObjectConstResult::Create(
+ thread.GetStackFrameAtIndex(0).get(), value, ConstString(""));
+ } else if (type_flags & eTypeIsStructUnion || type_flags & eTypeIsClass ||
+ type_flags & eTypeIsVector) {
+ // Any structure of up to 16 bytes in size is returned in the registers.
+ if (byte_size <= 16) {
+ DataBufferSP data_sp(new DataBufferHeap(16, 0));
+ DataExtractor return_ext(data_sp, target_byte_order,
+ target->GetArchitecture().GetAddressByteSize());
+
+ RegisterValue r2_value, r3_value, f0_value, f1_value, f2_value;
+
+ uint32_t integer_bytes = 0; // Tracks how much bytes of r2 and r3
+ // registers we've consumed so far
+ bool use_fp_regs = 0; // True if return values are in FP return registers.
+ bool found_non_fp_field =
+ 0; // True if we found any non floating point field in structure.
+ bool use_r2 = 0; // True if return values are in r2 register.
+ bool use_r3 = 0; // True if return values are in r3 register.
+ bool sucess = 0; // True if the result is copied into our data buffer
+ std::string name;
+ bool is_complex;
+ uint32_t count;
+ const uint32_t num_children = return_compiler_type.GetNumFields();
+
+ // A structure consisting of one or two FP values (and nothing else) will
+ // be
+ // returned in the two FP return-value registers i.e fp0 and fp2.
+ if (num_children <= 2) {
+ uint64_t field_bit_offset = 0;
+
+ // Check if this structure contains only floating point fields
+ for (uint32_t idx = 0; idx < num_children; idx++) {
+ CompilerType field_compiler_type =
+ return_compiler_type.GetFieldAtIndex(idx, name, &field_bit_offset,
+ nullptr, nullptr);
+
+ if (field_compiler_type.IsFloatingPointType(count, is_complex))
+ use_fp_regs = 1;
+ else
+ found_non_fp_field = 1;
+ }
- return return_valobj_sp;
+ if (use_fp_regs && !found_non_fp_field) {
+ // We have one or two FP-only values in this structure. Get it from
+ // f0/f2 registers.
+ DataExtractor f0_data, f1_data, f2_data;
+ const RegisterInfo *f0_info = reg_ctx->GetRegisterInfoByName("f0", 0);
+ const RegisterInfo *f1_info = reg_ctx->GetRegisterInfoByName("f1", 0);
+ const RegisterInfo *f2_info = reg_ctx->GetRegisterInfoByName("f2", 0);
+
+ reg_ctx->ReadRegister(f0_info, f0_value);
+ reg_ctx->ReadRegister(f2_info, f2_value);
+
+ f0_value.GetData(f0_data);
+ f2_value.GetData(f2_data);
+
+ for (uint32_t idx = 0; idx < num_children; idx++) {
+ CompilerType field_compiler_type =
+ return_compiler_type.GetFieldAtIndex(
+ idx, name, &field_bit_offset, nullptr, nullptr);
+ const size_t field_byte_width =
+ field_compiler_type.GetByteSize(nullptr);
+
+ DataExtractor *copy_from_extractor = nullptr;
+
+ if (idx == 0) {
+ if (field_byte_width == 16) // This case is for long double type.
+ {
+ // If structure contains long double type, then it is returned
+ // in fp0/fp1 registers.
+ reg_ctx->ReadRegister(f1_info, f1_value);
+ f1_value.GetData(f1_data);
+
+ if (target_byte_order == eByteOrderLittle) {
+ f0_data.Append(f1_data);
+ copy_from_extractor = &f0_data;
+ } else {
+ f1_data.Append(f0_data);
+ copy_from_extractor = &f1_data;
}
- }
+ } else
+ copy_from_extractor = &f0_data; // This is in f0, copy from
+ // register to our result
+ // structure
+ } else
+ copy_from_extractor = &f2_data; // This is in f2, copy from
+ // register to our result
+ // structure
+
+ // Sanity check to avoid crash
+ if (!copy_from_extractor ||
+ field_byte_width > copy_from_extractor->GetByteSize())
+ return return_valobj_sp;
+
+ // copy the register contents into our data buffer
+ copy_from_extractor->CopyByteOrderedData(
+ 0, field_byte_width,
+ data_sp->GetBytes() + (field_bit_offset / 8), field_byte_width,
+ target_byte_order);
+ }
+
+ // The result is in our data buffer. Create a variable object out of
+ // it
+ return_valobj_sp = ValueObjectConstResult::Create(
+ &thread, return_compiler_type, ConstString(""), return_ext);
- // If we reach here, it means this structure either contains more than two fields or
- // it contains at least one non floating point type.
- // In that case, all fields are returned in GP return registers.
- for (uint32_t idx = 0; idx < num_children; idx++)
- {
- uint64_t field_bit_offset = 0;
- bool is_signed;
- uint32_t padding;
-
- CompilerType field_compiler_type = return_compiler_type.GetFieldAtIndex(idx, name, &field_bit_offset, nullptr, nullptr);
- const size_t field_byte_width = field_compiler_type.GetByteSize(nullptr);
-
- // if we don't know the size of the field (e.g. invalid type), just bail out
- if (field_byte_width == 0)
- break;
-
- uint32_t field_byte_offset = field_bit_offset/8;
-
- if (field_compiler_type.IsIntegerOrEnumerationType (is_signed)
- || field_compiler_type.IsPointerType ()
- || field_compiler_type.IsFloatingPointType (count, is_complex))
- {
- padding = field_byte_offset - integer_bytes;
-
- if (integer_bytes < 8)
- {
- // We have not yet consumed r2 completely.
- if (integer_bytes + field_byte_width + padding <= 8)
- {
- // This field fits in r2, copy its value from r2 to our result structure
- integer_bytes = integer_bytes + field_byte_width + padding; // Increase the consumed bytes.
- use_r2 = 1;
- }
- else
- {
- // There isn't enough space left in r2 for this field, so this will be in r3.
- integer_bytes = integer_bytes + field_byte_width + padding; // Increase the consumed bytes.
- use_r3 = 1;
- }
- }
- // We already have consumed at-least 8 bytes that means r2 is done, and this field will be in r3.
- // Check if this field can fit in r3.
- else if (integer_bytes + field_byte_width + padding <= 16)
- {
- integer_bytes = integer_bytes + field_byte_width + padding;
- use_r3 = 1;
- }
- else
- {
- // There isn't any space left for this field, this should not happen as we have already checked
- // the overall size is not greater than 16 bytes. For now, return a nullptr return value object.
- return return_valobj_sp;
- }
- }
- }
- // Vector types up to 16 bytes are returned in GP return registers
- if (type_flags & eTypeIsVector)
- {
- if (byte_size <= 8)
- use_r2 = 1;
- else
- {
- use_r2 = 1;
- use_r3 = 1;
- }
- }
+ return return_valobj_sp;
+ }
+ }
- if (use_r2)
- {
- reg_ctx->ReadRegister (r2_info, r2_value);
-
- const size_t bytes_copied = r2_value.GetAsMemoryData (r2_info,
- data_sp->GetBytes(),
- r2_info->byte_size,
- target_byte_order,
- error);
- if (bytes_copied != r2_info->byte_size)
- return return_valobj_sp;
- sucess = 1;
- }
- if (use_r3)
- {
- reg_ctx->ReadRegister (r3_info, r3_value);
- const size_t bytes_copied = r3_value.GetAsMemoryData (r3_info,
- data_sp->GetBytes() + r2_info->byte_size,
- r3_info->byte_size,
- target_byte_order,
- error);
-
- if (bytes_copied != r3_info->byte_size)
- return return_valobj_sp;
- sucess = 1;
- }
- if (sucess)
- {
- // The result is in our data buffer. Create a variable object out of it
- return_valobj_sp = ValueObjectConstResult::Create (&thread,
- return_compiler_type,
- ConstString(""),
- return_ext);
+ // If we reach here, it means this structure either contains more than two
+ // fields or
+ // it contains at least one non floating point type.
+ // In that case, all fields are returned in GP return registers.
+ for (uint32_t idx = 0; idx < num_children; idx++) {
+ uint64_t field_bit_offset = 0;
+ bool is_signed;
+ uint32_t padding;
+
+ CompilerType field_compiler_type = return_compiler_type.GetFieldAtIndex(
+ idx, name, &field_bit_offset, nullptr, nullptr);
+ const size_t field_byte_width =
+ field_compiler_type.GetByteSize(nullptr);
+
+ // if we don't know the size of the field (e.g. invalid type), just bail
+ // out
+ if (field_byte_width == 0)
+ break;
+
+ uint32_t field_byte_offset = field_bit_offset / 8;
+
+ if (field_compiler_type.IsIntegerOrEnumerationType(is_signed) ||
+ field_compiler_type.IsPointerType() ||
+ field_compiler_type.IsFloatingPointType(count, is_complex)) {
+ padding = field_byte_offset - integer_bytes;
+
+ if (integer_bytes < 8) {
+ // We have not yet consumed r2 completely.
+ if (integer_bytes + field_byte_width + padding <= 8) {
+ // This field fits in r2, copy its value from r2 to our result
+ // structure
+ integer_bytes = integer_bytes + field_byte_width +
+ padding; // Increase the consumed bytes.
+ use_r2 = 1;
+ } else {
+ // There isn't enough space left in r2 for this field, so this
+ // will be in r3.
+ integer_bytes = integer_bytes + field_byte_width +
+ padding; // Increase the consumed bytes.
+ use_r3 = 1;
}
+ }
+ // We already have consumed at-least 8 bytes that means r2 is done,
+ // and this field will be in r3.
+ // Check if this field can fit in r3.
+ else if (integer_bytes + field_byte_width + padding <= 16) {
+ integer_bytes = integer_bytes + field_byte_width + padding;
+ use_r3 = 1;
+ } else {
+ // There isn't any space left for this field, this should not happen
+ // as we have already checked
+ // the overall size is not greater than 16 bytes. For now, return a
+ // nullptr return value object.
return return_valobj_sp;
+ }
+ }
+ }
+ // Vector types up to 16 bytes are returned in GP return registers
+ if (type_flags & eTypeIsVector) {
+ if (byte_size <= 8)
+ use_r2 = 1;
+ else {
+ use_r2 = 1;
+ use_r3 = 1;
}
+ }
- // Any structure/vector greater than 16 bytes in size is returned in memory.
- // The pointer to that memory is returned in r2.
- uint64_t mem_address = reg_ctx->ReadRegisterAsUnsigned(reg_ctx->GetRegisterInfoByName("r2", 0), 0);
-
- // We have got the address. Create a memory object out of it
- return_valobj_sp = ValueObjectMemory::Create(&thread,
- "",
- Address(mem_address, nullptr),
- return_compiler_type);
+ if (use_r2) {
+ reg_ctx->ReadRegister(r2_info, r2_value);
+
+ const size_t bytes_copied = r2_value.GetAsMemoryData(
+ r2_info, data_sp->GetBytes(), r2_info->byte_size, target_byte_order,
+ error);
+ if (bytes_copied != r2_info->byte_size)
+ return return_valobj_sp;
+ sucess = 1;
+ }
+ if (use_r3) {
+ reg_ctx->ReadRegister(r3_info, r3_value);
+ const size_t bytes_copied = r3_value.GetAsMemoryData(
+ r3_info, data_sp->GetBytes() + r2_info->byte_size,
+ r3_info->byte_size, target_byte_order, error);
+
+ if (bytes_copied != r3_info->byte_size)
+ return return_valobj_sp;
+ sucess = 1;
+ }
+ if (sucess) {
+ // The result is in our data buffer. Create a variable object out of it
+ return_valobj_sp = ValueObjectConstResult::Create(
+ &thread, return_compiler_type, ConstString(""), return_ext);
+ }
+ return return_valobj_sp;
}
- return return_valobj_sp;
+
+ // Any structure/vector greater than 16 bytes in size is returned in memory.
+ // The pointer to that memory is returned in r2.
+ uint64_t mem_address = reg_ctx->ReadRegisterAsUnsigned(
+ reg_ctx->GetRegisterInfoByName("r2", 0), 0);
+
+ // We have got the address. Create a memory object out of it
+ return_valobj_sp = ValueObjectMemory::Create(
+ &thread, "", Address(mem_address, nullptr), return_compiler_type);
+ }
+ return return_valobj_sp;
}
-bool
-ABISysV_mips64::CreateFunctionEntryUnwindPlan (UnwindPlan &unwind_plan)
-{
- unwind_plan.Clear();
- unwind_plan.SetRegisterKind (eRegisterKindDWARF);
+bool ABISysV_mips64::CreateFunctionEntryUnwindPlan(UnwindPlan &unwind_plan) {
+ unwind_plan.Clear();
+ unwind_plan.SetRegisterKind(eRegisterKindDWARF);
- UnwindPlan::RowSP row(new UnwindPlan::Row);
+ UnwindPlan::RowSP row(new UnwindPlan::Row);
- // Our Call Frame Address is the stack pointer value
- row->GetCFAValue().SetIsRegisterPlusOffset(dwarf_r29, 0);
+ // Our Call Frame Address is the stack pointer value
+ row->GetCFAValue().SetIsRegisterPlusOffset(dwarf_r29, 0);
- // The previous PC is in the RA
- row->SetRegisterLocationToRegister(dwarf_pc, dwarf_r31, true);
- unwind_plan.AppendRow (row);
+ // The previous PC is in the RA
+ row->SetRegisterLocationToRegister(dwarf_pc, dwarf_r31, true);
+ unwind_plan.AppendRow(row);
- // All other registers are the same.
+ // All other registers are the same.
- unwind_plan.SetSourceName ("mips64 at-func-entry default");
- unwind_plan.SetSourcedFromCompiler (eLazyBoolNo);
- unwind_plan.SetReturnAddressRegister(dwarf_r31);
- return true;
+ unwind_plan.SetSourceName("mips64 at-func-entry default");
+ unwind_plan.SetSourcedFromCompiler(eLazyBoolNo);
+ unwind_plan.SetReturnAddressRegister(dwarf_r31);
+ return true;
}
-bool
-ABISysV_mips64::CreateDefaultUnwindPlan (UnwindPlan &unwind_plan)
-{
- unwind_plan.Clear();
- unwind_plan.SetRegisterKind (eRegisterKindDWARF);
+bool ABISysV_mips64::CreateDefaultUnwindPlan(UnwindPlan &unwind_plan) {
+ unwind_plan.Clear();
+ unwind_plan.SetRegisterKind(eRegisterKindDWARF);
- UnwindPlan::RowSP row(new UnwindPlan::Row);
+ UnwindPlan::RowSP row(new UnwindPlan::Row);
- row->GetCFAValue().SetIsRegisterPlusOffset(dwarf_r29, 0);
+ row->GetCFAValue().SetIsRegisterPlusOffset(dwarf_r29, 0);
- row->SetRegisterLocationToRegister(dwarf_pc, dwarf_r31, true);
+ row->SetRegisterLocationToRegister(dwarf_pc, dwarf_r31, true);
- unwind_plan.AppendRow (row);
- unwind_plan.SetSourceName ("mips64 default unwind plan");
- unwind_plan.SetSourcedFromCompiler (eLazyBoolNo);
- unwind_plan.SetUnwindPlanValidAtAllInstructions (eLazyBoolNo);
- return true;
+ unwind_plan.AppendRow(row);
+ unwind_plan.SetSourceName("mips64 default unwind plan");
+ unwind_plan.SetSourcedFromCompiler(eLazyBoolNo);
+ unwind_plan.SetUnwindPlanValidAtAllInstructions(eLazyBoolNo);
+ return true;
}
-bool
-ABISysV_mips64::RegisterIsVolatile (const RegisterInfo *reg_info)
-{
- return !RegisterIsCalleeSaved (reg_info);
+bool ABISysV_mips64::RegisterIsVolatile(const RegisterInfo *reg_info) {
+ return !RegisterIsCalleeSaved(reg_info);
}
-bool
-ABISysV_mips64::IsSoftFloat (uint32_t fp_flag) const
-{
- return (fp_flag == lldb_private::ArchSpec::eMIPS_ABI_FP_SOFT);
+bool ABISysV_mips64::IsSoftFloat(uint32_t fp_flag) const {
+ return (fp_flag == lldb_private::ArchSpec::eMIPS_ABI_FP_SOFT);
}
-bool
-ABISysV_mips64::RegisterIsCalleeSaved (const RegisterInfo *reg_info)
-{
- if (reg_info)
- {
- // Preserved registers are :
- // r16-r23, r28, r29, r30, r31
-
- int reg = ((reg_info->byte_offset) / 8);
+bool ABISysV_mips64::RegisterIsCalleeSaved(const RegisterInfo *reg_info) {
+ if (reg_info) {
+ // Preserved registers are :
+ // r16-r23, r28, r29, r30, r31
+
+ int reg = ((reg_info->byte_offset) / 8);
+
+ bool save = (reg >= 16) && (reg <= 23);
+ save |= (reg >= 28) && (reg <= 31);
+
+ return save;
+ }
+ return false;
+}
- bool save = (reg >= 16) && (reg <= 23);
- save |= (reg >= 28) && (reg <= 31);
+void ABISysV_mips64::Initialize() {
+ PluginManager::RegisterPlugin(
+ GetPluginNameStatic(), "System V ABI for mips64 targets", CreateInstance);
+}
- return save;
- }
- return false;
+void ABISysV_mips64::Terminate() {
+ PluginManager::UnregisterPlugin(CreateInstance);
}
-void
-ABISysV_mips64::Initialize()
-{
- PluginManager::RegisterPlugin (GetPluginNameStatic(),
- "System V ABI for mips64 targets",
- CreateInstance);
-}
-
-void
-ABISysV_mips64::Terminate()
-{
- PluginManager::UnregisterPlugin (CreateInstance);
-}
-
-lldb_private::ConstString
-ABISysV_mips64::GetPluginNameStatic()
-{
- static ConstString g_name("sysv-mips64");
- return g_name;
+lldb_private::ConstString ABISysV_mips64::GetPluginNameStatic() {
+ static ConstString g_name("sysv-mips64");
+ return g_name;
}
//------------------------------------------------------------------
// PluginInterface protocol
//------------------------------------------------------------------
-lldb_private::ConstString
-ABISysV_mips64::GetPluginName()
-{
- return GetPluginNameStatic();
+lldb_private::ConstString ABISysV_mips64::GetPluginName() {
+ return GetPluginNameStatic();
}
-uint32_t
-ABISysV_mips64::GetPluginVersion()
-{
- return 1;
-}
+uint32_t ABISysV_mips64::GetPluginVersion() { return 1; }
Modified: lldb/trunk/source/Plugins/ABI/SysV-mips64/ABISysV_mips64.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ABI/SysV-mips64/ABISysV_mips64.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ABI/SysV-mips64/ABISysV_mips64.h (original)
+++ lldb/trunk/source/Plugins/ABI/SysV-mips64/ABISysV_mips64.h Tue Sep 6 15:57:50 2016
@@ -14,125 +14,104 @@
// C++ Includes
// Other libraries and framework includes
// Project includes
-#include "lldb/lldb-private.h"
#include "lldb/Target/ABI.h"
+#include "lldb/lldb-private.h"
-class ABISysV_mips64 :
- public lldb_private::ABI
-{
+class ABISysV_mips64 : public lldb_private::ABI {
public:
- ~ABISysV_mips64() override = default;
+ ~ABISysV_mips64() override = default;
+
+ size_t GetRedZoneSize() const override;
+
+ bool PrepareTrivialCall(lldb_private::Thread &thread, lldb::addr_t sp,
+ lldb::addr_t functionAddress,
+ lldb::addr_t returnAddress,
+ llvm::ArrayRef<lldb::addr_t> args) const override;
+
+ bool GetArgumentValues(lldb_private::Thread &thread,
+ lldb_private::ValueList &values) const override;
+
+ lldb_private::Error
+ SetReturnValueObject(lldb::StackFrameSP &frame_sp,
+ lldb::ValueObjectSP &new_value) override;
+
+ lldb::ValueObjectSP
+ GetReturnValueObjectImpl(lldb_private::Thread &thread,
+ lldb_private::CompilerType &type) const override;
+
+ bool
+ CreateFunctionEntryUnwindPlan(lldb_private::UnwindPlan &unwind_plan) override;
+
+ bool CreateDefaultUnwindPlan(lldb_private::UnwindPlan &unwind_plan) override;
+
+ bool RegisterIsVolatile(const lldb_private::RegisterInfo *reg_info) override;
+
+ bool IsSoftFloat(uint32_t fp_flag) const;
+
+ // The SysV mips ABI requires that stack frames be 16 byte aligned.
+ // When there is a trap handler on the stack, e.g. _sigtramp in userland
+ // code, we've seen that the stack pointer is often not aligned properly
+ // before the handler is invoked. This means that lldb will stop the unwind
+ // early -- before the function which caused the trap.
+ //
+ // To work around this, we relax that alignment to be just word-size
+ // (8-bytes).
+ // Whitelisting the trap handlers for user space would be easy (_sigtramp) but
+ // in other environments there can be a large number of different functions
+ // involved in async traps.
+ bool CallFrameAddressIsValid(lldb::addr_t cfa) override {
+ // Make sure the stack call frame addresses are 8 byte aligned
+ if (cfa & (8ull - 1ull))
+ return false; // Not 8 byte aligned
+ if (cfa == 0)
+ return false; // Zero is not a valid stack address
+ return true;
+ }
+
+ bool CodeAddressIsValid(lldb::addr_t pc) override {
+ if (pc & (4ull - 1ull))
+ return false; // Not 4 byte aligned
+
+ // Anything else if fair game..
+ return true;
+ }
+
+ const lldb_private::RegisterInfo *
+ GetRegisterInfoArray(uint32_t &count) override;
+
+ //------------------------------------------------------------------
+ // Static Functions
+ //------------------------------------------------------------------
+
+ static void Initialize();
+
+ static void Terminate();
+
+ static lldb::ABISP CreateInstance(const lldb_private::ArchSpec &arch);
- size_t
- GetRedZoneSize() const override;
+ static lldb_private::ConstString GetPluginNameStatic();
- bool
- PrepareTrivialCall(lldb_private::Thread &thread,
- lldb::addr_t sp,
- lldb::addr_t functionAddress,
- lldb::addr_t returnAddress,
- llvm::ArrayRef<lldb::addr_t> args) const override;
-
- bool
- GetArgumentValues(lldb_private::Thread &thread,
- lldb_private::ValueList &values) const override;
-
- lldb_private::Error
- SetReturnValueObject(lldb::StackFrameSP &frame_sp, lldb::ValueObjectSP &new_value) override;
-
- lldb::ValueObjectSP
- GetReturnValueObjectImpl(lldb_private::Thread &thread,
- lldb_private::CompilerType &type) const override;
-
- bool
- CreateFunctionEntryUnwindPlan(lldb_private::UnwindPlan &unwind_plan) override;
-
- bool
- CreateDefaultUnwindPlan(lldb_private::UnwindPlan &unwind_plan) override;
-
- bool
- RegisterIsVolatile(const lldb_private::RegisterInfo *reg_info) override;
-
- bool
- IsSoftFloat(uint32_t fp_flag) const;
-
- // The SysV mips ABI requires that stack frames be 16 byte aligned.
- // When there is a trap handler on the stack, e.g. _sigtramp in userland
- // code, we've seen that the stack pointer is often not aligned properly
- // before the handler is invoked. This means that lldb will stop the unwind
- // early -- before the function which caused the trap.
- //
- // To work around this, we relax that alignment to be just word-size (8-bytes).
- // Whitelisting the trap handlers for user space would be easy (_sigtramp) but
- // in other environments there can be a large number of different functions
- // involved in async traps.
- bool
- CallFrameAddressIsValid(lldb::addr_t cfa) override
- {
- // Make sure the stack call frame addresses are 8 byte aligned
- if (cfa & (8ull - 1ull))
- return false; // Not 8 byte aligned
- if (cfa == 0)
- return false; // Zero is not a valid stack address
- return true;
- }
-
- bool
- CodeAddressIsValid(lldb::addr_t pc) override
- {
- if (pc & (4ull - 1ull))
- return false; // Not 4 byte aligned
-
- // Anything else if fair game..
- return true;
- }
-
- const lldb_private::RegisterInfo *
- GetRegisterInfoArray(uint32_t &count) override;
-
- //------------------------------------------------------------------
- // Static Functions
- //------------------------------------------------------------------
-
- static void
- Initialize();
-
- static void
- Terminate();
-
- static lldb::ABISP
- CreateInstance (const lldb_private::ArchSpec &arch);
-
- static lldb_private::ConstString
- GetPluginNameStatic();
-
- //------------------------------------------------------------------
- // PluginInterface protocol
- //------------------------------------------------------------------
+ //------------------------------------------------------------------
+ // PluginInterface protocol
+ //------------------------------------------------------------------
- lldb_private::ConstString
- GetPluginName() override;
+ lldb_private::ConstString GetPluginName() override;
- uint32_t
- GetPluginVersion() override;
+ uint32_t GetPluginVersion() override;
protected:
- void
- CreateRegisterMapIfNeeded ();
+ void CreateRegisterMapIfNeeded();
- lldb::ValueObjectSP
- GetReturnValueObjectSimple(lldb_private::Thread &thread,
- lldb_private::CompilerType &ast_type) const;
+ lldb::ValueObjectSP
+ GetReturnValueObjectSimple(lldb_private::Thread &thread,
+ lldb_private::CompilerType &ast_type) const;
- bool
- RegisterIsCalleeSaved (const lldb_private::RegisterInfo *reg_info);
+ bool RegisterIsCalleeSaved(const lldb_private::RegisterInfo *reg_info);
private:
- ABISysV_mips64() :
- lldb_private::ABI()
- {
- // Call CreateInstance instead.
- }
+ ABISysV_mips64() : lldb_private::ABI() {
+ // Call CreateInstance instead.
+ }
};
#endif // liblldb_ABISysV_mips64_h_
Modified: lldb/trunk/source/Plugins/ABI/SysV-ppc/ABISysV_ppc.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ABI/SysV-ppc/ABISysV_ppc.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ABI/SysV-ppc/ABISysV_ppc.cpp (original)
+++ lldb/trunk/source/Plugins/ABI/SysV-ppc/ABISysV_ppc.cpp Tue Sep 6 15:57:50 2016
@@ -25,231 +25,271 @@
#include "lldb/Core/RegisterValue.h"
#include "lldb/Core/Value.h"
#include "lldb/Core/ValueObjectConstResult.h"
-#include "lldb/Core/ValueObjectRegister.h"
#include "lldb/Core/ValueObjectMemory.h"
+#include "lldb/Core/ValueObjectRegister.h"
#include "lldb/Symbol/UnwindPlan.h"
-#include "lldb/Target/Target.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/RegisterContext.h"
#include "lldb/Target/StackFrame.h"
+#include "lldb/Target/Target.h"
#include "lldb/Target/Thread.h"
using namespace lldb;
using namespace lldb_private;
-enum dwarf_regnums
-{
- dwarf_r0 = 0,
- dwarf_r1,
- dwarf_r2,
- dwarf_r3,
- dwarf_r4,
- dwarf_r5,
- dwarf_r6,
- dwarf_r7,
- dwarf_r8,
- dwarf_r9,
- dwarf_r10,
- dwarf_r11,
- dwarf_r12,
- dwarf_r13,
- dwarf_r14,
- dwarf_r15,
- dwarf_r16,
- dwarf_r17,
- dwarf_r18,
- dwarf_r19,
- dwarf_r20,
- dwarf_r21,
- dwarf_r22,
- dwarf_r23,
- dwarf_r24,
- dwarf_r25,
- dwarf_r26,
- dwarf_r27,
- dwarf_r28,
- dwarf_r29,
- dwarf_r30,
- dwarf_r31,
- dwarf_f0,
- dwarf_f1,
- dwarf_f2,
- dwarf_f3,
- dwarf_f4,
- dwarf_f5,
- dwarf_f6,
- dwarf_f7,
- dwarf_f8,
- dwarf_f9,
- dwarf_f10,
- dwarf_f11,
- dwarf_f12,
- dwarf_f13,
- dwarf_f14,
- dwarf_f15,
- dwarf_f16,
- dwarf_f17,
- dwarf_f18,
- dwarf_f19,
- dwarf_f20,
- dwarf_f21,
- dwarf_f22,
- dwarf_f23,
- dwarf_f24,
- dwarf_f25,
- dwarf_f26,
- dwarf_f27,
- dwarf_f28,
- dwarf_f29,
- dwarf_f30,
- dwarf_f31,
- dwarf_cr,
- dwarf_fpscr,
- dwarf_xer = 101,
- dwarf_lr = 108,
- dwarf_ctr,
- dwarf_pc,
- dwarf_cfa,
+enum dwarf_regnums {
+ dwarf_r0 = 0,
+ dwarf_r1,
+ dwarf_r2,
+ dwarf_r3,
+ dwarf_r4,
+ dwarf_r5,
+ dwarf_r6,
+ dwarf_r7,
+ dwarf_r8,
+ dwarf_r9,
+ dwarf_r10,
+ dwarf_r11,
+ dwarf_r12,
+ dwarf_r13,
+ dwarf_r14,
+ dwarf_r15,
+ dwarf_r16,
+ dwarf_r17,
+ dwarf_r18,
+ dwarf_r19,
+ dwarf_r20,
+ dwarf_r21,
+ dwarf_r22,
+ dwarf_r23,
+ dwarf_r24,
+ dwarf_r25,
+ dwarf_r26,
+ dwarf_r27,
+ dwarf_r28,
+ dwarf_r29,
+ dwarf_r30,
+ dwarf_r31,
+ dwarf_f0,
+ dwarf_f1,
+ dwarf_f2,
+ dwarf_f3,
+ dwarf_f4,
+ dwarf_f5,
+ dwarf_f6,
+ dwarf_f7,
+ dwarf_f8,
+ dwarf_f9,
+ dwarf_f10,
+ dwarf_f11,
+ dwarf_f12,
+ dwarf_f13,
+ dwarf_f14,
+ dwarf_f15,
+ dwarf_f16,
+ dwarf_f17,
+ dwarf_f18,
+ dwarf_f19,
+ dwarf_f20,
+ dwarf_f21,
+ dwarf_f22,
+ dwarf_f23,
+ dwarf_f24,
+ dwarf_f25,
+ dwarf_f26,
+ dwarf_f27,
+ dwarf_f28,
+ dwarf_f29,
+ dwarf_f30,
+ dwarf_f31,
+ dwarf_cr,
+ dwarf_fpscr,
+ dwarf_xer = 101,
+ dwarf_lr = 108,
+ dwarf_ctr,
+ dwarf_pc,
+ dwarf_cfa,
};
// Note that the size and offset will be updated by platform-specific classes.
-#define DEFINE_GPR(reg, alt, kind1, kind2, kind3, kind4) \
- { #reg, alt, 8, 0, eEncodingUint, \
- eFormatHex, { kind1, kind2, kind3, kind4}, nullptr, nullptr, nullptr, 0 }
-
-static const RegisterInfo
-g_register_infos[] =
-{
- // General purpose registers. eh_frame, DWARF, Generic, Process Plugin
- DEFINE_GPR(r0, nullptr, dwarf_r0, dwarf_r0, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r1, "sp", dwarf_r1, dwarf_r1, LLDB_REGNUM_GENERIC_SP, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r2, nullptr, dwarf_r2, dwarf_r2, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r3, "arg1", dwarf_r3, dwarf_r3, LLDB_REGNUM_GENERIC_ARG1, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r4, "arg2", dwarf_r4, dwarf_r4, LLDB_REGNUM_GENERIC_ARG2 ,LLDB_INVALID_REGNUM),
- DEFINE_GPR(r5, "arg3", dwarf_r5, dwarf_r5, LLDB_REGNUM_GENERIC_ARG3, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r6, "arg4", dwarf_r6, dwarf_r6, LLDB_REGNUM_GENERIC_ARG4, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r7, "arg5", dwarf_r7, dwarf_r7, LLDB_REGNUM_GENERIC_ARG5, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r8, "arg6", dwarf_r8, dwarf_r8, LLDB_REGNUM_GENERIC_ARG6, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r9, "arg7", dwarf_r9, dwarf_r9, LLDB_REGNUM_GENERIC_ARG7, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r10, "arg8", dwarf_r10, dwarf_r10, LLDB_REGNUM_GENERIC_ARG8, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r11, nullptr, dwarf_r11, dwarf_r11, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r12, nullptr, dwarf_r12, dwarf_r12, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r13, nullptr, dwarf_r13, dwarf_r13, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r14, nullptr, dwarf_r14, dwarf_r14, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r15, nullptr, dwarf_r15, dwarf_r15, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r16, nullptr, dwarf_r16, dwarf_r16, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r17, nullptr, dwarf_r17, dwarf_r17, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r18, nullptr, dwarf_r18, dwarf_r18, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r19, nullptr, dwarf_r19, dwarf_r19, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r20, nullptr, dwarf_r20, dwarf_r20, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r21, nullptr, dwarf_r21, dwarf_r21, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r22, nullptr, dwarf_r22, dwarf_r22, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r23, nullptr, dwarf_r23, dwarf_r23, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r24, nullptr, dwarf_r24, dwarf_r24, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r25, nullptr, dwarf_r25, dwarf_r25, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r26, nullptr, dwarf_r26, dwarf_r26, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r27, nullptr, dwarf_r27, dwarf_r27, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r28, nullptr, dwarf_r28, dwarf_r28, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r29, nullptr, dwarf_r29, dwarf_r29, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r30, nullptr, dwarf_r30, dwarf_r30, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r31, nullptr, dwarf_r31, dwarf_r31, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(lr, "lr", dwarf_lr, dwarf_lr, LLDB_REGNUM_GENERIC_RA, LLDB_INVALID_REGNUM),
- DEFINE_GPR(cr, "cr", dwarf_cr, dwarf_cr, LLDB_REGNUM_GENERIC_FLAGS, LLDB_INVALID_REGNUM),
- DEFINE_GPR(xer, "xer", dwarf_xer, dwarf_xer, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(ctr, "ctr", dwarf_ctr, dwarf_ctr, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(pc, "pc", dwarf_pc, dwarf_pc, LLDB_REGNUM_GENERIC_PC, LLDB_INVALID_REGNUM),
- { nullptr, nullptr, 8, 0, eEncodingUint, eFormatHex, { dwarf_cfa, dwarf_cfa, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM}, nullptr, nullptr, nullptr, 0 }
-};
+#define DEFINE_GPR(reg, alt, kind1, kind2, kind3, kind4) \
+ { \
+ #reg, alt, 8, 0, eEncodingUint, eFormatHex, {kind1, kind2, kind3, kind4 }, \
+ nullptr, nullptr, nullptr, 0 \
+ }
+
+static const RegisterInfo g_register_infos[] = {
+ // General purpose registers. eh_frame, DWARF,
+ // Generic, Process Plugin
+ DEFINE_GPR(r0, nullptr, dwarf_r0, dwarf_r0, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r1, "sp", dwarf_r1, dwarf_r1, LLDB_REGNUM_GENERIC_SP,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r2, nullptr, dwarf_r2, dwarf_r2, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r3, "arg1", dwarf_r3, dwarf_r3, LLDB_REGNUM_GENERIC_ARG1,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r4, "arg2", dwarf_r4, dwarf_r4, LLDB_REGNUM_GENERIC_ARG2,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r5, "arg3", dwarf_r5, dwarf_r5, LLDB_REGNUM_GENERIC_ARG3,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r6, "arg4", dwarf_r6, dwarf_r6, LLDB_REGNUM_GENERIC_ARG4,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r7, "arg5", dwarf_r7, dwarf_r7, LLDB_REGNUM_GENERIC_ARG5,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r8, "arg6", dwarf_r8, dwarf_r8, LLDB_REGNUM_GENERIC_ARG6,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r9, "arg7", dwarf_r9, dwarf_r9, LLDB_REGNUM_GENERIC_ARG7,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r10, "arg8", dwarf_r10, dwarf_r10, LLDB_REGNUM_GENERIC_ARG8,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r11, nullptr, dwarf_r11, dwarf_r11, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r12, nullptr, dwarf_r12, dwarf_r12, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r13, nullptr, dwarf_r13, dwarf_r13, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r14, nullptr, dwarf_r14, dwarf_r14, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r15, nullptr, dwarf_r15, dwarf_r15, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r16, nullptr, dwarf_r16, dwarf_r16, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r17, nullptr, dwarf_r17, dwarf_r17, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r18, nullptr, dwarf_r18, dwarf_r18, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r19, nullptr, dwarf_r19, dwarf_r19, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r20, nullptr, dwarf_r20, dwarf_r20, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r21, nullptr, dwarf_r21, dwarf_r21, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r22, nullptr, dwarf_r22, dwarf_r22, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r23, nullptr, dwarf_r23, dwarf_r23, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r24, nullptr, dwarf_r24, dwarf_r24, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r25, nullptr, dwarf_r25, dwarf_r25, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r26, nullptr, dwarf_r26, dwarf_r26, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r27, nullptr, dwarf_r27, dwarf_r27, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r28, nullptr, dwarf_r28, dwarf_r28, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r29, nullptr, dwarf_r29, dwarf_r29, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r30, nullptr, dwarf_r30, dwarf_r30, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r31, nullptr, dwarf_r31, dwarf_r31, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(lr, "lr", dwarf_lr, dwarf_lr, LLDB_REGNUM_GENERIC_RA,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(cr, "cr", dwarf_cr, dwarf_cr, LLDB_REGNUM_GENERIC_FLAGS,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(xer, "xer", dwarf_xer, dwarf_xer, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(ctr, "ctr", dwarf_ctr, dwarf_ctr, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(pc, "pc", dwarf_pc, dwarf_pc, LLDB_REGNUM_GENERIC_PC,
+ LLDB_INVALID_REGNUM),
+ {nullptr,
+ nullptr,
+ 8,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_cfa, dwarf_cfa, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0}};
-static const uint32_t k_num_register_infos = llvm::array_lengthof(g_register_infos);
+static const uint32_t k_num_register_infos =
+ llvm::array_lengthof(g_register_infos);
const lldb_private::RegisterInfo *
-ABISysV_ppc::GetRegisterInfoArray (uint32_t &count)
-{
- count = k_num_register_infos;
- return g_register_infos;
+ABISysV_ppc::GetRegisterInfoArray(uint32_t &count) {
+ count = k_num_register_infos;
+ return g_register_infos;
}
-size_t
-ABISysV_ppc::GetRedZoneSize () const
-{
- return 224;
-}
+size_t ABISysV_ppc::GetRedZoneSize() const { return 224; }
//------------------------------------------------------------------
// Static Functions
//------------------------------------------------------------------
ABISP
-ABISysV_ppc::CreateInstance (const ArchSpec &arch)
-{
- static ABISP g_abi_sp;
- if (arch.GetTriple().getArch() == llvm::Triple::ppc)
- {
- if (!g_abi_sp)
- g_abi_sp.reset (new ABISysV_ppc);
- return g_abi_sp;
- }
- return ABISP();
-}
-
-bool
-ABISysV_ppc::PrepareTrivialCall (Thread &thread,
- addr_t sp,
- addr_t func_addr,
- addr_t return_addr,
- llvm::ArrayRef<addr_t> args) const
-{
- Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
-
- if (log)
- {
- StreamString s;
- s.Printf("ABISysV_ppc::PrepareTrivialCall (tid = 0x%" PRIx64 ", sp = 0x%" PRIx64 ", func_addr = 0x%" PRIx64 ", return_addr = 0x%" PRIx64,
- thread.GetID(),
- (uint64_t)sp,
- (uint64_t)func_addr,
- (uint64_t)return_addr);
-
- for (size_t i = 0; i < args.size(); ++i)
- s.Printf (", arg%" PRIu64 " = 0x%" PRIx64, static_cast<uint64_t>(i + 1), args[i]);
- s.PutCString (")");
- log->PutCString(s.GetString().c_str());
- }
-
- RegisterContext *reg_ctx = thread.GetRegisterContext().get();
- if (!reg_ctx)
- return false;
-
- const RegisterInfo *reg_info = nullptr;
-
- if (args.size() > 8) // TODO handle more than 8 arguments
- return false;
+ABISysV_ppc::CreateInstance(const ArchSpec &arch) {
+ static ABISP g_abi_sp;
+ if (arch.GetTriple().getArch() == llvm::Triple::ppc) {
+ if (!g_abi_sp)
+ g_abi_sp.reset(new ABISysV_ppc);
+ return g_abi_sp;
+ }
+ return ABISP();
+}
+
+bool ABISysV_ppc::PrepareTrivialCall(Thread &thread, addr_t sp,
+ addr_t func_addr, addr_t return_addr,
+ llvm::ArrayRef<addr_t> args) const {
+ Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
+
+ if (log) {
+ StreamString s;
+ s.Printf("ABISysV_ppc::PrepareTrivialCall (tid = 0x%" PRIx64
+ ", sp = 0x%" PRIx64 ", func_addr = 0x%" PRIx64
+ ", return_addr = 0x%" PRIx64,
+ thread.GetID(), (uint64_t)sp, (uint64_t)func_addr,
+ (uint64_t)return_addr);
for (size_t i = 0; i < args.size(); ++i)
- {
- reg_info = reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG1 + i);
- if (log)
- log->Printf("About to write arg%" PRIu64 " (0x%" PRIx64 ") into %s", static_cast<uint64_t>(i + 1), args[i], reg_info->name);
- if (!reg_ctx->WriteRegisterFromUnsigned(reg_info, args[i]))
- return false;
- }
+ s.Printf(", arg%" PRIu64 " = 0x%" PRIx64, static_cast<uint64_t>(i + 1),
+ args[i]);
+ s.PutCString(")");
+ log->PutCString(s.GetString().c_str());
+ }
- // First, align the SP
-
- if (log)
- log->Printf("16-byte aligning SP: 0x%" PRIx64 " to 0x%" PRIx64, (uint64_t)sp, (uint64_t)(sp & ~0xfull));
+ RegisterContext *reg_ctx = thread.GetRegisterContext().get();
+ if (!reg_ctx)
+ return false;
- sp &= ~(0xfull); // 16-byte alignment
+ const RegisterInfo *reg_info = nullptr;
- sp -= 8;
+ if (args.size() > 8) // TODO handle more than 8 arguments
+ return false;
- Error error;
- const RegisterInfo *pc_reg_info = reg_ctx->GetRegisterInfo (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_PC);
- const RegisterInfo *sp_reg_info = reg_ctx->GetRegisterInfo (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_SP);
- ProcessSP process_sp (thread.GetProcess());
+ for (size_t i = 0; i < args.size(); ++i) {
+ reg_info = reg_ctx->GetRegisterInfo(eRegisterKindGeneric,
+ LLDB_REGNUM_GENERIC_ARG1 + i);
+ if (log)
+ log->Printf("About to write arg%" PRIu64 " (0x%" PRIx64 ") into %s",
+ static_cast<uint64_t>(i + 1), args[i], reg_info->name);
+ if (!reg_ctx->WriteRegisterFromUnsigned(reg_info, args[i]))
+ return false;
+ }
+
+ // First, align the SP
+
+ if (log)
+ log->Printf("16-byte aligning SP: 0x%" PRIx64 " to 0x%" PRIx64,
+ (uint64_t)sp, (uint64_t)(sp & ~0xfull));
+
+ sp &= ~(0xfull); // 16-byte alignment
+
+ sp -= 8;
+
+ Error error;
+ const RegisterInfo *pc_reg_info =
+ reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_PC);
+ const RegisterInfo *sp_reg_info =
+ reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_SP);
+ ProcessSP process_sp(thread.GetProcess());
- RegisterValue reg_value;
+ RegisterValue reg_value;
#if 0
// This code adds an extra frame so that we don't lose the function that we came from
@@ -292,775 +332,692 @@ ABISysV_ppc::PrepareTrivialCall (Thread
}
#endif
- if (log)
- log->Printf("Pushing the return address onto the stack: 0x%" PRIx64 ": 0x%" PRIx64, (uint64_t)sp, (uint64_t)return_addr);
+ if (log)
+ log->Printf("Pushing the return address onto the stack: 0x%" PRIx64
+ ": 0x%" PRIx64,
+ (uint64_t)sp, (uint64_t)return_addr);
- // Save return address onto the stack
- if (!process_sp->WritePointerToMemory(sp, return_addr, error))
- return false;
+ // Save return address onto the stack
+ if (!process_sp->WritePointerToMemory(sp, return_addr, error))
+ return false;
- // %r1 is set to the actual stack value.
+ // %r1 is set to the actual stack value.
- if (log)
- log->Printf("Writing SP: 0x%" PRIx64, (uint64_t)sp);
+ if (log)
+ log->Printf("Writing SP: 0x%" PRIx64, (uint64_t)sp);
- if (!reg_ctx->WriteRegisterFromUnsigned (sp_reg_info, sp))
- return false;
+ if (!reg_ctx->WriteRegisterFromUnsigned(sp_reg_info, sp))
+ return false;
- // %pc is set to the address of the called function.
+ // %pc is set to the address of the called function.
- if (log)
- log->Printf("Writing IP: 0x%" PRIx64, (uint64_t)func_addr);
+ if (log)
+ log->Printf("Writing IP: 0x%" PRIx64, (uint64_t)func_addr);
- if (!reg_ctx->WriteRegisterFromUnsigned (pc_reg_info, func_addr))
- return false;
+ if (!reg_ctx->WriteRegisterFromUnsigned(pc_reg_info, func_addr))
+ return false;
- return true;
+ return true;
}
-static bool ReadIntegerArgument(Scalar &scalar,
- unsigned int bit_width,
- bool is_signed,
- Thread &thread,
- uint32_t *argument_register_ids,
- unsigned int ¤t_argument_register,
- addr_t ¤t_stack_argument)
-{
- if (bit_width > 64)
- return false; // Scalar can't hold large integer arguments
-
- if (current_argument_register < 6)
- {
- scalar = thread.GetRegisterContext()->ReadRegisterAsUnsigned(argument_register_ids[current_argument_register], 0);
- current_argument_register++;
- if (is_signed)
- scalar.SignExtend (bit_width);
- }
- else
- {
- uint32_t byte_size = (bit_width + (8-1))/8;
- Error error;
- if (thread.GetProcess()->ReadScalarIntegerFromMemory(current_stack_argument, byte_size, is_signed, scalar, error))
- {
- current_stack_argument += byte_size;
- return true;
- }
- return false;
+static bool ReadIntegerArgument(Scalar &scalar, unsigned int bit_width,
+ bool is_signed, Thread &thread,
+ uint32_t *argument_register_ids,
+ unsigned int ¤t_argument_register,
+ addr_t ¤t_stack_argument) {
+ if (bit_width > 64)
+ return false; // Scalar can't hold large integer arguments
+
+ if (current_argument_register < 6) {
+ scalar = thread.GetRegisterContext()->ReadRegisterAsUnsigned(
+ argument_register_ids[current_argument_register], 0);
+ current_argument_register++;
+ if (is_signed)
+ scalar.SignExtend(bit_width);
+ } else {
+ uint32_t byte_size = (bit_width + (8 - 1)) / 8;
+ Error error;
+ if (thread.GetProcess()->ReadScalarIntegerFromMemory(
+ current_stack_argument, byte_size, is_signed, scalar, error)) {
+ current_stack_argument += byte_size;
+ return true;
}
- return true;
+ return false;
+ }
+ return true;
}
-bool
-ABISysV_ppc::GetArgumentValues (Thread &thread,
- ValueList &values) const
-{
- unsigned int num_values = values.GetSize();
- unsigned int value_index;
-
- // Extract the register context so we can read arguments from registers
-
- RegisterContext *reg_ctx = thread.GetRegisterContext().get();
-
- if (!reg_ctx)
- return false;
-
- // Get the pointer to the first stack argument so we have a place to start
- // when reading data
+bool ABISysV_ppc::GetArgumentValues(Thread &thread, ValueList &values) const {
+ unsigned int num_values = values.GetSize();
+ unsigned int value_index;
- addr_t sp = reg_ctx->GetSP(0);
+ // Extract the register context so we can read arguments from registers
- if (!sp)
- return false;
+ RegisterContext *reg_ctx = thread.GetRegisterContext().get();
- addr_t current_stack_argument = sp + 48; // jump over return address
-
- uint32_t argument_register_ids[8];
-
- argument_register_ids[0] = reg_ctx->GetRegisterInfo (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG1)->kinds[eRegisterKindLLDB];
- argument_register_ids[1] = reg_ctx->GetRegisterInfo (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG2)->kinds[eRegisterKindLLDB];
- argument_register_ids[2] = reg_ctx->GetRegisterInfo (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG3)->kinds[eRegisterKindLLDB];
- argument_register_ids[3] = reg_ctx->GetRegisterInfo (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG4)->kinds[eRegisterKindLLDB];
- argument_register_ids[4] = reg_ctx->GetRegisterInfo (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG5)->kinds[eRegisterKindLLDB];
- argument_register_ids[5] = reg_ctx->GetRegisterInfo (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG6)->kinds[eRegisterKindLLDB];
- argument_register_ids[6] = reg_ctx->GetRegisterInfo (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG7)->kinds[eRegisterKindLLDB];
- argument_register_ids[7] = reg_ctx->GetRegisterInfo (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG8)->kinds[eRegisterKindLLDB];
-
- unsigned int current_argument_register = 0;
-
- for (value_index = 0;
- value_index < num_values;
- ++value_index)
- {
- Value *value = values.GetValueAtIndex(value_index);
+ if (!reg_ctx)
+ return false;
- if (!value)
- return false;
+ // Get the pointer to the first stack argument so we have a place to start
+ // when reading data
- // We currently only support extracting values with Clang QualTypes.
- // Do we care about others?
- CompilerType compiler_type = value->GetCompilerType();
- if (!compiler_type)
- return false;
- bool is_signed;
+ addr_t sp = reg_ctx->GetSP(0);
- if (compiler_type.IsIntegerOrEnumerationType (is_signed))
- {
- ReadIntegerArgument(value->GetScalar(),
- compiler_type.GetBitSize(&thread),
- is_signed,
- thread,
- argument_register_ids,
- current_argument_register,
- current_stack_argument);
- }
- else if (compiler_type.IsPointerType ())
- {
- ReadIntegerArgument(value->GetScalar(),
- compiler_type.GetBitSize(&thread),
- false,
- thread,
- argument_register_ids,
- current_argument_register,
- current_stack_argument);
- }
- }
+ if (!sp)
+ return false;
- return true;
-}
+ addr_t current_stack_argument = sp + 48; // jump over return address
-Error
-ABISysV_ppc::SetReturnValueObject(lldb::StackFrameSP &frame_sp, lldb::ValueObjectSP &new_value_sp)
-{
- Error error;
- if (!new_value_sp)
- {
- error.SetErrorString("Empty value object for return value.");
- return error;
- }
+ uint32_t argument_register_ids[8];
- CompilerType compiler_type = new_value_sp->GetCompilerType();
+ argument_register_ids[0] =
+ reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG1)
+ ->kinds[eRegisterKindLLDB];
+ argument_register_ids[1] =
+ reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG2)
+ ->kinds[eRegisterKindLLDB];
+ argument_register_ids[2] =
+ reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG3)
+ ->kinds[eRegisterKindLLDB];
+ argument_register_ids[3] =
+ reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG4)
+ ->kinds[eRegisterKindLLDB];
+ argument_register_ids[4] =
+ reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG5)
+ ->kinds[eRegisterKindLLDB];
+ argument_register_ids[5] =
+ reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG6)
+ ->kinds[eRegisterKindLLDB];
+ argument_register_ids[6] =
+ reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG7)
+ ->kinds[eRegisterKindLLDB];
+ argument_register_ids[7] =
+ reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG8)
+ ->kinds[eRegisterKindLLDB];
+
+ unsigned int current_argument_register = 0;
+
+ for (value_index = 0; value_index < num_values; ++value_index) {
+ Value *value = values.GetValueAtIndex(value_index);
+
+ if (!value)
+ return false;
+
+ // We currently only support extracting values with Clang QualTypes.
+ // Do we care about others?
+ CompilerType compiler_type = value->GetCompilerType();
if (!compiler_type)
- {
- error.SetErrorString ("Null clang type for return value.");
- return error;
- }
-
- Thread *thread = frame_sp->GetThread().get();
-
+ return false;
bool is_signed;
- uint32_t count;
- bool is_complex;
- RegisterContext *reg_ctx = thread->GetRegisterContext().get();
+ if (compiler_type.IsIntegerOrEnumerationType(is_signed)) {
+ ReadIntegerArgument(value->GetScalar(), compiler_type.GetBitSize(&thread),
+ is_signed, thread, argument_register_ids,
+ current_argument_register, current_stack_argument);
+ } else if (compiler_type.IsPointerType()) {
+ ReadIntegerArgument(value->GetScalar(), compiler_type.GetBitSize(&thread),
+ false, thread, argument_register_ids,
+ current_argument_register, current_stack_argument);
+ }
+ }
+
+ return true;
+}
+
+Error ABISysV_ppc::SetReturnValueObject(lldb::StackFrameSP &frame_sp,
+ lldb::ValueObjectSP &new_value_sp) {
+ Error error;
+ if (!new_value_sp) {
+ error.SetErrorString("Empty value object for return value.");
+ return error;
+ }
- bool set_it_simple = false;
- if (compiler_type.IsIntegerOrEnumerationType (is_signed) || compiler_type.IsPointerType())
- {
- const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoByName("r3", 0);
+ CompilerType compiler_type = new_value_sp->GetCompilerType();
+ if (!compiler_type) {
+ error.SetErrorString("Null clang type for return value.");
+ return error;
+ }
+
+ Thread *thread = frame_sp->GetThread().get();
+ bool is_signed;
+ uint32_t count;
+ bool is_complex;
+
+ RegisterContext *reg_ctx = thread->GetRegisterContext().get();
+
+ bool set_it_simple = false;
+ if (compiler_type.IsIntegerOrEnumerationType(is_signed) ||
+ compiler_type.IsPointerType()) {
+ const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoByName("r3", 0);
+
+ DataExtractor data;
+ Error data_error;
+ size_t num_bytes = new_value_sp->GetData(data, data_error);
+ if (data_error.Fail()) {
+ error.SetErrorStringWithFormat(
+ "Couldn't convert return value to raw data: %s",
+ data_error.AsCString());
+ return error;
+ }
+ lldb::offset_t offset = 0;
+ if (num_bytes <= 8) {
+ uint64_t raw_value = data.GetMaxU64(&offset, num_bytes);
+
+ if (reg_ctx->WriteRegisterFromUnsigned(reg_info, raw_value))
+ set_it_simple = true;
+ } else {
+ error.SetErrorString("We don't support returning longer than 64 bit "
+ "integer values at present.");
+ }
+ } else if (compiler_type.IsFloatingPointType(count, is_complex)) {
+ if (is_complex)
+ error.SetErrorString(
+ "We don't support returning complex values at present");
+ else {
+ size_t bit_width = compiler_type.GetBitSize(frame_sp.get());
+ if (bit_width <= 64) {
DataExtractor data;
Error data_error;
size_t num_bytes = new_value_sp->GetData(data, data_error);
- if (data_error.Fail())
- {
- error.SetErrorStringWithFormat("Couldn't convert return value to raw data: %s", data_error.AsCString());
- return error;
- }
- lldb::offset_t offset = 0;
- if (num_bytes <= 8)
- {
- uint64_t raw_value = data.GetMaxU64(&offset, num_bytes);
+ if (data_error.Fail()) {
+ error.SetErrorStringWithFormat(
+ "Couldn't convert return value to raw data: %s",
+ data_error.AsCString());
+ return error;
+ }
+
+ unsigned char buffer[16];
+ ByteOrder byte_order = data.GetByteOrder();
+
+ data.CopyByteOrderedData(0, num_bytes, buffer, 16, byte_order);
+ set_it_simple = true;
+ } else {
+ // FIXME - don't know how to do 80 bit long doubles yet.
+ error.SetErrorString(
+ "We don't support returning float values > 64 bits at present");
+ }
+ }
+ }
+
+ if (!set_it_simple) {
+ // Okay we've got a structure or something that doesn't fit in a simple
+ // register.
+ // We should figure out where it really goes, but we don't support this yet.
+ error.SetErrorString("We only support setting simple integer and float "
+ "return types at present.");
+ }
+
+ return error;
+}
+
+ValueObjectSP ABISysV_ppc::GetReturnValueObjectSimple(
+ Thread &thread, CompilerType &return_compiler_type) const {
+ ValueObjectSP return_valobj_sp;
+ Value value;
- if (reg_ctx->WriteRegisterFromUnsigned (reg_info, raw_value))
- set_it_simple = true;
- }
- else
- {
- error.SetErrorString("We don't support returning longer than 64 bit integer values at present.");
- }
- }
- else if (compiler_type.IsFloatingPointType (count, is_complex))
- {
- if (is_complex)
- error.SetErrorString ("We don't support returning complex values at present");
- else
- {
- size_t bit_width = compiler_type.GetBitSize(frame_sp.get());
- if (bit_width <= 64)
- {
- DataExtractor data;
- Error data_error;
- size_t num_bytes = new_value_sp->GetData(data, data_error);
- if (data_error.Fail())
- {
- error.SetErrorStringWithFormat("Couldn't convert return value to raw data: %s", data_error.AsCString());
- return error;
- }
-
- unsigned char buffer[16];
- ByteOrder byte_order = data.GetByteOrder();
-
- data.CopyByteOrderedData (0, num_bytes, buffer, 16, byte_order);
- set_it_simple = true;
- }
- else
- {
- // FIXME - don't know how to do 80 bit long doubles yet.
- error.SetErrorString ("We don't support returning float values > 64 bits at present");
- }
- }
- }
-
- if (!set_it_simple)
- {
- // Okay we've got a structure or something that doesn't fit in a simple register.
- // We should figure out where it really goes, but we don't support this yet.
- error.SetErrorString ("We only support setting simple integer and float return types at present.");
- }
+ if (!return_compiler_type)
+ return return_valobj_sp;
- return error;
-}
+ // value.SetContext (Value::eContextTypeClangType, return_value_type);
+ value.SetCompilerType(return_compiler_type);
-ValueObjectSP
-ABISysV_ppc::GetReturnValueObjectSimple (Thread &thread,
- CompilerType &return_compiler_type) const
-{
- ValueObjectSP return_valobj_sp;
- Value value;
-
- if (!return_compiler_type)
- return return_valobj_sp;
-
- //value.SetContext (Value::eContextTypeClangType, return_value_type);
- value.SetCompilerType (return_compiler_type);
-
- RegisterContext *reg_ctx = thread.GetRegisterContext().get();
- if (!reg_ctx)
- return return_valobj_sp;
+ RegisterContext *reg_ctx = thread.GetRegisterContext().get();
+ if (!reg_ctx)
+ return return_valobj_sp;
- const uint32_t type_flags = return_compiler_type.GetTypeInfo ();
- if (type_flags & eTypeIsScalar)
- {
- value.SetValueType(Value::eValueTypeScalar);
+ const uint32_t type_flags = return_compiler_type.GetTypeInfo();
+ if (type_flags & eTypeIsScalar) {
+ value.SetValueType(Value::eValueTypeScalar);
+
+ bool success = false;
+ if (type_flags & eTypeIsInteger) {
+ // Extract the register context so we can read arguments from registers
+
+ const size_t byte_size = return_compiler_type.GetByteSize(nullptr);
+ uint64_t raw_value = thread.GetRegisterContext()->ReadRegisterAsUnsigned(
+ reg_ctx->GetRegisterInfoByName("r3", 0), 0);
+ const bool is_signed = (type_flags & eTypeIsSigned) != 0;
+ switch (byte_size) {
+ default:
+ break;
- bool success = false;
- if (type_flags & eTypeIsInteger)
- {
- // Extract the register context so we can read arguments from registers
+ case sizeof(uint64_t):
+ if (is_signed)
+ value.GetScalar() = (int64_t)(raw_value);
+ else
+ value.GetScalar() = (uint64_t)(raw_value);
+ success = true;
+ break;
- const size_t byte_size = return_compiler_type.GetByteSize(nullptr);
- uint64_t raw_value = thread.GetRegisterContext()->ReadRegisterAsUnsigned(reg_ctx->GetRegisterInfoByName("r3", 0), 0);
- const bool is_signed = (type_flags & eTypeIsSigned) != 0;
- switch (byte_size)
- {
- default:
- break;
-
- case sizeof(uint64_t):
- if (is_signed)
- value.GetScalar() = (int64_t)(raw_value);
- else
- value.GetScalar() = (uint64_t)(raw_value);
- success = true;
- break;
+ case sizeof(uint32_t):
+ if (is_signed)
+ value.GetScalar() = (int32_t)(raw_value & UINT32_MAX);
+ else
+ value.GetScalar() = (uint32_t)(raw_value & UINT32_MAX);
+ success = true;
+ break;
- case sizeof(uint32_t):
- if (is_signed)
- value.GetScalar() = (int32_t)(raw_value & UINT32_MAX);
- else
- value.GetScalar() = (uint32_t)(raw_value & UINT32_MAX);
- success = true;
- break;
+ case sizeof(uint16_t):
+ if (is_signed)
+ value.GetScalar() = (int16_t)(raw_value & UINT16_MAX);
+ else
+ value.GetScalar() = (uint16_t)(raw_value & UINT16_MAX);
+ success = true;
+ break;
- case sizeof(uint16_t):
- if (is_signed)
- value.GetScalar() = (int16_t)(raw_value & UINT16_MAX);
- else
- value.GetScalar() = (uint16_t)(raw_value & UINT16_MAX);
+ case sizeof(uint8_t):
+ if (is_signed)
+ value.GetScalar() = (int8_t)(raw_value & UINT8_MAX);
+ else
+ value.GetScalar() = (uint8_t)(raw_value & UINT8_MAX);
+ success = true;
+ break;
+ }
+ } else if (type_flags & eTypeIsFloat) {
+ if (type_flags & eTypeIsComplex) {
+ // Don't handle complex yet.
+ } else {
+ const size_t byte_size = return_compiler_type.GetByteSize(nullptr);
+ if (byte_size <= sizeof(long double)) {
+ const RegisterInfo *f1_info = reg_ctx->GetRegisterInfoByName("f1", 0);
+ RegisterValue f1_value;
+ if (reg_ctx->ReadRegister(f1_info, f1_value)) {
+ DataExtractor data;
+ if (f1_value.GetData(data)) {
+ lldb::offset_t offset = 0;
+ if (byte_size == sizeof(float)) {
+ value.GetScalar() = (float)data.GetFloat(&offset);
success = true;
- break;
-
- case sizeof(uint8_t):
- if (is_signed)
- value.GetScalar() = (int8_t)(raw_value & UINT8_MAX);
- else
- value.GetScalar() = (uint8_t)(raw_value & UINT8_MAX);
+ } else if (byte_size == sizeof(double)) {
+ value.GetScalar() = (double)data.GetDouble(&offset);
success = true;
- break;
- }
- }
- else if (type_flags & eTypeIsFloat)
- {
- if (type_flags & eTypeIsComplex)
- {
- // Don't handle complex yet.
- }
- else
- {
- const size_t byte_size = return_compiler_type.GetByteSize(nullptr);
- if (byte_size <= sizeof(long double))
- {
- const RegisterInfo *f1_info = reg_ctx->GetRegisterInfoByName("f1", 0);
- RegisterValue f1_value;
- if (reg_ctx->ReadRegister (f1_info, f1_value))
- {
- DataExtractor data;
- if (f1_value.GetData(data))
- {
- lldb::offset_t offset = 0;
- if (byte_size == sizeof(float))
- {
- value.GetScalar() = (float) data.GetFloat(&offset);
- success = true;
- }
- else if (byte_size == sizeof(double))
- {
- value.GetScalar() = (double) data.GetDouble(&offset);
- success = true;
- }
- }
- }
- }
+ }
}
+ }
}
-
- if (success)
- return_valobj_sp = ValueObjectConstResult::Create (thread.GetStackFrameAtIndex(0).get(),
- value,
- ConstString(""));
+ }
}
- else if (type_flags & eTypeIsPointer)
- {
- unsigned r3_id = reg_ctx->GetRegisterInfoByName("r3", 0)->kinds[eRegisterKindLLDB];
- value.GetScalar() = (uint64_t)thread.GetRegisterContext()->ReadRegisterAsUnsigned(r3_id, 0);
- value.SetValueType(Value::eValueTypeScalar);
- return_valobj_sp = ValueObjectConstResult::Create (thread.GetStackFrameAtIndex(0).get(),
- value,
- ConstString(""));
- }
- else if (type_flags & eTypeIsVector)
- {
- const size_t byte_size = return_compiler_type.GetByteSize(nullptr);
- if (byte_size > 0)
- {
- const RegisterInfo *altivec_reg = reg_ctx->GetRegisterInfoByName("v2", 0);
- if (altivec_reg)
- {
- if (byte_size <= altivec_reg->byte_size)
- {
- ProcessSP process_sp (thread.GetProcess());
- if (process_sp)
- {
- std::unique_ptr<DataBufferHeap> heap_data_ap (new DataBufferHeap(byte_size, 0));
- const ByteOrder byte_order = process_sp->GetByteOrder();
- RegisterValue reg_value;
- if (reg_ctx->ReadRegister(altivec_reg, reg_value))
- {
- Error error;
- if (reg_value.GetAsMemoryData (altivec_reg,
- heap_data_ap->GetBytes(),
- heap_data_ap->GetByteSize(),
- byte_order,
- error))
- {
- DataExtractor data (DataBufferSP (heap_data_ap.release()),
- byte_order,
- process_sp->GetTarget().GetArchitecture().GetAddressByteSize());
- return_valobj_sp = ValueObjectConstResult::Create (&thread,
- return_compiler_type,
- ConstString(""),
- data);
- }
- }
- }
- }
+
+ if (success)
+ return_valobj_sp = ValueObjectConstResult::Create(
+ thread.GetStackFrameAtIndex(0).get(), value, ConstString(""));
+ } else if (type_flags & eTypeIsPointer) {
+ unsigned r3_id =
+ reg_ctx->GetRegisterInfoByName("r3", 0)->kinds[eRegisterKindLLDB];
+ value.GetScalar() =
+ (uint64_t)thread.GetRegisterContext()->ReadRegisterAsUnsigned(r3_id, 0);
+ value.SetValueType(Value::eValueTypeScalar);
+ return_valobj_sp = ValueObjectConstResult::Create(
+ thread.GetStackFrameAtIndex(0).get(), value, ConstString(""));
+ } else if (type_flags & eTypeIsVector) {
+ const size_t byte_size = return_compiler_type.GetByteSize(nullptr);
+ if (byte_size > 0) {
+ const RegisterInfo *altivec_reg = reg_ctx->GetRegisterInfoByName("v2", 0);
+ if (altivec_reg) {
+ if (byte_size <= altivec_reg->byte_size) {
+ ProcessSP process_sp(thread.GetProcess());
+ if (process_sp) {
+ std::unique_ptr<DataBufferHeap> heap_data_ap(
+ new DataBufferHeap(byte_size, 0));
+ const ByteOrder byte_order = process_sp->GetByteOrder();
+ RegisterValue reg_value;
+ if (reg_ctx->ReadRegister(altivec_reg, reg_value)) {
+ Error error;
+ if (reg_value.GetAsMemoryData(
+ altivec_reg, heap_data_ap->GetBytes(),
+ heap_data_ap->GetByteSize(), byte_order, error)) {
+ DataExtractor data(DataBufferSP(heap_data_ap.release()),
+ byte_order, process_sp->GetTarget()
+ .GetArchitecture()
+ .GetAddressByteSize());
+ return_valobj_sp = ValueObjectConstResult::Create(
+ &thread, return_compiler_type, ConstString(""), data);
+ }
}
+ }
}
+ }
}
+ }
- return return_valobj_sp;
+ return return_valobj_sp;
}
-ValueObjectSP
-ABISysV_ppc::GetReturnValueObjectImpl (Thread &thread, CompilerType &return_compiler_type) const
-{
- ValueObjectSP return_valobj_sp;
-
- if (!return_compiler_type)
- return return_valobj_sp;
-
- ExecutionContext exe_ctx (thread.shared_from_this());
- return_valobj_sp = GetReturnValueObjectSimple(thread, return_compiler_type);
- if (return_valobj_sp)
- return return_valobj_sp;
-
- RegisterContextSP reg_ctx_sp = thread.GetRegisterContext();
- if (!reg_ctx_sp)
- return return_valobj_sp;
+ValueObjectSP ABISysV_ppc::GetReturnValueObjectImpl(
+ Thread &thread, CompilerType &return_compiler_type) const {
+ ValueObjectSP return_valobj_sp;
- const size_t bit_width = return_compiler_type.GetBitSize(&thread);
- if (return_compiler_type.IsAggregateType())
- {
- Target *target = exe_ctx.GetTargetPtr();
- bool is_memory = true;
- if (bit_width <= 128)
- {
- ByteOrder target_byte_order = target->GetArchitecture().GetByteOrder();
- DataBufferSP data_sp (new DataBufferHeap(16, 0));
- DataExtractor return_ext (data_sp,
- target_byte_order,
- target->GetArchitecture().GetAddressByteSize());
-
- const RegisterInfo *r3_info = reg_ctx_sp->GetRegisterInfoByName("r3", 0);
- const RegisterInfo *rdx_info = reg_ctx_sp->GetRegisterInfoByName("rdx", 0);
-
- RegisterValue r3_value, rdx_value;
- reg_ctx_sp->ReadRegister (r3_info, r3_value);
- reg_ctx_sp->ReadRegister (rdx_info, rdx_value);
-
- DataExtractor r3_data, rdx_data;
-
- r3_value.GetData(r3_data);
- rdx_value.GetData(rdx_data);
-
- uint32_t fp_bytes = 0; // Tracks how much of the xmm registers we've consumed so far
- uint32_t integer_bytes = 0; // Tracks how much of the r3/rds registers we've consumed so far
-
- const uint32_t num_children = return_compiler_type.GetNumFields ();
-
- // Since we are in the small struct regime, assume we are not in memory.
- is_memory = false;
-
- for (uint32_t idx = 0; idx < num_children; idx++)
- {
- std::string name;
- uint64_t field_bit_offset = 0;
- bool is_signed;
- bool is_complex;
- uint32_t count;
-
- CompilerType field_compiler_type = return_compiler_type.GetFieldAtIndex(idx, name, &field_bit_offset, nullptr, nullptr);
- const size_t field_bit_width = field_compiler_type.GetBitSize(&thread);
-
- // If there are any unaligned fields, this is stored in memory.
- if (field_bit_offset % field_bit_width != 0)
- {
- is_memory = true;
- break;
- }
+ if (!return_compiler_type)
+ return return_valobj_sp;
+
+ ExecutionContext exe_ctx(thread.shared_from_this());
+ return_valobj_sp = GetReturnValueObjectSimple(thread, return_compiler_type);
+ if (return_valobj_sp)
+ return return_valobj_sp;
- uint32_t field_byte_width = field_bit_width/8;
- uint32_t field_byte_offset = field_bit_offset/8;
+ RegisterContextSP reg_ctx_sp = thread.GetRegisterContext();
+ if (!reg_ctx_sp)
+ return return_valobj_sp;
- DataExtractor *copy_from_extractor = nullptr;
- uint32_t copy_from_offset = 0;
+ const size_t bit_width = return_compiler_type.GetBitSize(&thread);
+ if (return_compiler_type.IsAggregateType()) {
+ Target *target = exe_ctx.GetTargetPtr();
+ bool is_memory = true;
+ if (bit_width <= 128) {
+ ByteOrder target_byte_order = target->GetArchitecture().GetByteOrder();
+ DataBufferSP data_sp(new DataBufferHeap(16, 0));
+ DataExtractor return_ext(data_sp, target_byte_order,
+ target->GetArchitecture().GetAddressByteSize());
+
+ const RegisterInfo *r3_info = reg_ctx_sp->GetRegisterInfoByName("r3", 0);
+ const RegisterInfo *rdx_info =
+ reg_ctx_sp->GetRegisterInfoByName("rdx", 0);
+
+ RegisterValue r3_value, rdx_value;
+ reg_ctx_sp->ReadRegister(r3_info, r3_value);
+ reg_ctx_sp->ReadRegister(rdx_info, rdx_value);
+
+ DataExtractor r3_data, rdx_data;
+
+ r3_value.GetData(r3_data);
+ rdx_value.GetData(rdx_data);
+
+ uint32_t fp_bytes =
+ 0; // Tracks how much of the xmm registers we've consumed so far
+ uint32_t integer_bytes =
+ 0; // Tracks how much of the r3/rds registers we've consumed so far
+
+ const uint32_t num_children = return_compiler_type.GetNumFields();
+
+ // Since we are in the small struct regime, assume we are not in memory.
+ is_memory = false;
+
+ for (uint32_t idx = 0; idx < num_children; idx++) {
+ std::string name;
+ uint64_t field_bit_offset = 0;
+ bool is_signed;
+ bool is_complex;
+ uint32_t count;
- if (field_compiler_type.IsIntegerOrEnumerationType (is_signed) || field_compiler_type.IsPointerType ())
- {
- if (integer_bytes < 8)
- {
- if (integer_bytes + field_byte_width <= 8)
- {
- // This is in RAX, copy from register to our result structure:
- copy_from_extractor = &r3_data;
- copy_from_offset = integer_bytes;
- integer_bytes += field_byte_width;
- }
- else
- {
- // The next field wouldn't fit in the remaining space, so we pushed it to rdx.
- copy_from_extractor = &rdx_data;
- copy_from_offset = 0;
- integer_bytes = 8 + field_byte_width;
- }
- }
- else if (integer_bytes + field_byte_width <= 16)
- {
- copy_from_extractor = &rdx_data;
- copy_from_offset = integer_bytes - 8;
- integer_bytes += field_byte_width;
- }
- else
- {
- // The last field didn't fit. I can't see how that would happen w/o the overall size being
- // greater than 16 bytes. For now, return a nullptr return value object.
- return return_valobj_sp;
- }
+ CompilerType field_compiler_type = return_compiler_type.GetFieldAtIndex(
+ idx, name, &field_bit_offset, nullptr, nullptr);
+ const size_t field_bit_width = field_compiler_type.GetBitSize(&thread);
+
+ // If there are any unaligned fields, this is stored in memory.
+ if (field_bit_offset % field_bit_width != 0) {
+ is_memory = true;
+ break;
+ }
+
+ uint32_t field_byte_width = field_bit_width / 8;
+ uint32_t field_byte_offset = field_bit_offset / 8;
+
+ DataExtractor *copy_from_extractor = nullptr;
+ uint32_t copy_from_offset = 0;
+
+ if (field_compiler_type.IsIntegerOrEnumerationType(is_signed) ||
+ field_compiler_type.IsPointerType()) {
+ if (integer_bytes < 8) {
+ if (integer_bytes + field_byte_width <= 8) {
+ // This is in RAX, copy from register to our result structure:
+ copy_from_extractor = &r3_data;
+ copy_from_offset = integer_bytes;
+ integer_bytes += field_byte_width;
+ } else {
+ // The next field wouldn't fit in the remaining space, so we
+ // pushed it to rdx.
+ copy_from_extractor = &rdx_data;
+ copy_from_offset = 0;
+ integer_bytes = 8 + field_byte_width;
+ }
+ } else if (integer_bytes + field_byte_width <= 16) {
+ copy_from_extractor = &rdx_data;
+ copy_from_offset = integer_bytes - 8;
+ integer_bytes += field_byte_width;
+ } else {
+ // The last field didn't fit. I can't see how that would happen w/o
+ // the overall size being
+ // greater than 16 bytes. For now, return a nullptr return value
+ // object.
+ return return_valobj_sp;
+ }
+ } else if (field_compiler_type.IsFloatingPointType(count, is_complex)) {
+ // Structs with long doubles are always passed in memory.
+ if (field_bit_width == 128) {
+ is_memory = true;
+ break;
+ } else if (field_bit_width == 64) {
+ copy_from_offset = 0;
+ fp_bytes += field_byte_width;
+ } else if (field_bit_width == 32) {
+ // This one is kind of complicated. If we are in an "eightbyte"
+ // with another float, we'll
+ // be stuffed into an xmm register with it. If we are in an
+ // "eightbyte" with one or more ints,
+ // then we will be stuffed into the appropriate GPR with them.
+ bool in_gpr;
+ if (field_byte_offset % 8 == 0) {
+ // We are at the beginning of one of the eightbytes, so check the
+ // next element (if any)
+ if (idx == num_children - 1)
+ in_gpr = false;
+ else {
+ uint64_t next_field_bit_offset = 0;
+ CompilerType next_field_compiler_type =
+ return_compiler_type.GetFieldAtIndex(idx + 1, name,
+ &next_field_bit_offset,
+ nullptr, nullptr);
+ if (next_field_compiler_type.IsIntegerOrEnumerationType(
+ is_signed))
+ in_gpr = true;
+ else {
+ copy_from_offset = 0;
+ in_gpr = false;
}
- else if (field_compiler_type.IsFloatingPointType (count, is_complex))
- {
- // Structs with long doubles are always passed in memory.
- if (field_bit_width == 128)
- {
- is_memory = true;
- break;
- }
- else if (field_bit_width == 64)
- {
- copy_from_offset = 0;
- fp_bytes += field_byte_width;
- }
- else if (field_bit_width == 32)
- {
- // This one is kind of complicated. If we are in an "eightbyte" with another float, we'll
- // be stuffed into an xmm register with it. If we are in an "eightbyte" with one or more ints,
- // then we will be stuffed into the appropriate GPR with them.
- bool in_gpr;
- if (field_byte_offset % 8 == 0)
- {
- // We are at the beginning of one of the eightbytes, so check the next element (if any)
- if (idx == num_children - 1)
- in_gpr = false;
- else
- {
- uint64_t next_field_bit_offset = 0;
- CompilerType next_field_compiler_type = return_compiler_type.GetFieldAtIndex (idx + 1,
- name,
- &next_field_bit_offset,
- nullptr,
- nullptr);
- if (next_field_compiler_type.IsIntegerOrEnumerationType (is_signed))
- in_gpr = true;
- else
- {
- copy_from_offset = 0;
- in_gpr = false;
- }
- }
- }
- else if (field_byte_offset % 4 == 0)
- {
- // We are inside of an eightbyte, so see if the field before us is floating point:
- // This could happen if somebody put padding in the structure.
- if (idx == 0)
- in_gpr = false;
- else
- {
- uint64_t prev_field_bit_offset = 0;
- CompilerType prev_field_compiler_type = return_compiler_type.GetFieldAtIndex (idx - 1,
- name,
- &prev_field_bit_offset,
- nullptr,
- nullptr);
- if (prev_field_compiler_type.IsIntegerOrEnumerationType (is_signed))
- in_gpr = true;
- else
- {
- copy_from_offset = 4;
- in_gpr = false;
- }
- }
- }
- else
- {
- is_memory = true;
- continue;
- }
-
- // Okay, we've figured out whether we are in GPR or XMM, now figure out which one.
- if (in_gpr)
- {
- if (integer_bytes < 8)
- {
- // This is in RAX, copy from register to our result structure:
- copy_from_extractor = &r3_data;
- copy_from_offset = integer_bytes;
- integer_bytes += field_byte_width;
- }
- else
- {
- copy_from_extractor = &rdx_data;
- copy_from_offset = integer_bytes - 8;
- integer_bytes += field_byte_width;
- }
- }
- else
- {
- fp_bytes += field_byte_width;
- }
- }
+ }
+ } else if (field_byte_offset % 4 == 0) {
+ // We are inside of an eightbyte, so see if the field before us is
+ // floating point:
+ // This could happen if somebody put padding in the structure.
+ if (idx == 0)
+ in_gpr = false;
+ else {
+ uint64_t prev_field_bit_offset = 0;
+ CompilerType prev_field_compiler_type =
+ return_compiler_type.GetFieldAtIndex(idx - 1, name,
+ &prev_field_bit_offset,
+ nullptr, nullptr);
+ if (prev_field_compiler_type.IsIntegerOrEnumerationType(
+ is_signed))
+ in_gpr = true;
+ else {
+ copy_from_offset = 4;
+ in_gpr = false;
}
-
- // These two tests are just sanity checks. If I somehow get the
- // type calculation wrong above it is better to just return nothing
- // than to assert or crash.
- if (!copy_from_extractor)
- return return_valobj_sp;
- if (copy_from_offset + field_byte_width > copy_from_extractor->GetByteSize())
- return return_valobj_sp;
-
- copy_from_extractor->CopyByteOrderedData (copy_from_offset,
- field_byte_width,
- data_sp->GetBytes() + field_byte_offset,
- field_byte_width,
- target_byte_order);
+ }
+ } else {
+ is_memory = true;
+ continue;
}
- if (!is_memory)
- {
- // The result is in our data buffer. Let's make a variable object out of it:
- return_valobj_sp = ValueObjectConstResult::Create (&thread,
- return_compiler_type,
- ConstString(""),
- return_ext);
+ // Okay, we've figured out whether we are in GPR or XMM, now figure
+ // out which one.
+ if (in_gpr) {
+ if (integer_bytes < 8) {
+ // This is in RAX, copy from register to our result structure:
+ copy_from_extractor = &r3_data;
+ copy_from_offset = integer_bytes;
+ integer_bytes += field_byte_width;
+ } else {
+ copy_from_extractor = &rdx_data;
+ copy_from_offset = integer_bytes - 8;
+ integer_bytes += field_byte_width;
+ }
+ } else {
+ fp_bytes += field_byte_width;
}
+ }
}
- // FIXME: This is just taking a guess, r3 may very well no longer hold the return storage location.
- // If we are going to do this right, when we make a new frame we should check to see if it uses a memory
- // return, and if we are at the first instruction and if so stash away the return location. Then we would
- // only return the memory return value if we know it is valid.
+ // These two tests are just sanity checks. If I somehow get the
+ // type calculation wrong above it is better to just return nothing
+ // than to assert or crash.
+ if (!copy_from_extractor)
+ return return_valobj_sp;
+ if (copy_from_offset + field_byte_width >
+ copy_from_extractor->GetByteSize())
+ return return_valobj_sp;
- if (is_memory)
- {
- unsigned r3_id = reg_ctx_sp->GetRegisterInfoByName("r3", 0)->kinds[eRegisterKindLLDB];
- lldb::addr_t storage_addr = (uint64_t)thread.GetRegisterContext()->ReadRegisterAsUnsigned(r3_id, 0);
- return_valobj_sp = ValueObjectMemory::Create(&thread,
- "",
- Address(storage_addr, nullptr),
- return_compiler_type);
- }
+ copy_from_extractor->CopyByteOrderedData(
+ copy_from_offset, field_byte_width,
+ data_sp->GetBytes() + field_byte_offset, field_byte_width,
+ target_byte_order);
+ }
+
+ if (!is_memory) {
+ // The result is in our data buffer. Let's make a variable object out
+ // of it:
+ return_valobj_sp = ValueObjectConstResult::Create(
+ &thread, return_compiler_type, ConstString(""), return_ext);
+ }
}
- return return_valobj_sp;
-}
+ // FIXME: This is just taking a guess, r3 may very well no longer hold the
+ // return storage location.
+ // If we are going to do this right, when we make a new frame we should
+ // check to see if it uses a memory
+ // return, and if we are at the first instruction and if so stash away the
+ // return location. Then we would
+ // only return the memory return value if we know it is valid.
-bool
-ABISysV_ppc::CreateFunctionEntryUnwindPlan (UnwindPlan &unwind_plan)
-{
- unwind_plan.Clear();
- unwind_plan.SetRegisterKind (eRegisterKindDWARF);
+ if (is_memory) {
+ unsigned r3_id =
+ reg_ctx_sp->GetRegisterInfoByName("r3", 0)->kinds[eRegisterKindLLDB];
+ lldb::addr_t storage_addr =
+ (uint64_t)thread.GetRegisterContext()->ReadRegisterAsUnsigned(r3_id,
+ 0);
+ return_valobj_sp = ValueObjectMemory::Create(
+ &thread, "", Address(storage_addr, nullptr), return_compiler_type);
+ }
+ }
- uint32_t lr_reg_num = dwarf_lr;
- uint32_t sp_reg_num = dwarf_r1;
- uint32_t pc_reg_num = dwarf_pc;
+ return return_valobj_sp;
+}
- UnwindPlan::RowSP row(new UnwindPlan::Row);
+bool ABISysV_ppc::CreateFunctionEntryUnwindPlan(UnwindPlan &unwind_plan) {
+ unwind_plan.Clear();
+ unwind_plan.SetRegisterKind(eRegisterKindDWARF);
- // Our Call Frame Address is the stack pointer value
- row->GetCFAValue().SetIsRegisterPlusOffset (sp_reg_num, 0);
+ uint32_t lr_reg_num = dwarf_lr;
+ uint32_t sp_reg_num = dwarf_r1;
+ uint32_t pc_reg_num = dwarf_pc;
- // The previous PC is in the LR
- row->SetRegisterLocationToRegister(pc_reg_num, lr_reg_num, true);
- unwind_plan.AppendRow (row);
+ UnwindPlan::RowSP row(new UnwindPlan::Row);
- // All other registers are the same.
+ // Our Call Frame Address is the stack pointer value
+ row->GetCFAValue().SetIsRegisterPlusOffset(sp_reg_num, 0);
- unwind_plan.SetSourceName ("ppc at-func-entry default");
- unwind_plan.SetSourcedFromCompiler (eLazyBoolNo);
+ // The previous PC is in the LR
+ row->SetRegisterLocationToRegister(pc_reg_num, lr_reg_num, true);
+ unwind_plan.AppendRow(row);
- return true;
-}
+ // All other registers are the same.
-bool
-ABISysV_ppc::CreateDefaultUnwindPlan (UnwindPlan &unwind_plan)
-{
- unwind_plan.Clear();
- unwind_plan.SetRegisterKind (eRegisterKindDWARF);
-
- uint32_t sp_reg_num = dwarf_r1;
- uint32_t pc_reg_num = dwarf_lr;
-
- UnwindPlan::RowSP row(new UnwindPlan::Row);
-
- const int32_t ptr_size = 4;
- row->GetCFAValue().SetIsRegisterDereferenced (sp_reg_num);
-
- row->SetRegisterLocationToAtCFAPlusOffset(pc_reg_num, ptr_size * 1, true);
- row->SetRegisterLocationToIsCFAPlusOffset(sp_reg_num, 0, true);
-
- unwind_plan.AppendRow (row);
- unwind_plan.SetSourceName ("ppc default unwind plan");
- unwind_plan.SetSourcedFromCompiler (eLazyBoolNo);
- unwind_plan.SetUnwindPlanValidAtAllInstructions (eLazyBoolNo);
- unwind_plan.SetReturnAddressRegister(dwarf_lr);
- return true;
-}
+ unwind_plan.SetSourceName("ppc at-func-entry default");
+ unwind_plan.SetSourcedFromCompiler(eLazyBoolNo);
-bool
-ABISysV_ppc::RegisterIsVolatile (const RegisterInfo *reg_info)
-{
- return !RegisterIsCalleeSaved (reg_info);
+ return true;
}
-// See "Register Usage" in the
-// "System V Application Binary Interface"
-// "64-bit PowerPC ELF Application Binary Interface Supplement"
-// current version is 1.9 released 2004 at http://refspecs.linuxfoundation.org/ELF/ppc/PPC-elf64abi-1.9.pdf
+bool ABISysV_ppc::CreateDefaultUnwindPlan(UnwindPlan &unwind_plan) {
+ unwind_plan.Clear();
+ unwind_plan.SetRegisterKind(eRegisterKindDWARF);
-bool
-ABISysV_ppc::RegisterIsCalleeSaved (const RegisterInfo *reg_info)
-{
- if (reg_info)
- {
- // Preserved registers are :
- // r1,r2,r13-r31
- // f14-f31 (not yet)
- // v20-v31 (not yet)
- // vrsave (not yet)
+ uint32_t sp_reg_num = dwarf_r1;
+ uint32_t pc_reg_num = dwarf_lr;
- const char *name = reg_info->name;
- if (name[0] == 'r')
- {
- if ((name[1] == '1' || name[1] == '2') && name[2] == '\0')
- return true;
- if (name[1] == '1' && name[2] > '2')
- return true;
- if ((name[1] == '2' || name[1] == '3') && name[2] != '\0')
- return true;
- }
+ UnwindPlan::RowSP row(new UnwindPlan::Row);
- if (name[0] == 'f' && name[1] >= '0' && name[1] <= '9')
- {
- if (name[3] == '1' && name[4] >= '4')
- return true;
- if ((name[3] == '2' || name[3] == '3') && name[4] != '\0')
- return true;
- }
+ const int32_t ptr_size = 4;
+ row->GetCFAValue().SetIsRegisterDereferenced(sp_reg_num);
- if (name[0] == 's' && name[1] == 'p' && name[2] == '\0') // sp
- return true;
- if (name[0] == 'f' && name[1] == 'p' && name[2] == '\0') // fp
- return true;
- if (name[0] == 'p' && name[1] == 'c' && name[2] == '\0') // pc
- return true;
- }
- return false;
-}
+ row->SetRegisterLocationToAtCFAPlusOffset(pc_reg_num, ptr_size * 1, true);
+ row->SetRegisterLocationToIsCFAPlusOffset(sp_reg_num, 0, true);
-void
-ABISysV_ppc::Initialize()
-{
- PluginManager::RegisterPlugin (GetPluginNameStatic(),
- "System V ABI for ppc targets",
- CreateInstance);
+ unwind_plan.AppendRow(row);
+ unwind_plan.SetSourceName("ppc default unwind plan");
+ unwind_plan.SetSourcedFromCompiler(eLazyBoolNo);
+ unwind_plan.SetUnwindPlanValidAtAllInstructions(eLazyBoolNo);
+ unwind_plan.SetReturnAddressRegister(dwarf_lr);
+ return true;
}
-void
-ABISysV_ppc::Terminate()
-{
- PluginManager::UnregisterPlugin (CreateInstance);
+bool ABISysV_ppc::RegisterIsVolatile(const RegisterInfo *reg_info) {
+ return !RegisterIsCalleeSaved(reg_info);
}
-lldb_private::ConstString
-ABISysV_ppc::GetPluginNameStatic()
-{
- static ConstString g_name("sysv-ppc");
- return g_name;
+// See "Register Usage" in the
+// "System V Application Binary Interface"
+// "64-bit PowerPC ELF Application Binary Interface Supplement"
+// current version is 1.9 released 2004 at
+// http://refspecs.linuxfoundation.org/ELF/ppc/PPC-elf64abi-1.9.pdf
+
+bool ABISysV_ppc::RegisterIsCalleeSaved(const RegisterInfo *reg_info) {
+ if (reg_info) {
+ // Preserved registers are :
+ // r1,r2,r13-r31
+ // f14-f31 (not yet)
+ // v20-v31 (not yet)
+ // vrsave (not yet)
+
+ const char *name = reg_info->name;
+ if (name[0] == 'r') {
+ if ((name[1] == '1' || name[1] == '2') && name[2] == '\0')
+ return true;
+ if (name[1] == '1' && name[2] > '2')
+ return true;
+ if ((name[1] == '2' || name[1] == '3') && name[2] != '\0')
+ return true;
+ }
+
+ if (name[0] == 'f' && name[1] >= '0' && name[1] <= '9') {
+ if (name[3] == '1' && name[4] >= '4')
+ return true;
+ if ((name[3] == '2' || name[3] == '3') && name[4] != '\0')
+ return true;
+ }
+
+ if (name[0] == 's' && name[1] == 'p' && name[2] == '\0') // sp
+ return true;
+ if (name[0] == 'f' && name[1] == 'p' && name[2] == '\0') // fp
+ return true;
+ if (name[0] == 'p' && name[1] == 'c' && name[2] == '\0') // pc
+ return true;
+ }
+ return false;
+}
+
+void ABISysV_ppc::Initialize() {
+ PluginManager::RegisterPlugin(GetPluginNameStatic(),
+ "System V ABI for ppc targets", CreateInstance);
+}
+
+void ABISysV_ppc::Terminate() {
+ PluginManager::UnregisterPlugin(CreateInstance);
+}
+
+lldb_private::ConstString ABISysV_ppc::GetPluginNameStatic() {
+ static ConstString g_name("sysv-ppc");
+ return g_name;
}
//------------------------------------------------------------------
// PluginInterface protocol
//------------------------------------------------------------------
-lldb_private::ConstString
-ABISysV_ppc::GetPluginName()
-{
- return GetPluginNameStatic();
+lldb_private::ConstString ABISysV_ppc::GetPluginName() {
+ return GetPluginNameStatic();
}
-uint32_t
-ABISysV_ppc::GetPluginVersion()
-{
- return 1;
-}
+uint32_t ABISysV_ppc::GetPluginVersion() { return 1; }
Modified: lldb/trunk/source/Plugins/ABI/SysV-ppc/ABISysV_ppc.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ABI/SysV-ppc/ABISysV_ppc.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ABI/SysV-ppc/ABISysV_ppc.h (original)
+++ lldb/trunk/source/Plugins/ABI/SysV-ppc/ABISysV_ppc.h Tue Sep 6 15:57:50 2016
@@ -14,120 +14,100 @@
// C++ Includes
// Other libraries and framework includes
// Project includes
-#include "lldb/lldb-private.h"
#include "lldb/Target/ABI.h"
+#include "lldb/lldb-private.h"
-class ABISysV_ppc :
- public lldb_private::ABI
-{
+class ABISysV_ppc : public lldb_private::ABI {
public:
- ~ABISysV_ppc() override = default;
+ ~ABISysV_ppc() override = default;
+
+ size_t GetRedZoneSize() const override;
+
+ bool PrepareTrivialCall(lldb_private::Thread &thread, lldb::addr_t sp,
+ lldb::addr_t functionAddress,
+ lldb::addr_t returnAddress,
+ llvm::ArrayRef<lldb::addr_t> args) const override;
+
+ bool GetArgumentValues(lldb_private::Thread &thread,
+ lldb_private::ValueList &values) const override;
+
+ lldb_private::Error
+ SetReturnValueObject(lldb::StackFrameSP &frame_sp,
+ lldb::ValueObjectSP &new_value) override;
+
+ lldb::ValueObjectSP
+ GetReturnValueObjectImpl(lldb_private::Thread &thread,
+ lldb_private::CompilerType &type) const override;
+
+ bool
+ CreateFunctionEntryUnwindPlan(lldb_private::UnwindPlan &unwind_plan) override;
+
+ bool CreateDefaultUnwindPlan(lldb_private::UnwindPlan &unwind_plan) override;
+
+ bool RegisterIsVolatile(const lldb_private::RegisterInfo *reg_info) override;
+
+ // The SysV ppc ABI requires that stack frames be 16 byte aligned.
+ // When there is a trap handler on the stack, e.g. _sigtramp in userland
+ // code, we've seen that the stack pointer is often not aligned properly
+ // before the handler is invoked. This means that lldb will stop the unwind
+ // early -- before the function which caused the trap.
+ //
+ // To work around this, we relax that alignment to be just word-size
+ // (8-bytes).
+ // Whitelisting the trap handlers for user space would be easy (_sigtramp) but
+ // in other environments there can be a large number of different functions
+ // involved in async traps.
+ bool CallFrameAddressIsValid(lldb::addr_t cfa) override {
+ // Make sure the stack call frame addresses are 8 byte aligned
+ if (cfa & (8ull - 1ull))
+ return false; // Not 8 byte aligned
+ if (cfa == 0)
+ return false; // Zero is not a valid stack address
+ return true;
+ }
+
+ bool CodeAddressIsValid(lldb::addr_t pc) override {
+ // We have a 64 bit address space, so anything is valid as opcodes
+ // aren't fixed width...
+ return true;
+ }
+
+ const lldb_private::RegisterInfo *
+ GetRegisterInfoArray(uint32_t &count) override;
+
+ //------------------------------------------------------------------
+ // Static Functions
+ //------------------------------------------------------------------
+
+ static void Initialize();
+
+ static void Terminate();
+
+ static lldb::ABISP CreateInstance(const lldb_private::ArchSpec &arch);
- size_t
- GetRedZoneSize() const override;
+ static lldb_private::ConstString GetPluginNameStatic();
- bool
- PrepareTrivialCall(lldb_private::Thread &thread,
- lldb::addr_t sp,
- lldb::addr_t functionAddress,
- lldb::addr_t returnAddress,
- llvm::ArrayRef<lldb::addr_t> args) const override;
-
- bool
- GetArgumentValues(lldb_private::Thread &thread,
- lldb_private::ValueList &values) const override;
-
- lldb_private::Error
- SetReturnValueObject(lldb::StackFrameSP &frame_sp, lldb::ValueObjectSP &new_value) override;
-
- lldb::ValueObjectSP
- GetReturnValueObjectImpl(lldb_private::Thread &thread,
- lldb_private::CompilerType &type) const override;
-
- bool
- CreateFunctionEntryUnwindPlan(lldb_private::UnwindPlan &unwind_plan) override;
-
- bool
- CreateDefaultUnwindPlan(lldb_private::UnwindPlan &unwind_plan) override;
-
- bool
- RegisterIsVolatile(const lldb_private::RegisterInfo *reg_info) override;
-
- // The SysV ppc ABI requires that stack frames be 16 byte aligned.
- // When there is a trap handler on the stack, e.g. _sigtramp in userland
- // code, we've seen that the stack pointer is often not aligned properly
- // before the handler is invoked. This means that lldb will stop the unwind
- // early -- before the function which caused the trap.
- //
- // To work around this, we relax that alignment to be just word-size (8-bytes).
- // Whitelisting the trap handlers for user space would be easy (_sigtramp) but
- // in other environments there can be a large number of different functions
- // involved in async traps.
- bool
- CallFrameAddressIsValid(lldb::addr_t cfa) override
- {
- // Make sure the stack call frame addresses are 8 byte aligned
- if (cfa & (8ull - 1ull))
- return false; // Not 8 byte aligned
- if (cfa == 0)
- return false; // Zero is not a valid stack address
- return true;
- }
-
- bool
- CodeAddressIsValid(lldb::addr_t pc) override
- {
- // We have a 64 bit address space, so anything is valid as opcodes
- // aren't fixed width...
- return true;
- }
-
- const lldb_private::RegisterInfo *
- GetRegisterInfoArray(uint32_t &count) override;
-
- //------------------------------------------------------------------
- // Static Functions
- //------------------------------------------------------------------
-
- static void
- Initialize();
-
- static void
- Terminate();
-
- static lldb::ABISP
- CreateInstance (const lldb_private::ArchSpec &arch);
-
- static lldb_private::ConstString
- GetPluginNameStatic();
-
- //------------------------------------------------------------------
- // PluginInterface protocol
- //------------------------------------------------------------------
+ //------------------------------------------------------------------
+ // PluginInterface protocol
+ //------------------------------------------------------------------
- lldb_private::ConstString
- GetPluginName() override;
+ lldb_private::ConstString GetPluginName() override;
- uint32_t
- GetPluginVersion() override;
+ uint32_t GetPluginVersion() override;
protected:
- void
- CreateRegisterMapIfNeeded ();
+ void CreateRegisterMapIfNeeded();
- lldb::ValueObjectSP
- GetReturnValueObjectSimple(lldb_private::Thread &thread,
- lldb_private::CompilerType &ast_type) const;
+ lldb::ValueObjectSP
+ GetReturnValueObjectSimple(lldb_private::Thread &thread,
+ lldb_private::CompilerType &ast_type) const;
- bool
- RegisterIsCalleeSaved (const lldb_private::RegisterInfo *reg_info);
+ bool RegisterIsCalleeSaved(const lldb_private::RegisterInfo *reg_info);
private:
- ABISysV_ppc() :
- lldb_private::ABI()
- {
- // Call CreateInstance instead.
- }
+ ABISysV_ppc() : lldb_private::ABI() {
+ // Call CreateInstance instead.
+ }
};
#endif // liblldb_ABISysV_ppc_h_
Modified: lldb/trunk/source/Plugins/ABI/SysV-ppc64/ABISysV_ppc64.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ABI/SysV-ppc64/ABISysV_ppc64.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ABI/SysV-ppc64/ABISysV_ppc64.cpp (original)
+++ lldb/trunk/source/Plugins/ABI/SysV-ppc64/ABISysV_ppc64.cpp Tue Sep 6 15:57:50 2016
@@ -25,231 +25,271 @@
#include "lldb/Core/RegisterValue.h"
#include "lldb/Core/Value.h"
#include "lldb/Core/ValueObjectConstResult.h"
-#include "lldb/Core/ValueObjectRegister.h"
#include "lldb/Core/ValueObjectMemory.h"
+#include "lldb/Core/ValueObjectRegister.h"
#include "lldb/Symbol/UnwindPlan.h"
-#include "lldb/Target/Target.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/RegisterContext.h"
#include "lldb/Target/StackFrame.h"
+#include "lldb/Target/Target.h"
#include "lldb/Target/Thread.h"
using namespace lldb;
using namespace lldb_private;
-enum dwarf_regnums
-{
- dwarf_r0 = 0,
- dwarf_r1,
- dwarf_r2,
- dwarf_r3,
- dwarf_r4,
- dwarf_r5,
- dwarf_r6,
- dwarf_r7,
- dwarf_r8,
- dwarf_r9,
- dwarf_r10,
- dwarf_r11,
- dwarf_r12,
- dwarf_r13,
- dwarf_r14,
- dwarf_r15,
- dwarf_r16,
- dwarf_r17,
- dwarf_r18,
- dwarf_r19,
- dwarf_r20,
- dwarf_r21,
- dwarf_r22,
- dwarf_r23,
- dwarf_r24,
- dwarf_r25,
- dwarf_r26,
- dwarf_r27,
- dwarf_r28,
- dwarf_r29,
- dwarf_r30,
- dwarf_r31,
- dwarf_f0,
- dwarf_f1,
- dwarf_f2,
- dwarf_f3,
- dwarf_f4,
- dwarf_f5,
- dwarf_f6,
- dwarf_f7,
- dwarf_f8,
- dwarf_f9,
- dwarf_f10,
- dwarf_f11,
- dwarf_f12,
- dwarf_f13,
- dwarf_f14,
- dwarf_f15,
- dwarf_f16,
- dwarf_f17,
- dwarf_f18,
- dwarf_f19,
- dwarf_f20,
- dwarf_f21,
- dwarf_f22,
- dwarf_f23,
- dwarf_f24,
- dwarf_f25,
- dwarf_f26,
- dwarf_f27,
- dwarf_f28,
- dwarf_f29,
- dwarf_f30,
- dwarf_f31,
- dwarf_cr,
- dwarf_fpscr,
- dwarf_xer = 101,
- dwarf_lr = 108,
- dwarf_ctr,
- dwarf_pc,
- dwarf_cfa,
+enum dwarf_regnums {
+ dwarf_r0 = 0,
+ dwarf_r1,
+ dwarf_r2,
+ dwarf_r3,
+ dwarf_r4,
+ dwarf_r5,
+ dwarf_r6,
+ dwarf_r7,
+ dwarf_r8,
+ dwarf_r9,
+ dwarf_r10,
+ dwarf_r11,
+ dwarf_r12,
+ dwarf_r13,
+ dwarf_r14,
+ dwarf_r15,
+ dwarf_r16,
+ dwarf_r17,
+ dwarf_r18,
+ dwarf_r19,
+ dwarf_r20,
+ dwarf_r21,
+ dwarf_r22,
+ dwarf_r23,
+ dwarf_r24,
+ dwarf_r25,
+ dwarf_r26,
+ dwarf_r27,
+ dwarf_r28,
+ dwarf_r29,
+ dwarf_r30,
+ dwarf_r31,
+ dwarf_f0,
+ dwarf_f1,
+ dwarf_f2,
+ dwarf_f3,
+ dwarf_f4,
+ dwarf_f5,
+ dwarf_f6,
+ dwarf_f7,
+ dwarf_f8,
+ dwarf_f9,
+ dwarf_f10,
+ dwarf_f11,
+ dwarf_f12,
+ dwarf_f13,
+ dwarf_f14,
+ dwarf_f15,
+ dwarf_f16,
+ dwarf_f17,
+ dwarf_f18,
+ dwarf_f19,
+ dwarf_f20,
+ dwarf_f21,
+ dwarf_f22,
+ dwarf_f23,
+ dwarf_f24,
+ dwarf_f25,
+ dwarf_f26,
+ dwarf_f27,
+ dwarf_f28,
+ dwarf_f29,
+ dwarf_f30,
+ dwarf_f31,
+ dwarf_cr,
+ dwarf_fpscr,
+ dwarf_xer = 101,
+ dwarf_lr = 108,
+ dwarf_ctr,
+ dwarf_pc,
+ dwarf_cfa,
};
// Note that the size and offset will be updated by platform-specific classes.
-#define DEFINE_GPR(reg, alt, kind1, kind2, kind3, kind4) \
- { #reg, alt, 8, 0, eEncodingUint, \
- eFormatHex, { kind1, kind2, kind3, kind4}, nullptr, nullptr, nullptr, 0 }
-
-static const RegisterInfo
-g_register_infos[] =
-{
- // General purpose registers. eh_frame, DWARF, Generic, Process Plugin
- DEFINE_GPR(r0, nullptr, dwarf_r0, dwarf_r0, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r1, "sp", dwarf_r1, dwarf_r1, LLDB_REGNUM_GENERIC_SP, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r2, nullptr, dwarf_r2, dwarf_r2, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r3, "arg1", dwarf_r3, dwarf_r3, LLDB_REGNUM_GENERIC_ARG1, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r4, "arg2", dwarf_r4, dwarf_r4, LLDB_REGNUM_GENERIC_ARG2 ,LLDB_INVALID_REGNUM),
- DEFINE_GPR(r5, "arg3", dwarf_r5, dwarf_r5, LLDB_REGNUM_GENERIC_ARG3, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r6, "arg4", dwarf_r6, dwarf_r6, LLDB_REGNUM_GENERIC_ARG4, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r7, "arg5", dwarf_r7, dwarf_r7, LLDB_REGNUM_GENERIC_ARG5, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r8, "arg6", dwarf_r8, dwarf_r8, LLDB_REGNUM_GENERIC_ARG6, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r9, "arg7", dwarf_r9, dwarf_r9, LLDB_REGNUM_GENERIC_ARG7, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r10, "arg8", dwarf_r10, dwarf_r10, LLDB_REGNUM_GENERIC_ARG8, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r11, nullptr, dwarf_r11, dwarf_r11, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r12, nullptr, dwarf_r12, dwarf_r12, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r13, nullptr, dwarf_r13, dwarf_r13, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r14, nullptr, dwarf_r14, dwarf_r14, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r15, nullptr, dwarf_r15, dwarf_r15, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r16, nullptr, dwarf_r16, dwarf_r16, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r17, nullptr, dwarf_r17, dwarf_r17, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r18, nullptr, dwarf_r18, dwarf_r18, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r19, nullptr, dwarf_r19, dwarf_r19, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r20, nullptr, dwarf_r20, dwarf_r20, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r21, nullptr, dwarf_r21, dwarf_r21, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r22, nullptr, dwarf_r22, dwarf_r22, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r23, nullptr, dwarf_r23, dwarf_r23, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r24, nullptr, dwarf_r24, dwarf_r24, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r25, nullptr, dwarf_r25, dwarf_r25, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r26, nullptr, dwarf_r26, dwarf_r26, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r27, nullptr, dwarf_r27, dwarf_r27, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r28, nullptr, dwarf_r28, dwarf_r28, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r29, nullptr, dwarf_r29, dwarf_r29, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r30, nullptr, dwarf_r30, dwarf_r30, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r31, nullptr, dwarf_r31, dwarf_r31, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(lr, "lr", dwarf_lr, dwarf_lr, LLDB_REGNUM_GENERIC_RA, LLDB_INVALID_REGNUM),
- DEFINE_GPR(cr, "cr", dwarf_cr, dwarf_cr, LLDB_REGNUM_GENERIC_FLAGS, LLDB_INVALID_REGNUM),
- DEFINE_GPR(xer, "xer", dwarf_xer, dwarf_xer, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(ctr, "ctr", dwarf_ctr, dwarf_ctr, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(pc, "pc", dwarf_pc, dwarf_pc, LLDB_REGNUM_GENERIC_PC, LLDB_INVALID_REGNUM),
- { nullptr, nullptr, 8, 0, eEncodingUint, eFormatHex, { dwarf_cfa, dwarf_cfa, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM}, nullptr, nullptr, nullptr, 0 }
-};
+#define DEFINE_GPR(reg, alt, kind1, kind2, kind3, kind4) \
+ { \
+ #reg, alt, 8, 0, eEncodingUint, eFormatHex, {kind1, kind2, kind3, kind4 }, \
+ nullptr, nullptr, nullptr, 0 \
+ }
+
+static const RegisterInfo g_register_infos[] = {
+ // General purpose registers. eh_frame, DWARF,
+ // Generic, Process Plugin
+ DEFINE_GPR(r0, nullptr, dwarf_r0, dwarf_r0, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r1, "sp", dwarf_r1, dwarf_r1, LLDB_REGNUM_GENERIC_SP,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r2, nullptr, dwarf_r2, dwarf_r2, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r3, "arg1", dwarf_r3, dwarf_r3, LLDB_REGNUM_GENERIC_ARG1,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r4, "arg2", dwarf_r4, dwarf_r4, LLDB_REGNUM_GENERIC_ARG2,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r5, "arg3", dwarf_r5, dwarf_r5, LLDB_REGNUM_GENERIC_ARG3,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r6, "arg4", dwarf_r6, dwarf_r6, LLDB_REGNUM_GENERIC_ARG4,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r7, "arg5", dwarf_r7, dwarf_r7, LLDB_REGNUM_GENERIC_ARG5,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r8, "arg6", dwarf_r8, dwarf_r8, LLDB_REGNUM_GENERIC_ARG6,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r9, "arg7", dwarf_r9, dwarf_r9, LLDB_REGNUM_GENERIC_ARG7,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r10, "arg8", dwarf_r10, dwarf_r10, LLDB_REGNUM_GENERIC_ARG8,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r11, nullptr, dwarf_r11, dwarf_r11, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r12, nullptr, dwarf_r12, dwarf_r12, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r13, nullptr, dwarf_r13, dwarf_r13, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r14, nullptr, dwarf_r14, dwarf_r14, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r15, nullptr, dwarf_r15, dwarf_r15, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r16, nullptr, dwarf_r16, dwarf_r16, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r17, nullptr, dwarf_r17, dwarf_r17, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r18, nullptr, dwarf_r18, dwarf_r18, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r19, nullptr, dwarf_r19, dwarf_r19, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r20, nullptr, dwarf_r20, dwarf_r20, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r21, nullptr, dwarf_r21, dwarf_r21, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r22, nullptr, dwarf_r22, dwarf_r22, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r23, nullptr, dwarf_r23, dwarf_r23, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r24, nullptr, dwarf_r24, dwarf_r24, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r25, nullptr, dwarf_r25, dwarf_r25, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r26, nullptr, dwarf_r26, dwarf_r26, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r27, nullptr, dwarf_r27, dwarf_r27, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r28, nullptr, dwarf_r28, dwarf_r28, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r29, nullptr, dwarf_r29, dwarf_r29, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r30, nullptr, dwarf_r30, dwarf_r30, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(r31, nullptr, dwarf_r31, dwarf_r31, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(lr, "lr", dwarf_lr, dwarf_lr, LLDB_REGNUM_GENERIC_RA,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(cr, "cr", dwarf_cr, dwarf_cr, LLDB_REGNUM_GENERIC_FLAGS,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(xer, "xer", dwarf_xer, dwarf_xer, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(ctr, "ctr", dwarf_ctr, dwarf_ctr, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM),
+ DEFINE_GPR(pc, "pc", dwarf_pc, dwarf_pc, LLDB_REGNUM_GENERIC_PC,
+ LLDB_INVALID_REGNUM),
+ {nullptr,
+ nullptr,
+ 8,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_cfa, dwarf_cfa, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0}};
-static const uint32_t k_num_register_infos = llvm::array_lengthof(g_register_infos);
+static const uint32_t k_num_register_infos =
+ llvm::array_lengthof(g_register_infos);
const lldb_private::RegisterInfo *
-ABISysV_ppc64::GetRegisterInfoArray (uint32_t &count)
-{
- count = k_num_register_infos;
- return g_register_infos;
+ABISysV_ppc64::GetRegisterInfoArray(uint32_t &count) {
+ count = k_num_register_infos;
+ return g_register_infos;
}
-size_t
-ABISysV_ppc64::GetRedZoneSize () const
-{
- return 224;
-}
+size_t ABISysV_ppc64::GetRedZoneSize() const { return 224; }
//------------------------------------------------------------------
// Static Functions
//------------------------------------------------------------------
ABISP
-ABISysV_ppc64::CreateInstance (const ArchSpec &arch)
-{
- static ABISP g_abi_sp;
- if (arch.GetTriple().getArch() == llvm::Triple::ppc64)
- {
- if (!g_abi_sp)
- g_abi_sp.reset (new ABISysV_ppc64);
- return g_abi_sp;
- }
- return ABISP();
-}
-
-bool
-ABISysV_ppc64::PrepareTrivialCall (Thread &thread,
- addr_t sp,
- addr_t func_addr,
- addr_t return_addr,
- llvm::ArrayRef<addr_t> args) const
-{
- Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
-
- if (log)
- {
- StreamString s;
- s.Printf("ABISysV_ppc64::PrepareTrivialCall (tid = 0x%" PRIx64 ", sp = 0x%" PRIx64 ", func_addr = 0x%" PRIx64 ", return_addr = 0x%" PRIx64,
- thread.GetID(),
- (uint64_t)sp,
- (uint64_t)func_addr,
- (uint64_t)return_addr);
-
- for (size_t i = 0; i < args.size(); ++i)
- s.Printf (", arg%" PRIu64 " = 0x%" PRIx64, static_cast<uint64_t>(i + 1), args[i]);
- s.PutCString (")");
- log->PutCString(s.GetString().c_str());
- }
-
- RegisterContext *reg_ctx = thread.GetRegisterContext().get();
- if (!reg_ctx)
- return false;
-
- const RegisterInfo *reg_info = nullptr;
-
- if (args.size() > 8) // TODO handle more than 8 arguments
- return false;
+ABISysV_ppc64::CreateInstance(const ArchSpec &arch) {
+ static ABISP g_abi_sp;
+ if (arch.GetTriple().getArch() == llvm::Triple::ppc64) {
+ if (!g_abi_sp)
+ g_abi_sp.reset(new ABISysV_ppc64);
+ return g_abi_sp;
+ }
+ return ABISP();
+}
+
+bool ABISysV_ppc64::PrepareTrivialCall(Thread &thread, addr_t sp,
+ addr_t func_addr, addr_t return_addr,
+ llvm::ArrayRef<addr_t> args) const {
+ Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
+
+ if (log) {
+ StreamString s;
+ s.Printf("ABISysV_ppc64::PrepareTrivialCall (tid = 0x%" PRIx64
+ ", sp = 0x%" PRIx64 ", func_addr = 0x%" PRIx64
+ ", return_addr = 0x%" PRIx64,
+ thread.GetID(), (uint64_t)sp, (uint64_t)func_addr,
+ (uint64_t)return_addr);
for (size_t i = 0; i < args.size(); ++i)
- {
- reg_info = reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG1 + i);
- if (log)
- log->Printf("About to write arg%" PRIu64 " (0x%" PRIx64 ") into %s", static_cast<uint64_t>(i + 1), args[i], reg_info->name);
- if (!reg_ctx->WriteRegisterFromUnsigned(reg_info, args[i]))
- return false;
- }
-
- // First, align the SP
+ s.Printf(", arg%" PRIu64 " = 0x%" PRIx64, static_cast<uint64_t>(i + 1),
+ args[i]);
+ s.PutCString(")");
+ log->PutCString(s.GetString().c_str());
+ }
- if (log)
- log->Printf("16-byte aligning SP: 0x%" PRIx64 " to 0x%" PRIx64, (uint64_t)sp, (uint64_t)(sp & ~0xfull));
+ RegisterContext *reg_ctx = thread.GetRegisterContext().get();
+ if (!reg_ctx)
+ return false;
- sp &= ~(0xfull); // 16-byte alignment
+ const RegisterInfo *reg_info = nullptr;
- sp -= 8;
+ if (args.size() > 8) // TODO handle more than 8 arguments
+ return false;
- Error error;
- const RegisterInfo *pc_reg_info = reg_ctx->GetRegisterInfo (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_PC);
- const RegisterInfo *sp_reg_info = reg_ctx->GetRegisterInfo (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_SP);
- ProcessSP process_sp (thread.GetProcess());
+ for (size_t i = 0; i < args.size(); ++i) {
+ reg_info = reg_ctx->GetRegisterInfo(eRegisterKindGeneric,
+ LLDB_REGNUM_GENERIC_ARG1 + i);
+ if (log)
+ log->Printf("About to write arg%" PRIu64 " (0x%" PRIx64 ") into %s",
+ static_cast<uint64_t>(i + 1), args[i], reg_info->name);
+ if (!reg_ctx->WriteRegisterFromUnsigned(reg_info, args[i]))
+ return false;
+ }
+
+ // First, align the SP
+
+ if (log)
+ log->Printf("16-byte aligning SP: 0x%" PRIx64 " to 0x%" PRIx64,
+ (uint64_t)sp, (uint64_t)(sp & ~0xfull));
+
+ sp &= ~(0xfull); // 16-byte alignment
+
+ sp -= 8;
+
+ Error error;
+ const RegisterInfo *pc_reg_info =
+ reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_PC);
+ const RegisterInfo *sp_reg_info =
+ reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_SP);
+ ProcessSP process_sp(thread.GetProcess());
- RegisterValue reg_value;
+ RegisterValue reg_value;
#if 0
// This code adds an extra frame so that we don't lose the function that we came from
@@ -292,780 +332,696 @@ ABISysV_ppc64::PrepareTrivialCall (Threa
}
#endif
- if (log)
- log->Printf("Pushing the return address onto the stack: 0x%" PRIx64 ": 0x%" PRIx64, (uint64_t)sp, (uint64_t)return_addr);
+ if (log)
+ log->Printf("Pushing the return address onto the stack: 0x%" PRIx64
+ ": 0x%" PRIx64,
+ (uint64_t)sp, (uint64_t)return_addr);
- // Save return address onto the stack
- if (!process_sp->WritePointerToMemory(sp, return_addr, error))
- return false;
+ // Save return address onto the stack
+ if (!process_sp->WritePointerToMemory(sp, return_addr, error))
+ return false;
- // %r1 is set to the actual stack value.
+ // %r1 is set to the actual stack value.
- if (log)
- log->Printf("Writing SP: 0x%" PRIx64, (uint64_t)sp);
+ if (log)
+ log->Printf("Writing SP: 0x%" PRIx64, (uint64_t)sp);
- if (!reg_ctx->WriteRegisterFromUnsigned (sp_reg_info, sp))
- return false;
+ if (!reg_ctx->WriteRegisterFromUnsigned(sp_reg_info, sp))
+ return false;
- // %pc is set to the address of the called function.
+ // %pc is set to the address of the called function.
- if (log)
- log->Printf("Writing IP: 0x%" PRIx64, (uint64_t)func_addr);
+ if (log)
+ log->Printf("Writing IP: 0x%" PRIx64, (uint64_t)func_addr);
- if (!reg_ctx->WriteRegisterFromUnsigned (pc_reg_info, func_addr))
- return false;
+ if (!reg_ctx->WriteRegisterFromUnsigned(pc_reg_info, func_addr))
+ return false;
- return true;
+ return true;
}
-static bool ReadIntegerArgument(Scalar &scalar,
- unsigned int bit_width,
- bool is_signed,
- Thread &thread,
- uint32_t *argument_register_ids,
- unsigned int ¤t_argument_register,
- addr_t ¤t_stack_argument)
-{
- if (bit_width > 64)
- return false; // Scalar can't hold large integer arguments
-
- if (current_argument_register < 6)
- {
- scalar = thread.GetRegisterContext()->ReadRegisterAsUnsigned(argument_register_ids[current_argument_register], 0);
- current_argument_register++;
- if (is_signed)
- scalar.SignExtend (bit_width);
- }
- else
- {
- uint32_t byte_size = (bit_width + (8-1))/8;
- Error error;
- if (thread.GetProcess()->ReadScalarIntegerFromMemory(current_stack_argument, byte_size, is_signed, scalar, error))
- {
- current_stack_argument += byte_size;
- return true;
- }
- return false;
+static bool ReadIntegerArgument(Scalar &scalar, unsigned int bit_width,
+ bool is_signed, Thread &thread,
+ uint32_t *argument_register_ids,
+ unsigned int ¤t_argument_register,
+ addr_t ¤t_stack_argument) {
+ if (bit_width > 64)
+ return false; // Scalar can't hold large integer arguments
+
+ if (current_argument_register < 6) {
+ scalar = thread.GetRegisterContext()->ReadRegisterAsUnsigned(
+ argument_register_ids[current_argument_register], 0);
+ current_argument_register++;
+ if (is_signed)
+ scalar.SignExtend(bit_width);
+ } else {
+ uint32_t byte_size = (bit_width + (8 - 1)) / 8;
+ Error error;
+ if (thread.GetProcess()->ReadScalarIntegerFromMemory(
+ current_stack_argument, byte_size, is_signed, scalar, error)) {
+ current_stack_argument += byte_size;
+ return true;
}
- return true;
+ return false;
+ }
+ return true;
}
-bool
-ABISysV_ppc64::GetArgumentValues (Thread &thread,
- ValueList &values) const
-{
- unsigned int num_values = values.GetSize();
- unsigned int value_index;
+bool ABISysV_ppc64::GetArgumentValues(Thread &thread, ValueList &values) const {
+ unsigned int num_values = values.GetSize();
+ unsigned int value_index;
- // Extract the register context so we can read arguments from registers
+ // Extract the register context so we can read arguments from registers
- RegisterContext *reg_ctx = thread.GetRegisterContext().get();
+ RegisterContext *reg_ctx = thread.GetRegisterContext().get();
- if (!reg_ctx)
- return false;
+ if (!reg_ctx)
+ return false;
- // Get the pointer to the first stack argument so we have a place to start
- // when reading data
+ // Get the pointer to the first stack argument so we have a place to start
+ // when reading data
- addr_t sp = reg_ctx->GetSP(0);
+ addr_t sp = reg_ctx->GetSP(0);
- if (!sp)
- return false;
+ if (!sp)
+ return false;
- addr_t current_stack_argument = sp + 48; // jump over return address
+ addr_t current_stack_argument = sp + 48; // jump over return address
- uint32_t argument_register_ids[8];
+ uint32_t argument_register_ids[8];
- argument_register_ids[0] = reg_ctx->GetRegisterInfo (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG1)->kinds[eRegisterKindLLDB];
- argument_register_ids[1] = reg_ctx->GetRegisterInfo (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG2)->kinds[eRegisterKindLLDB];
- argument_register_ids[2] = reg_ctx->GetRegisterInfo (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG3)->kinds[eRegisterKindLLDB];
- argument_register_ids[3] = reg_ctx->GetRegisterInfo (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG4)->kinds[eRegisterKindLLDB];
- argument_register_ids[4] = reg_ctx->GetRegisterInfo (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG5)->kinds[eRegisterKindLLDB];
- argument_register_ids[5] = reg_ctx->GetRegisterInfo (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG6)->kinds[eRegisterKindLLDB];
- argument_register_ids[6] = reg_ctx->GetRegisterInfo (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG7)->kinds[eRegisterKindLLDB];
- argument_register_ids[7] = reg_ctx->GetRegisterInfo (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG8)->kinds[eRegisterKindLLDB];
-
- unsigned int current_argument_register = 0;
-
- for (value_index = 0;
- value_index < num_values;
- ++value_index)
- {
- Value *value = values.GetValueAtIndex(value_index);
+ argument_register_ids[0] =
+ reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG1)
+ ->kinds[eRegisterKindLLDB];
+ argument_register_ids[1] =
+ reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG2)
+ ->kinds[eRegisterKindLLDB];
+ argument_register_ids[2] =
+ reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG3)
+ ->kinds[eRegisterKindLLDB];
+ argument_register_ids[3] =
+ reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG4)
+ ->kinds[eRegisterKindLLDB];
+ argument_register_ids[4] =
+ reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG5)
+ ->kinds[eRegisterKindLLDB];
+ argument_register_ids[5] =
+ reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG6)
+ ->kinds[eRegisterKindLLDB];
+ argument_register_ids[6] =
+ reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG7)
+ ->kinds[eRegisterKindLLDB];
+ argument_register_ids[7] =
+ reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG8)
+ ->kinds[eRegisterKindLLDB];
+
+ unsigned int current_argument_register = 0;
+
+ for (value_index = 0; value_index < num_values; ++value_index) {
+ Value *value = values.GetValueAtIndex(value_index);
+
+ if (!value)
+ return false;
+
+ // We currently only support extracting values with Clang QualTypes.
+ // Do we care about others?
+ CompilerType compiler_type = value->GetCompilerType();
+ if (!compiler_type)
+ return false;
+ bool is_signed;
- if (!value)
- return false;
+ if (compiler_type.IsIntegerOrEnumerationType(is_signed)) {
+ ReadIntegerArgument(value->GetScalar(), compiler_type.GetBitSize(&thread),
+ is_signed, thread, argument_register_ids,
+ current_argument_register, current_stack_argument);
+ } else if (compiler_type.IsPointerType()) {
+ ReadIntegerArgument(value->GetScalar(), compiler_type.GetBitSize(&thread),
+ false, thread, argument_register_ids,
+ current_argument_register, current_stack_argument);
+ }
+ }
+
+ return true;
+}
+
+Error ABISysV_ppc64::SetReturnValueObject(lldb::StackFrameSP &frame_sp,
+ lldb::ValueObjectSP &new_value_sp) {
+ Error error;
+ if (!new_value_sp) {
+ error.SetErrorString("Empty value object for return value.");
+ return error;
+ }
- // We currently only support extracting values with Clang QualTypes.
- // Do we care about others?
- CompilerType compiler_type = value->GetCompilerType();
- if (!compiler_type)
- return false;
- bool is_signed;
+ CompilerType compiler_type = new_value_sp->GetCompilerType();
+ if (!compiler_type) {
+ error.SetErrorString("Null clang type for return value.");
+ return error;
+ }
- if (compiler_type.IsIntegerOrEnumerationType (is_signed))
- {
- ReadIntegerArgument(value->GetScalar(),
- compiler_type.GetBitSize(&thread),
- is_signed,
- thread,
- argument_register_ids,
- current_argument_register,
- current_stack_argument);
- }
- else if (compiler_type.IsPointerType ())
- {
- ReadIntegerArgument(value->GetScalar(),
- compiler_type.GetBitSize(&thread),
- false,
- thread,
- argument_register_ids,
- current_argument_register,
- current_stack_argument);
- }
- }
+ Thread *thread = frame_sp->GetThread().get();
- return true;
-}
+ bool is_signed;
+ uint32_t count;
+ bool is_complex;
+
+ RegisterContext *reg_ctx = thread->GetRegisterContext().get();
+
+ bool set_it_simple = false;
+ if (compiler_type.IsIntegerOrEnumerationType(is_signed) ||
+ compiler_type.IsPointerType()) {
+ const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoByName("r3", 0);
+
+ DataExtractor data;
+ Error data_error;
+ size_t num_bytes = new_value_sp->GetData(data, data_error);
+ if (data_error.Fail()) {
+ error.SetErrorStringWithFormat(
+ "Couldn't convert return value to raw data: %s",
+ data_error.AsCString());
+ return error;
+ }
+ lldb::offset_t offset = 0;
+ if (num_bytes <= 8) {
+ uint64_t raw_value = data.GetMaxU64(&offset, num_bytes);
+
+ if (reg_ctx->WriteRegisterFromUnsigned(reg_info, raw_value))
+ set_it_simple = true;
+ } else {
+ error.SetErrorString("We don't support returning longer than 64 bit "
+ "integer values at present.");
+ }
+ } else if (compiler_type.IsFloatingPointType(count, is_complex)) {
+ if (is_complex)
+ error.SetErrorString(
+ "We don't support returning complex values at present");
+ else {
+ size_t bit_width = compiler_type.GetBitSize(frame_sp.get());
+ if (bit_width <= 64) {
+ DataExtractor data;
+ Error data_error;
+ size_t num_bytes = new_value_sp->GetData(data, data_error);
+ if (data_error.Fail()) {
+ error.SetErrorStringWithFormat(
+ "Couldn't convert return value to raw data: %s",
+ data_error.AsCString());
+ return error;
+ }
+
+ unsigned char buffer[16];
+ ByteOrder byte_order = data.GetByteOrder();
+
+ data.CopyByteOrderedData(0, num_bytes, buffer, 16, byte_order);
+ set_it_simple = true;
+ } else {
+ // FIXME - don't know how to do 80 bit long doubles yet.
+ error.SetErrorString(
+ "We don't support returning float values > 64 bits at present");
+ }
+ }
+ }
+
+ if (!set_it_simple) {
+ // Okay we've got a structure or something that doesn't fit in a simple
+ // register.
+ // We should figure out where it really goes, but we don't support this yet.
+ error.SetErrorString("We only support setting simple integer and float "
+ "return types at present.");
+ }
+
+ return error;
+}
+
+ValueObjectSP ABISysV_ppc64::GetReturnValueObjectSimple(
+ Thread &thread, CompilerType &return_compiler_type) const {
+ ValueObjectSP return_valobj_sp;
+ Value value;
-Error
-ABISysV_ppc64::SetReturnValueObject(lldb::StackFrameSP &frame_sp, lldb::ValueObjectSP &new_value_sp)
-{
- Error error;
- if (!new_value_sp)
- {
- error.SetErrorString("Empty value object for return value.");
- return error;
- }
+ if (!return_compiler_type)
+ return return_valobj_sp;
- CompilerType compiler_type = new_value_sp->GetCompilerType();
- if (!compiler_type)
- {
- error.SetErrorString ("Null clang type for return value.");
- return error;
- }
+ // value.SetContext (Value::eContextTypeClangType, return_value_type);
+ value.SetCompilerType(return_compiler_type);
- Thread *thread = frame_sp->GetThread().get();
+ RegisterContext *reg_ctx = thread.GetRegisterContext().get();
+ if (!reg_ctx)
+ return return_valobj_sp;
- bool is_signed;
- uint32_t count;
- bool is_complex;
+ const uint32_t type_flags = return_compiler_type.GetTypeInfo();
+ if (type_flags & eTypeIsScalar) {
+ value.SetValueType(Value::eValueTypeScalar);
+
+ bool success = false;
+ if (type_flags & eTypeIsInteger) {
+ // Extract the register context so we can read arguments from registers
+
+ const size_t byte_size = return_compiler_type.GetByteSize(nullptr);
+ uint64_t raw_value = thread.GetRegisterContext()->ReadRegisterAsUnsigned(
+ reg_ctx->GetRegisterInfoByName("r3", 0), 0);
+ const bool is_signed = (type_flags & eTypeIsSigned) != 0;
+ switch (byte_size) {
+ default:
+ break;
- RegisterContext *reg_ctx = thread->GetRegisterContext().get();
+ case sizeof(uint64_t):
+ if (is_signed)
+ value.GetScalar() = (int64_t)(raw_value);
+ else
+ value.GetScalar() = (uint64_t)(raw_value);
+ success = true;
+ break;
- bool set_it_simple = false;
- if (compiler_type.IsIntegerOrEnumerationType (is_signed) || compiler_type.IsPointerType())
- {
- const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoByName("r3", 0);
+ case sizeof(uint32_t):
+ if (is_signed)
+ value.GetScalar() = (int32_t)(raw_value & UINT32_MAX);
+ else
+ value.GetScalar() = (uint32_t)(raw_value & UINT32_MAX);
+ success = true;
+ break;
- DataExtractor data;
- Error data_error;
- size_t num_bytes = new_value_sp->GetData(data, data_error);
- if (data_error.Fail())
- {
- error.SetErrorStringWithFormat("Couldn't convert return value to raw data: %s", data_error.AsCString());
- return error;
- }
- lldb::offset_t offset = 0;
- if (num_bytes <= 8)
- {
- uint64_t raw_value = data.GetMaxU64(&offset, num_bytes);
+ case sizeof(uint16_t):
+ if (is_signed)
+ value.GetScalar() = (int16_t)(raw_value & UINT16_MAX);
+ else
+ value.GetScalar() = (uint16_t)(raw_value & UINT16_MAX);
+ success = true;
+ break;
- if (reg_ctx->WriteRegisterFromUnsigned (reg_info, raw_value))
- set_it_simple = true;
- }
+ case sizeof(uint8_t):
+ if (is_signed)
+ value.GetScalar() = (int8_t)(raw_value & UINT8_MAX);
else
- {
- error.SetErrorString("We don't support returning longer than 64 bit integer values at present.");
+ value.GetScalar() = (uint8_t)(raw_value & UINT8_MAX);
+ success = true;
+ break;
+ }
+ } else if (type_flags & eTypeIsFloat) {
+ if (type_flags & eTypeIsComplex) {
+ // Don't handle complex yet.
+ } else {
+ const size_t byte_size = return_compiler_type.GetByteSize(nullptr);
+ if (byte_size <= sizeof(long double)) {
+ const RegisterInfo *f1_info = reg_ctx->GetRegisterInfoByName("f1", 0);
+ RegisterValue f1_value;
+ if (reg_ctx->ReadRegister(f1_info, f1_value)) {
+ DataExtractor data;
+ if (f1_value.GetData(data)) {
+ lldb::offset_t offset = 0;
+ if (byte_size == sizeof(float)) {
+ value.GetScalar() = (float)data.GetFloat(&offset);
+ success = true;
+ } else if (byte_size == sizeof(double)) {
+ value.GetScalar() = (double)data.GetDouble(&offset);
+ success = true;
+ }
+ }
+ }
}
+ }
}
- else if (compiler_type.IsFloatingPointType (count, is_complex))
- {
- if (is_complex)
- error.SetErrorString ("We don't support returning complex values at present");
- else
- {
- size_t bit_width = compiler_type.GetBitSize(frame_sp.get());
- if (bit_width <= 64)
- {
- DataExtractor data;
- Error data_error;
- size_t num_bytes = new_value_sp->GetData(data, data_error);
- if (data_error.Fail())
- {
- error.SetErrorStringWithFormat("Couldn't convert return value to raw data: %s", data_error.AsCString());
- return error;
- }
- unsigned char buffer[16];
- ByteOrder byte_order = data.GetByteOrder();
-
- data.CopyByteOrderedData (0, num_bytes, buffer, 16, byte_order);
- set_it_simple = true;
- }
- else
- {
- // FIXME - don't know how to do 80 bit long doubles yet.
- error.SetErrorString ("We don't support returning float values > 64 bits at present");
+ if (success)
+ return_valobj_sp = ValueObjectConstResult::Create(
+ thread.GetStackFrameAtIndex(0).get(), value, ConstString(""));
+ } else if (type_flags & eTypeIsPointer) {
+ unsigned r3_id =
+ reg_ctx->GetRegisterInfoByName("r3", 0)->kinds[eRegisterKindLLDB];
+ value.GetScalar() =
+ (uint64_t)thread.GetRegisterContext()->ReadRegisterAsUnsigned(r3_id, 0);
+ value.SetValueType(Value::eValueTypeScalar);
+ return_valobj_sp = ValueObjectConstResult::Create(
+ thread.GetStackFrameAtIndex(0).get(), value, ConstString(""));
+ } else if (type_flags & eTypeIsVector) {
+ const size_t byte_size = return_compiler_type.GetByteSize(nullptr);
+ if (byte_size > 0) {
+ const RegisterInfo *altivec_reg = reg_ctx->GetRegisterInfoByName("v2", 0);
+ if (altivec_reg) {
+ if (byte_size <= altivec_reg->byte_size) {
+ ProcessSP process_sp(thread.GetProcess());
+ if (process_sp) {
+ std::unique_ptr<DataBufferHeap> heap_data_ap(
+ new DataBufferHeap(byte_size, 0));
+ const ByteOrder byte_order = process_sp->GetByteOrder();
+ RegisterValue reg_value;
+ if (reg_ctx->ReadRegister(altivec_reg, reg_value)) {
+ Error error;
+ if (reg_value.GetAsMemoryData(
+ altivec_reg, heap_data_ap->GetBytes(),
+ heap_data_ap->GetByteSize(), byte_order, error)) {
+ DataExtractor data(DataBufferSP(heap_data_ap.release()),
+ byte_order, process_sp->GetTarget()
+ .GetArchitecture()
+ .GetAddressByteSize());
+ return_valobj_sp = ValueObjectConstResult::Create(
+ &thread, return_compiler_type, ConstString(""), data);
+ }
}
+ }
}
+ }
}
+ }
- if (!set_it_simple)
- {
- // Okay we've got a structure or something that doesn't fit in a simple register.
- // We should figure out where it really goes, but we don't support this yet.
- error.SetErrorString ("We only support setting simple integer and float return types at present.");
- }
-
- return error;
+ return return_valobj_sp;
}
-ValueObjectSP
-ABISysV_ppc64::GetReturnValueObjectSimple (Thread &thread,
- CompilerType &return_compiler_type) const
-{
- ValueObjectSP return_valobj_sp;
- Value value;
-
- if (!return_compiler_type)
- return return_valobj_sp;
-
- //value.SetContext (Value::eContextTypeClangType, return_value_type);
- value.SetCompilerType (return_compiler_type);
-
- RegisterContext *reg_ctx = thread.GetRegisterContext().get();
- if (!reg_ctx)
- return return_valobj_sp;
-
- const uint32_t type_flags = return_compiler_type.GetTypeInfo ();
- if (type_flags & eTypeIsScalar)
- {
- value.SetValueType(Value::eValueTypeScalar);
+ValueObjectSP ABISysV_ppc64::GetReturnValueObjectImpl(
+ Thread &thread, CompilerType &return_compiler_type) const {
+ ValueObjectSP return_valobj_sp;
- bool success = false;
- if (type_flags & eTypeIsInteger)
- {
- // Extract the register context so we can read arguments from registers
+ if (!return_compiler_type)
+ return return_valobj_sp;
- const size_t byte_size = return_compiler_type.GetByteSize(nullptr);
- uint64_t raw_value = thread.GetRegisterContext()->ReadRegisterAsUnsigned(reg_ctx->GetRegisterInfoByName("r3", 0), 0);
- const bool is_signed = (type_flags & eTypeIsSigned) != 0;
- switch (byte_size)
- {
- default:
- break;
-
- case sizeof(uint64_t):
- if (is_signed)
- value.GetScalar() = (int64_t)(raw_value);
- else
- value.GetScalar() = (uint64_t)(raw_value);
- success = true;
- break;
+ ExecutionContext exe_ctx(thread.shared_from_this());
+ return_valobj_sp = GetReturnValueObjectSimple(thread, return_compiler_type);
+ if (return_valobj_sp)
+ return return_valobj_sp;
- case sizeof(uint32_t):
- if (is_signed)
- value.GetScalar() = (int32_t)(raw_value & UINT32_MAX);
- else
- value.GetScalar() = (uint32_t)(raw_value & UINT32_MAX);
- success = true;
- break;
+ RegisterContextSP reg_ctx_sp = thread.GetRegisterContext();
+ if (!reg_ctx_sp)
+ return return_valobj_sp;
- case sizeof(uint16_t):
- if (is_signed)
- value.GetScalar() = (int16_t)(raw_value & UINT16_MAX);
- else
- value.GetScalar() = (uint16_t)(raw_value & UINT16_MAX);
- success = true;
- break;
+ const size_t bit_width = return_compiler_type.GetBitSize(&thread);
+ if (return_compiler_type.IsAggregateType()) {
+ Target *target = exe_ctx.GetTargetPtr();
+ bool is_memory = true;
+ if (bit_width <= 128) {
+ ByteOrder target_byte_order = target->GetArchitecture().GetByteOrder();
+ DataBufferSP data_sp(new DataBufferHeap(16, 0));
+ DataExtractor return_ext(data_sp, target_byte_order,
+ target->GetArchitecture().GetAddressByteSize());
+
+ const RegisterInfo *r3_info = reg_ctx_sp->GetRegisterInfoByName("r3", 0);
+ const RegisterInfo *rdx_info =
+ reg_ctx_sp->GetRegisterInfoByName("rdx", 0);
+
+ RegisterValue r3_value, rdx_value;
+ reg_ctx_sp->ReadRegister(r3_info, r3_value);
+ reg_ctx_sp->ReadRegister(rdx_info, rdx_value);
+
+ DataExtractor r3_data, rdx_data;
+
+ r3_value.GetData(r3_data);
+ rdx_value.GetData(rdx_data);
+
+ uint32_t fp_bytes =
+ 0; // Tracks how much of the xmm registers we've consumed so far
+ uint32_t integer_bytes =
+ 0; // Tracks how much of the r3/rds registers we've consumed so far
+
+ const uint32_t num_children = return_compiler_type.GetNumFields();
+
+ // Since we are in the small struct regime, assume we are not in memory.
+ is_memory = false;
+
+ for (uint32_t idx = 0; idx < num_children; idx++) {
+ std::string name;
+ uint64_t field_bit_offset = 0;
+ bool is_signed;
+ bool is_complex;
+ uint32_t count;
- case sizeof(uint8_t):
- if (is_signed)
- value.GetScalar() = (int8_t)(raw_value & UINT8_MAX);
- else
- value.GetScalar() = (uint8_t)(raw_value & UINT8_MAX);
- success = true;
- break;
+ CompilerType field_compiler_type = return_compiler_type.GetFieldAtIndex(
+ idx, name, &field_bit_offset, nullptr, nullptr);
+ const size_t field_bit_width = field_compiler_type.GetBitSize(&thread);
+
+ // If there are any unaligned fields, this is stored in memory.
+ if (field_bit_offset % field_bit_width != 0) {
+ is_memory = true;
+ break;
+ }
+
+ uint32_t field_byte_width = field_bit_width / 8;
+ uint32_t field_byte_offset = field_bit_offset / 8;
+
+ DataExtractor *copy_from_extractor = nullptr;
+ uint32_t copy_from_offset = 0;
+
+ if (field_compiler_type.IsIntegerOrEnumerationType(is_signed) ||
+ field_compiler_type.IsPointerType()) {
+ if (integer_bytes < 8) {
+ if (integer_bytes + field_byte_width <= 8) {
+ // This is in RAX, copy from register to our result structure:
+ copy_from_extractor = &r3_data;
+ copy_from_offset = integer_bytes;
+ integer_bytes += field_byte_width;
+ } else {
+ // The next field wouldn't fit in the remaining space, so we
+ // pushed it to rdx.
+ copy_from_extractor = &rdx_data;
+ copy_from_offset = 0;
+ integer_bytes = 8 + field_byte_width;
}
- }
- else if (type_flags & eTypeIsFloat)
- {
- if (type_flags & eTypeIsComplex)
- {
- // Don't handle complex yet.
- }
- else
- {
- const size_t byte_size = return_compiler_type.GetByteSize(nullptr);
- if (byte_size <= sizeof(long double))
- {
- const RegisterInfo *f1_info = reg_ctx->GetRegisterInfoByName("f1", 0);
- RegisterValue f1_value;
- if (reg_ctx->ReadRegister (f1_info, f1_value))
- {
- DataExtractor data;
- if (f1_value.GetData(data))
- {
- lldb::offset_t offset = 0;
- if (byte_size == sizeof(float))
- {
- value.GetScalar() = (float) data.GetFloat(&offset);
- success = true;
- }
- else if (byte_size == sizeof(double))
- {
- value.GetScalar() = (double) data.GetDouble(&offset);
- success = true;
- }
- }
- }
+ } else if (integer_bytes + field_byte_width <= 16) {
+ copy_from_extractor = &rdx_data;
+ copy_from_offset = integer_bytes - 8;
+ integer_bytes += field_byte_width;
+ } else {
+ // The last field didn't fit. I can't see how that would happen w/o
+ // the overall size being
+ // greater than 16 bytes. For now, return a nullptr return value
+ // object.
+ return return_valobj_sp;
+ }
+ } else if (field_compiler_type.IsFloatingPointType(count, is_complex)) {
+ // Structs with long doubles are always passed in memory.
+ if (field_bit_width == 128) {
+ is_memory = true;
+ break;
+ } else if (field_bit_width == 64) {
+ copy_from_offset = 0;
+ fp_bytes += field_byte_width;
+ } else if (field_bit_width == 32) {
+ // This one is kind of complicated. If we are in an "eightbyte"
+ // with another float, we'll
+ // be stuffed into an xmm register with it. If we are in an
+ // "eightbyte" with one or more ints,
+ // then we will be stuffed into the appropriate GPR with them.
+ bool in_gpr;
+ if (field_byte_offset % 8 == 0) {
+ // We are at the beginning of one of the eightbytes, so check the
+ // next element (if any)
+ if (idx == num_children - 1)
+ in_gpr = false;
+ else {
+ uint64_t next_field_bit_offset = 0;
+ CompilerType next_field_compiler_type =
+ return_compiler_type.GetFieldAtIndex(idx + 1, name,
+ &next_field_bit_offset,
+ nullptr, nullptr);
+ if (next_field_compiler_type.IsIntegerOrEnumerationType(
+ is_signed))
+ in_gpr = true;
+ else {
+ copy_from_offset = 0;
+ in_gpr = false;
}
+ }
+ } else if (field_byte_offset % 4 == 0) {
+ // We are inside of an eightbyte, so see if the field before us is
+ // floating point:
+ // This could happen if somebody put padding in the structure.
+ if (idx == 0)
+ in_gpr = false;
+ else {
+ uint64_t prev_field_bit_offset = 0;
+ CompilerType prev_field_compiler_type =
+ return_compiler_type.GetFieldAtIndex(idx - 1, name,
+ &prev_field_bit_offset,
+ nullptr, nullptr);
+ if (prev_field_compiler_type.IsIntegerOrEnumerationType(
+ is_signed))
+ in_gpr = true;
+ else {
+ copy_from_offset = 4;
+ in_gpr = false;
+ }
+ }
+ } else {
+ is_memory = true;
+ continue;
}
- }
- if (success)
- return_valobj_sp = ValueObjectConstResult::Create (thread.GetStackFrameAtIndex(0).get(),
- value,
- ConstString(""));
- }
- else if (type_flags & eTypeIsPointer)
- {
- unsigned r3_id = reg_ctx->GetRegisterInfoByName("r3", 0)->kinds[eRegisterKindLLDB];
- value.GetScalar() = (uint64_t)thread.GetRegisterContext()->ReadRegisterAsUnsigned(r3_id, 0);
- value.SetValueType(Value::eValueTypeScalar);
- return_valobj_sp = ValueObjectConstResult::Create (thread.GetStackFrameAtIndex(0).get(),
- value,
- ConstString(""));
- }
- else if (type_flags & eTypeIsVector)
- {
- const size_t byte_size = return_compiler_type.GetByteSize(nullptr);
- if (byte_size > 0)
- {
- const RegisterInfo *altivec_reg = reg_ctx->GetRegisterInfoByName("v2", 0);
- if (altivec_reg)
- {
- if (byte_size <= altivec_reg->byte_size)
- {
- ProcessSP process_sp (thread.GetProcess());
- if (process_sp)
- {
- std::unique_ptr<DataBufferHeap> heap_data_ap (new DataBufferHeap(byte_size, 0));
- const ByteOrder byte_order = process_sp->GetByteOrder();
- RegisterValue reg_value;
- if (reg_ctx->ReadRegister(altivec_reg, reg_value))
- {
- Error error;
- if (reg_value.GetAsMemoryData (altivec_reg,
- heap_data_ap->GetBytes(),
- heap_data_ap->GetByteSize(),
- byte_order,
- error))
- {
- DataExtractor data (DataBufferSP (heap_data_ap.release()),
- byte_order,
- process_sp->GetTarget().GetArchitecture().GetAddressByteSize());
- return_valobj_sp = ValueObjectConstResult::Create (&thread,
- return_compiler_type,
- ConstString(""),
- data);
- }
- }
- }
- }
+ // Okay, we've figured out whether we are in GPR or XMM, now figure
+ // out which one.
+ if (in_gpr) {
+ if (integer_bytes < 8) {
+ // This is in RAX, copy from register to our result structure:
+ copy_from_extractor = &r3_data;
+ copy_from_offset = integer_bytes;
+ integer_bytes += field_byte_width;
+ } else {
+ copy_from_extractor = &rdx_data;
+ copy_from_offset = integer_bytes - 8;
+ integer_bytes += field_byte_width;
+ }
+ } else {
+ fp_bytes += field_byte_width;
}
+ }
}
- }
- return return_valobj_sp;
-}
+ // These two tests are just sanity checks. If I somehow get the
+ // type calculation wrong above it is better to just return nothing
+ // than to assert or crash.
+ if (!copy_from_extractor)
+ return return_valobj_sp;
+ if (copy_from_offset + field_byte_width >
+ copy_from_extractor->GetByteSize())
+ return return_valobj_sp;
-ValueObjectSP
-ABISysV_ppc64::GetReturnValueObjectImpl (Thread &thread, CompilerType &return_compiler_type) const
-{
- ValueObjectSP return_valobj_sp;
-
- if (!return_compiler_type)
- return return_valobj_sp;
-
- ExecutionContext exe_ctx (thread.shared_from_this());
- return_valobj_sp = GetReturnValueObjectSimple(thread, return_compiler_type);
- if (return_valobj_sp)
- return return_valobj_sp;
-
- RegisterContextSP reg_ctx_sp = thread.GetRegisterContext();
- if (!reg_ctx_sp)
- return return_valobj_sp;
+ copy_from_extractor->CopyByteOrderedData(
+ copy_from_offset, field_byte_width,
+ data_sp->GetBytes() + field_byte_offset, field_byte_width,
+ target_byte_order);
+ }
- const size_t bit_width = return_compiler_type.GetBitSize(&thread);
- if (return_compiler_type.IsAggregateType())
- {
- Target *target = exe_ctx.GetTargetPtr();
- bool is_memory = true;
- if (bit_width <= 128)
- {
- ByteOrder target_byte_order = target->GetArchitecture().GetByteOrder();
- DataBufferSP data_sp (new DataBufferHeap(16, 0));
- DataExtractor return_ext (data_sp,
- target_byte_order,
- target->GetArchitecture().GetAddressByteSize());
-
- const RegisterInfo *r3_info = reg_ctx_sp->GetRegisterInfoByName("r3", 0);
- const RegisterInfo *rdx_info = reg_ctx_sp->GetRegisterInfoByName("rdx", 0);
-
- RegisterValue r3_value, rdx_value;
- reg_ctx_sp->ReadRegister (r3_info, r3_value);
- reg_ctx_sp->ReadRegister (rdx_info, rdx_value);
-
- DataExtractor r3_data, rdx_data;
-
- r3_value.GetData(r3_data);
- rdx_value.GetData(rdx_data);
-
- uint32_t fp_bytes = 0; // Tracks how much of the xmm registers we've consumed so far
- uint32_t integer_bytes = 0; // Tracks how much of the r3/rds registers we've consumed so far
-
- const uint32_t num_children = return_compiler_type.GetNumFields ();
-
- // Since we are in the small struct regime, assume we are not in memory.
- is_memory = false;
-
- for (uint32_t idx = 0; idx < num_children; idx++)
- {
- std::string name;
- uint64_t field_bit_offset = 0;
- bool is_signed;
- bool is_complex;
- uint32_t count;
-
- CompilerType field_compiler_type = return_compiler_type.GetFieldAtIndex(idx, name, &field_bit_offset, nullptr, nullptr);
- const size_t field_bit_width = field_compiler_type.GetBitSize(&thread);
-
- // If there are any unaligned fields, this is stored in memory.
- if (field_bit_offset % field_bit_width != 0)
- {
- is_memory = true;
- break;
- }
+ if (!is_memory) {
+ // The result is in our data buffer. Let's make a variable object out
+ // of it:
+ return_valobj_sp = ValueObjectConstResult::Create(
+ &thread, return_compiler_type, ConstString(""), return_ext);
+ }
+ }
- uint32_t field_byte_width = field_bit_width/8;
- uint32_t field_byte_offset = field_bit_offset/8;
+ // FIXME: This is just taking a guess, r3 may very well no longer hold the
+ // return storage location.
+ // If we are going to do this right, when we make a new frame we should
+ // check to see if it uses a memory
+ // return, and if we are at the first instruction and if so stash away the
+ // return location. Then we would
+ // only return the memory return value if we know it is valid.
- DataExtractor *copy_from_extractor = nullptr;
- uint32_t copy_from_offset = 0;
+ if (is_memory) {
+ unsigned r3_id =
+ reg_ctx_sp->GetRegisterInfoByName("r3", 0)->kinds[eRegisterKindLLDB];
+ lldb::addr_t storage_addr =
+ (uint64_t)thread.GetRegisterContext()->ReadRegisterAsUnsigned(r3_id,
+ 0);
+ return_valobj_sp = ValueObjectMemory::Create(
+ &thread, "", Address(storage_addr, nullptr), return_compiler_type);
+ }
+ }
- if (field_compiler_type.IsIntegerOrEnumerationType (is_signed) || field_compiler_type.IsPointerType ())
- {
- if (integer_bytes < 8)
- {
- if (integer_bytes + field_byte_width <= 8)
- {
- // This is in RAX, copy from register to our result structure:
- copy_from_extractor = &r3_data;
- copy_from_offset = integer_bytes;
- integer_bytes += field_byte_width;
- }
- else
- {
- // The next field wouldn't fit in the remaining space, so we pushed it to rdx.
- copy_from_extractor = &rdx_data;
- copy_from_offset = 0;
- integer_bytes = 8 + field_byte_width;
-
- }
- }
- else if (integer_bytes + field_byte_width <= 16)
- {
- copy_from_extractor = &rdx_data;
- copy_from_offset = integer_bytes - 8;
- integer_bytes += field_byte_width;
- }
- else
- {
- // The last field didn't fit. I can't see how that would happen w/o the overall size being
- // greater than 16 bytes. For now, return a nullptr return value object.
- return return_valobj_sp;
- }
- }
- else if (field_compiler_type.IsFloatingPointType (count, is_complex))
- {
- // Structs with long doubles are always passed in memory.
- if (field_bit_width == 128)
- {
- is_memory = true;
- break;
- }
- else if (field_bit_width == 64)
- {
- copy_from_offset = 0;
- fp_bytes += field_byte_width;
- }
- else if (field_bit_width == 32)
- {
- // This one is kind of complicated. If we are in an "eightbyte" with another float, we'll
- // be stuffed into an xmm register with it. If we are in an "eightbyte" with one or more ints,
- // then we will be stuffed into the appropriate GPR with them.
- bool in_gpr;
- if (field_byte_offset % 8 == 0)
- {
- // We are at the beginning of one of the eightbytes, so check the next element (if any)
- if (idx == num_children - 1)
- in_gpr = false;
- else
- {
- uint64_t next_field_bit_offset = 0;
- CompilerType next_field_compiler_type = return_compiler_type.GetFieldAtIndex (idx + 1,
- name,
- &next_field_bit_offset,
- nullptr,
- nullptr);
- if (next_field_compiler_type.IsIntegerOrEnumerationType (is_signed))
- in_gpr = true;
- else
- {
- copy_from_offset = 0;
- in_gpr = false;
- }
- }
- }
- else if (field_byte_offset % 4 == 0)
- {
- // We are inside of an eightbyte, so see if the field before us is floating point:
- // This could happen if somebody put padding in the structure.
- if (idx == 0)
- in_gpr = false;
- else
- {
- uint64_t prev_field_bit_offset = 0;
- CompilerType prev_field_compiler_type = return_compiler_type.GetFieldAtIndex (idx - 1,
- name,
- &prev_field_bit_offset,
- nullptr,
- nullptr);
- if (prev_field_compiler_type.IsIntegerOrEnumerationType (is_signed))
- in_gpr = true;
- else
- {
- copy_from_offset = 4;
- in_gpr = false;
- }
- }
- }
- else
- {
- is_memory = true;
- continue;
- }
-
- // Okay, we've figured out whether we are in GPR or XMM, now figure out which one.
- if (in_gpr)
- {
- if (integer_bytes < 8)
- {
- // This is in RAX, copy from register to our result structure:
- copy_from_extractor = &r3_data;
- copy_from_offset = integer_bytes;
- integer_bytes += field_byte_width;
- }
- else
- {
- copy_from_extractor = &rdx_data;
- copy_from_offset = integer_bytes - 8;
- integer_bytes += field_byte_width;
- }
- }
- else
- {
- fp_bytes += field_byte_width;
- }
- }
- }
+ return return_valobj_sp;
+}
- // These two tests are just sanity checks. If I somehow get the
- // type calculation wrong above it is better to just return nothing
- // than to assert or crash.
- if (!copy_from_extractor)
- return return_valobj_sp;
- if (copy_from_offset + field_byte_width > copy_from_extractor->GetByteSize())
- return return_valobj_sp;
-
- copy_from_extractor->CopyByteOrderedData (copy_from_offset,
- field_byte_width,
- data_sp->GetBytes() + field_byte_offset,
- field_byte_width,
- target_byte_order);
- }
+bool ABISysV_ppc64::CreateFunctionEntryUnwindPlan(UnwindPlan &unwind_plan) {
+ unwind_plan.Clear();
+ unwind_plan.SetRegisterKind(eRegisterKindDWARF);
- if (!is_memory)
- {
- // The result is in our data buffer. Let's make a variable object out of it:
- return_valobj_sp = ValueObjectConstResult::Create (&thread,
- return_compiler_type,
- ConstString(""),
- return_ext);
- }
- }
+ uint32_t lr_reg_num = dwarf_lr;
+ uint32_t sp_reg_num = dwarf_r1;
+ uint32_t pc_reg_num = dwarf_pc;
- // FIXME: This is just taking a guess, r3 may very well no longer hold the return storage location.
- // If we are going to do this right, when we make a new frame we should check to see if it uses a memory
- // return, and if we are at the first instruction and if so stash away the return location. Then we would
- // only return the memory return value if we know it is valid.
+ UnwindPlan::RowSP row(new UnwindPlan::Row);
- if (is_memory)
- {
- unsigned r3_id = reg_ctx_sp->GetRegisterInfoByName("r3", 0)->kinds[eRegisterKindLLDB];
- lldb::addr_t storage_addr = (uint64_t)thread.GetRegisterContext()->ReadRegisterAsUnsigned(r3_id, 0);
- return_valobj_sp = ValueObjectMemory::Create(&thread,
- "",
- Address(storage_addr, nullptr),
- return_compiler_type);
- }
- }
+ // Our Call Frame Address is the stack pointer value
+ row->GetCFAValue().SetIsRegisterPlusOffset(sp_reg_num, 0);
- return return_valobj_sp;
-}
+ // The previous PC is in the LR
+ row->SetRegisterLocationToRegister(pc_reg_num, lr_reg_num, true);
+ unwind_plan.AppendRow(row);
-bool
-ABISysV_ppc64::CreateFunctionEntryUnwindPlan (UnwindPlan &unwind_plan)
-{
- unwind_plan.Clear();
- unwind_plan.SetRegisterKind (eRegisterKindDWARF);
+ // All other registers are the same.
- uint32_t lr_reg_num = dwarf_lr;
- uint32_t sp_reg_num = dwarf_r1;
- uint32_t pc_reg_num = dwarf_pc;
+ unwind_plan.SetSourceName("ppc64 at-func-entry default");
+ unwind_plan.SetSourcedFromCompiler(eLazyBoolNo);
- UnwindPlan::RowSP row(new UnwindPlan::Row);
+ return true;
+}
- // Our Call Frame Address is the stack pointer value
- row->GetCFAValue().SetIsRegisterPlusOffset(sp_reg_num, 0);
+bool ABISysV_ppc64::CreateDefaultUnwindPlan(UnwindPlan &unwind_plan) {
+ unwind_plan.Clear();
+ unwind_plan.SetRegisterKind(eRegisterKindDWARF);
- // The previous PC is in the LR
- row->SetRegisterLocationToRegister(pc_reg_num, lr_reg_num, true);
- unwind_plan.AppendRow (row);
+ uint32_t sp_reg_num = dwarf_r1;
+ uint32_t pc_reg_num = dwarf_lr;
- // All other registers are the same.
+ UnwindPlan::RowSP row(new UnwindPlan::Row);
- unwind_plan.SetSourceName ("ppc64 at-func-entry default");
- unwind_plan.SetSourcedFromCompiler (eLazyBoolNo);
+ const int32_t ptr_size = 8;
+ row->GetCFAValue().SetIsRegisterDereferenced(sp_reg_num);
- return true;
-}
+ row->SetRegisterLocationToAtCFAPlusOffset(pc_reg_num, ptr_size * 2, true);
+ row->SetRegisterLocationToIsCFAPlusOffset(sp_reg_num, 0, true);
+ row->SetRegisterLocationToAtCFAPlusOffset(dwarf_cr, ptr_size, true);
-bool
-ABISysV_ppc64::CreateDefaultUnwindPlan (UnwindPlan &unwind_plan)
-{
- unwind_plan.Clear();
- unwind_plan.SetRegisterKind (eRegisterKindDWARF);
-
- uint32_t sp_reg_num = dwarf_r1;
- uint32_t pc_reg_num = dwarf_lr;
-
- UnwindPlan::RowSP row(new UnwindPlan::Row);
-
- const int32_t ptr_size = 8;
- row->GetCFAValue().SetIsRegisterDereferenced(sp_reg_num);
-
- row->SetRegisterLocationToAtCFAPlusOffset(pc_reg_num, ptr_size * 2, true);
- row->SetRegisterLocationToIsCFAPlusOffset(sp_reg_num, 0, true);
- row->SetRegisterLocationToAtCFAPlusOffset(dwarf_cr, ptr_size, true);
-
- unwind_plan.AppendRow (row);
- unwind_plan.SetSourceName ("ppc64 default unwind plan");
- unwind_plan.SetSourcedFromCompiler (eLazyBoolNo);
- unwind_plan.SetUnwindPlanValidAtAllInstructions (eLazyBoolNo);
- unwind_plan.SetReturnAddressRegister(dwarf_lr);
- return true;
+ unwind_plan.AppendRow(row);
+ unwind_plan.SetSourceName("ppc64 default unwind plan");
+ unwind_plan.SetSourcedFromCompiler(eLazyBoolNo);
+ unwind_plan.SetUnwindPlanValidAtAllInstructions(eLazyBoolNo);
+ unwind_plan.SetReturnAddressRegister(dwarf_lr);
+ return true;
}
-bool
-ABISysV_ppc64::RegisterIsVolatile (const RegisterInfo *reg_info)
-{
- return !RegisterIsCalleeSaved (reg_info);
+bool ABISysV_ppc64::RegisterIsVolatile(const RegisterInfo *reg_info) {
+ return !RegisterIsCalleeSaved(reg_info);
}
// See "Register Usage" in the
// "System V Application Binary Interface"
// "64-bit PowerPC ELF Application Binary Interface Supplement"
-// current version is 1.9 released 2004 at http://refspecs.linuxfoundation.org/ELF/ppc64/PPC-elf64abi-1.9.pdf
-
-bool
-ABISysV_ppc64::RegisterIsCalleeSaved (const RegisterInfo *reg_info)
-{
- if (reg_info)
- {
- // Preserved registers are :
- // r1,r2,r13-r31
- // cr2-cr4 (partially preserved)
- // f14-f31 (not yet)
- // v20-v31 (not yet)
- // vrsave (not yet)
-
- const char *name = reg_info->name;
- if (name[0] == 'r')
- {
- if ((name[1] == '1' || name[1] == '2') && name[2] == '\0')
- return true;
- if (name[1] == '1' && name[2] > '2')
- return true;
- if ((name[1] == '2' || name[1] == '3') && name[2] != '\0')
- return true;
- }
+// current version is 1.9 released 2004 at
+// http://refspecs.linuxfoundation.org/ELF/ppc64/PPC-elf64abi-1.9.pdf
- if (name[0] == 'f' && name[1] >= '0' && name[2] <= '9')
- {
- if (name[2] == '\0')
- return false;
- if (name[1] == '1' && name[2] >= '4')
- return true;
- if ((name[1] == '2' || name[1] == '3') && name[2] != '\0')
- return true;
- }
+bool ABISysV_ppc64::RegisterIsCalleeSaved(const RegisterInfo *reg_info) {
+ if (reg_info) {
+ // Preserved registers are :
+ // r1,r2,r13-r31
+ // cr2-cr4 (partially preserved)
+ // f14-f31 (not yet)
+ // v20-v31 (not yet)
+ // vrsave (not yet)
+
+ const char *name = reg_info->name;
+ if (name[0] == 'r') {
+ if ((name[1] == '1' || name[1] == '2') && name[2] == '\0')
+ return true;
+ if (name[1] == '1' && name[2] > '2')
+ return true;
+ if ((name[1] == '2' || name[1] == '3') && name[2] != '\0')
+ return true;
+ }
- if (name[0] == 's' && name[1] == 'p' && name[2] == '\0') // sp
- return true;
- if (name[0] == 'f' && name[1] == 'p' && name[2] == '\0') // fp
- return true;
- if (name[0] == 'p' && name[1] == 'c' && name[2] == '\0') // pc
- return true;
+ if (name[0] == 'f' && name[1] >= '0' && name[2] <= '9') {
+ if (name[2] == '\0')
+ return false;
+ if (name[1] == '1' && name[2] >= '4')
+ return true;
+ if ((name[1] == '2' || name[1] == '3') && name[2] != '\0')
+ return true;
}
- return false;
+
+ if (name[0] == 's' && name[1] == 'p' && name[2] == '\0') // sp
+ return true;
+ if (name[0] == 'f' && name[1] == 'p' && name[2] == '\0') // fp
+ return true;
+ if (name[0] == 'p' && name[1] == 'c' && name[2] == '\0') // pc
+ return true;
+ }
+ return false;
}
-void
-ABISysV_ppc64::Initialize()
-{
- PluginManager::RegisterPlugin (GetPluginNameStatic(),
- "System V ABI for ppc64 targets",
- CreateInstance);
+void ABISysV_ppc64::Initialize() {
+ PluginManager::RegisterPlugin(
+ GetPluginNameStatic(), "System V ABI for ppc64 targets", CreateInstance);
}
-void
-ABISysV_ppc64::Terminate()
-{
- PluginManager::UnregisterPlugin (CreateInstance);
+void ABISysV_ppc64::Terminate() {
+ PluginManager::UnregisterPlugin(CreateInstance);
}
-lldb_private::ConstString
-ABISysV_ppc64::GetPluginNameStatic()
-{
- static ConstString g_name("sysv-ppc64");
- return g_name;
+lldb_private::ConstString ABISysV_ppc64::GetPluginNameStatic() {
+ static ConstString g_name("sysv-ppc64");
+ return g_name;
}
//------------------------------------------------------------------
// PluginInterface protocol
//------------------------------------------------------------------
-lldb_private::ConstString
-ABISysV_ppc64::GetPluginName()
-{
- return GetPluginNameStatic();
+lldb_private::ConstString ABISysV_ppc64::GetPluginName() {
+ return GetPluginNameStatic();
}
-uint32_t
-ABISysV_ppc64::GetPluginVersion()
-{
- return 1;
-}
+uint32_t ABISysV_ppc64::GetPluginVersion() { return 1; }
Modified: lldb/trunk/source/Plugins/ABI/SysV-ppc64/ABISysV_ppc64.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ABI/SysV-ppc64/ABISysV_ppc64.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ABI/SysV-ppc64/ABISysV_ppc64.h (original)
+++ lldb/trunk/source/Plugins/ABI/SysV-ppc64/ABISysV_ppc64.h Tue Sep 6 15:57:50 2016
@@ -14,120 +14,100 @@
// C++ Includes
// Other libraries and framework includes
// Project includes
-#include "lldb/lldb-private.h"
#include "lldb/Target/ABI.h"
+#include "lldb/lldb-private.h"
-class ABISysV_ppc64 :
- public lldb_private::ABI
-{
+class ABISysV_ppc64 : public lldb_private::ABI {
public:
- ~ABISysV_ppc64() override = default;
+ ~ABISysV_ppc64() override = default;
+
+ size_t GetRedZoneSize() const override;
+
+ bool PrepareTrivialCall(lldb_private::Thread &thread, lldb::addr_t sp,
+ lldb::addr_t functionAddress,
+ lldb::addr_t returnAddress,
+ llvm::ArrayRef<lldb::addr_t> args) const override;
+
+ bool GetArgumentValues(lldb_private::Thread &thread,
+ lldb_private::ValueList &values) const override;
+
+ lldb_private::Error
+ SetReturnValueObject(lldb::StackFrameSP &frame_sp,
+ lldb::ValueObjectSP &new_value) override;
+
+ lldb::ValueObjectSP
+ GetReturnValueObjectImpl(lldb_private::Thread &thread,
+ lldb_private::CompilerType &type) const override;
+
+ bool
+ CreateFunctionEntryUnwindPlan(lldb_private::UnwindPlan &unwind_plan) override;
+
+ bool CreateDefaultUnwindPlan(lldb_private::UnwindPlan &unwind_plan) override;
- size_t
- GetRedZoneSize() const override;
+ bool RegisterIsVolatile(const lldb_private::RegisterInfo *reg_info) override;
- bool
- PrepareTrivialCall(lldb_private::Thread &thread,
- lldb::addr_t sp,
- lldb::addr_t functionAddress,
- lldb::addr_t returnAddress,
- llvm::ArrayRef<lldb::addr_t> args) const override;
-
- bool
- GetArgumentValues(lldb_private::Thread &thread,
- lldb_private::ValueList &values) const override;
-
- lldb_private::Error
- SetReturnValueObject(lldb::StackFrameSP &frame_sp, lldb::ValueObjectSP &new_value) override;
-
- lldb::ValueObjectSP
- GetReturnValueObjectImpl(lldb_private::Thread &thread,
- lldb_private::CompilerType &type) const override;
-
- bool
- CreateFunctionEntryUnwindPlan(lldb_private::UnwindPlan &unwind_plan) override;
-
- bool
- CreateDefaultUnwindPlan(lldb_private::UnwindPlan &unwind_plan) override;
-
- bool
- RegisterIsVolatile(const lldb_private::RegisterInfo *reg_info) override;
-
- // The SysV ppc64 ABI requires that stack frames be 16 byte aligned.
- // When there is a trap handler on the stack, e.g. _sigtramp in userland
- // code, we've seen that the stack pointer is often not aligned properly
- // before the handler is invoked. This means that lldb will stop the unwind
- // early -- before the function which caused the trap.
- //
- // To work around this, we relax that alignment to be just word-size (8-bytes).
- // Whitelisting the trap handlers for user space would be easy (_sigtramp) but
- // in other environments there can be a large number of different functions
- // involved in async traps.
- bool
- CallFrameAddressIsValid(lldb::addr_t cfa) override
- {
- // Make sure the stack call frame addresses are 8 byte aligned
- if (cfa & (8ull - 1ull))
- return false; // Not 8 byte aligned
- if (cfa == 0)
- return false; // Zero is not a valid stack address
- return true;
- }
-
- bool
- CodeAddressIsValid(lldb::addr_t pc) override
- {
- // We have a 64 bit address space, so anything is valid as opcodes
- // aren't fixed width...
- return true;
- }
-
- const lldb_private::RegisterInfo *
- GetRegisterInfoArray(uint32_t &count) override;
-
- //------------------------------------------------------------------
- // Static Functions
- //------------------------------------------------------------------
-
- static void
- Initialize();
-
- static void
- Terminate();
-
- static lldb::ABISP
- CreateInstance (const lldb_private::ArchSpec &arch);
-
- static lldb_private::ConstString
- GetPluginNameStatic();
-
- //------------------------------------------------------------------
- // PluginInterface protocol
- //------------------------------------------------------------------
+ // The SysV ppc64 ABI requires that stack frames be 16 byte aligned.
+ // When there is a trap handler on the stack, e.g. _sigtramp in userland
+ // code, we've seen that the stack pointer is often not aligned properly
+ // before the handler is invoked. This means that lldb will stop the unwind
+ // early -- before the function which caused the trap.
+ //
+ // To work around this, we relax that alignment to be just word-size
+ // (8-bytes).
+ // Whitelisting the trap handlers for user space would be easy (_sigtramp) but
+ // in other environments there can be a large number of different functions
+ // involved in async traps.
+ bool CallFrameAddressIsValid(lldb::addr_t cfa) override {
+ // Make sure the stack call frame addresses are 8 byte aligned
+ if (cfa & (8ull - 1ull))
+ return false; // Not 8 byte aligned
+ if (cfa == 0)
+ return false; // Zero is not a valid stack address
+ return true;
+ }
- lldb_private::ConstString
- GetPluginName() override;
+ bool CodeAddressIsValid(lldb::addr_t pc) override {
+ // We have a 64 bit address space, so anything is valid as opcodes
+ // aren't fixed width...
+ return true;
+ }
- uint32_t
- GetPluginVersion() override;
+ const lldb_private::RegisterInfo *
+ GetRegisterInfoArray(uint32_t &count) override;
+
+ //------------------------------------------------------------------
+ // Static Functions
+ //------------------------------------------------------------------
+
+ static void Initialize();
+
+ static void Terminate();
+
+ static lldb::ABISP CreateInstance(const lldb_private::ArchSpec &arch);
+
+ static lldb_private::ConstString GetPluginNameStatic();
+
+ //------------------------------------------------------------------
+ // PluginInterface protocol
+ //------------------------------------------------------------------
+
+ lldb_private::ConstString GetPluginName() override;
+
+ uint32_t GetPluginVersion() override;
protected:
- void
- CreateRegisterMapIfNeeded ();
+ void CreateRegisterMapIfNeeded();
+
+ lldb::ValueObjectSP
+ GetReturnValueObjectSimple(lldb_private::Thread &thread,
+ lldb_private::CompilerType &ast_type) const;
- lldb::ValueObjectSP
- GetReturnValueObjectSimple(lldb_private::Thread &thread,
- lldb_private::CompilerType &ast_type) const;
-
- bool
- RegisterIsCalleeSaved (const lldb_private::RegisterInfo *reg_info);
+ bool RegisterIsCalleeSaved(const lldb_private::RegisterInfo *reg_info);
private:
- ABISysV_ppc64() :
- lldb_private::ABI()
- {
- // Call CreateInstance instead.
- }
+ ABISysV_ppc64() : lldb_private::ABI() {
+ // Call CreateInstance instead.
+ }
};
#endif // liblldb_ABISysV_ppc64_h_
Modified: lldb/trunk/source/Plugins/ABI/SysV-s390x/ABISysV_s390x.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ABI/SysV-s390x/ABISysV_s390x.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ABI/SysV-s390x/ABISysV_s390x.cpp (original)
+++ lldb/trunk/source/Plugins/ABI/SysV-s390x/ABISysV_s390x.cpp Tue Sep 6 15:57:50 2016
@@ -37,92 +37,91 @@
using namespace lldb;
using namespace lldb_private;
-enum dwarf_regnums
-{
- // General Purpose Registers
- dwarf_r0_s390x = 0,
- dwarf_r1_s390x,
- dwarf_r2_s390x,
- dwarf_r3_s390x,
- dwarf_r4_s390x,
- dwarf_r5_s390x,
- dwarf_r6_s390x,
- dwarf_r7_s390x,
- dwarf_r8_s390x,
- dwarf_r9_s390x,
- dwarf_r10_s390x,
- dwarf_r11_s390x,
- dwarf_r12_s390x,
- dwarf_r13_s390x,
- dwarf_r14_s390x,
- dwarf_r15_s390x,
- // Floating Point Registers / Vector Registers 0-15
- dwarf_f0_s390x = 16,
- dwarf_f2_s390x,
- dwarf_f4_s390x,
- dwarf_f6_s390x,
- dwarf_f1_s390x,
- dwarf_f3_s390x,
- dwarf_f5_s390x,
- dwarf_f7_s390x,
- dwarf_f8_s390x,
- dwarf_f10_s390x,
- dwarf_f12_s390x,
- dwarf_f14_s390x,
- dwarf_f9_s390x,
- dwarf_f11_s390x,
- dwarf_f13_s390x,
- dwarf_f15_s390x,
- // Access Registers
- dwarf_acr0_s390x = 48,
- dwarf_acr1_s390x,
- dwarf_acr2_s390x,
- dwarf_acr3_s390x,
- dwarf_acr4_s390x,
- dwarf_acr5_s390x,
- dwarf_acr6_s390x,
- dwarf_acr7_s390x,
- dwarf_acr8_s390x,
- dwarf_acr9_s390x,
- dwarf_acr10_s390x,
- dwarf_acr11_s390x,
- dwarf_acr12_s390x,
- dwarf_acr13_s390x,
- dwarf_acr14_s390x,
- dwarf_acr15_s390x,
- // Program Status Word
- dwarf_pswm_s390x = 64,
- dwarf_pswa_s390x,
- // Vector Registers 16-31
- dwarf_v16_s390x = 68,
- dwarf_v18_s390x,
- dwarf_v20_s390x,
- dwarf_v22_s390x,
- dwarf_v17_s390x,
- dwarf_v19_s390x,
- dwarf_v21_s390x,
- dwarf_v23_s390x,
- dwarf_v24_s390x,
- dwarf_v26_s390x,
- dwarf_v28_s390x,
- dwarf_v30_s390x,
- dwarf_v25_s390x,
- dwarf_v27_s390x,
- dwarf_v29_s390x,
- dwarf_v31_s390x,
+enum dwarf_regnums {
+ // General Purpose Registers
+ dwarf_r0_s390x = 0,
+ dwarf_r1_s390x,
+ dwarf_r2_s390x,
+ dwarf_r3_s390x,
+ dwarf_r4_s390x,
+ dwarf_r5_s390x,
+ dwarf_r6_s390x,
+ dwarf_r7_s390x,
+ dwarf_r8_s390x,
+ dwarf_r9_s390x,
+ dwarf_r10_s390x,
+ dwarf_r11_s390x,
+ dwarf_r12_s390x,
+ dwarf_r13_s390x,
+ dwarf_r14_s390x,
+ dwarf_r15_s390x,
+ // Floating Point Registers / Vector Registers 0-15
+ dwarf_f0_s390x = 16,
+ dwarf_f2_s390x,
+ dwarf_f4_s390x,
+ dwarf_f6_s390x,
+ dwarf_f1_s390x,
+ dwarf_f3_s390x,
+ dwarf_f5_s390x,
+ dwarf_f7_s390x,
+ dwarf_f8_s390x,
+ dwarf_f10_s390x,
+ dwarf_f12_s390x,
+ dwarf_f14_s390x,
+ dwarf_f9_s390x,
+ dwarf_f11_s390x,
+ dwarf_f13_s390x,
+ dwarf_f15_s390x,
+ // Access Registers
+ dwarf_acr0_s390x = 48,
+ dwarf_acr1_s390x,
+ dwarf_acr2_s390x,
+ dwarf_acr3_s390x,
+ dwarf_acr4_s390x,
+ dwarf_acr5_s390x,
+ dwarf_acr6_s390x,
+ dwarf_acr7_s390x,
+ dwarf_acr8_s390x,
+ dwarf_acr9_s390x,
+ dwarf_acr10_s390x,
+ dwarf_acr11_s390x,
+ dwarf_acr12_s390x,
+ dwarf_acr13_s390x,
+ dwarf_acr14_s390x,
+ dwarf_acr15_s390x,
+ // Program Status Word
+ dwarf_pswm_s390x = 64,
+ dwarf_pswa_s390x,
+ // Vector Registers 16-31
+ dwarf_v16_s390x = 68,
+ dwarf_v18_s390x,
+ dwarf_v20_s390x,
+ dwarf_v22_s390x,
+ dwarf_v17_s390x,
+ dwarf_v19_s390x,
+ dwarf_v21_s390x,
+ dwarf_v23_s390x,
+ dwarf_v24_s390x,
+ dwarf_v26_s390x,
+ dwarf_v28_s390x,
+ dwarf_v30_s390x,
+ dwarf_v25_s390x,
+ dwarf_v27_s390x,
+ dwarf_v29_s390x,
+ dwarf_v31_s390x,
};
// RegisterKind: EHFrame, DWARF, Generic, Process Plugin, LLDB
-#define DEFINE_REG(name, size, alt, generic) \
- { \
- #name, alt, size, 0, eEncodingUint, eFormatHex, \
- { dwarf_##name##_s390x, dwarf_##name##_s390x, generic, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, \
- nullptr, nullptr, nullptr, 0 \
- }
+#define DEFINE_REG(name, size, alt, generic) \
+ { \
+ #name, alt, size, 0, eEncodingUint, eFormatHex, \
+ {dwarf_##name##_s390x, dwarf_##name##_s390x, generic, \
+ LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, \
+ nullptr, nullptr, nullptr, 0 \
+ }
-static RegisterInfo g_register_infos[] =
-{
+static RegisterInfo g_register_infos[] = {
DEFINE_REG(r0, 8, nullptr, LLDB_INVALID_REGNUM),
DEFINE_REG(r1, 8, nullptr, LLDB_INVALID_REGNUM),
DEFINE_REG(r2, 8, "arg1", LLDB_REGNUM_GENERIC_ARG1),
@@ -175,633 +174,580 @@ static RegisterInfo g_register_infos[] =
DEFINE_REG(f15, 8, nullptr, LLDB_INVALID_REGNUM),
};
-static const uint32_t k_num_register_infos = llvm::array_lengthof(g_register_infos);
+static const uint32_t k_num_register_infos =
+ llvm::array_lengthof(g_register_infos);
static bool g_register_info_names_constified = false;
const lldb_private::RegisterInfo *
-ABISysV_s390x::GetRegisterInfoArray(uint32_t &count)
-{
- // Make the C-string names and alt_names for the register infos into const
- // C-string values by having the ConstString unique the names in the global
- // constant C-string pool.
- if (!g_register_info_names_constified)
- {
- g_register_info_names_constified = true;
- for (uint32_t i = 0; i < k_num_register_infos; ++i)
- {
- if (g_register_infos[i].name)
- g_register_infos[i].name = ConstString(g_register_infos[i].name).GetCString();
- if (g_register_infos[i].alt_name)
- g_register_infos[i].alt_name = ConstString(g_register_infos[i].alt_name).GetCString();
- }
- }
- count = k_num_register_infos;
- return g_register_infos;
+ABISysV_s390x::GetRegisterInfoArray(uint32_t &count) {
+ // Make the C-string names and alt_names for the register infos into const
+ // C-string values by having the ConstString unique the names in the global
+ // constant C-string pool.
+ if (!g_register_info_names_constified) {
+ g_register_info_names_constified = true;
+ for (uint32_t i = 0; i < k_num_register_infos; ++i) {
+ if (g_register_infos[i].name)
+ g_register_infos[i].name =
+ ConstString(g_register_infos[i].name).GetCString();
+ if (g_register_infos[i].alt_name)
+ g_register_infos[i].alt_name =
+ ConstString(g_register_infos[i].alt_name).GetCString();
+ }
+ }
+ count = k_num_register_infos;
+ return g_register_infos;
}
-size_t
-ABISysV_s390x::GetRedZoneSize() const
-{
- return 0;
-}
+size_t ABISysV_s390x::GetRedZoneSize() const { return 0; }
//------------------------------------------------------------------
// Static Functions
//------------------------------------------------------------------
ABISP
-ABISysV_s390x::CreateInstance(const ArchSpec &arch)
-{
- static ABISP g_abi_sp;
- if (arch.GetTriple().getArch() == llvm::Triple::systemz)
- {
- if (!g_abi_sp)
- g_abi_sp.reset(new ABISysV_s390x);
- return g_abi_sp;
- }
- return ABISP();
-}
-
-bool
-ABISysV_s390x::PrepareTrivialCall(Thread &thread, addr_t sp, addr_t func_addr, addr_t return_addr,
- llvm::ArrayRef<addr_t> args) const
-{
- Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
-
- if (log)
- {
- StreamString s;
- s.Printf("ABISysV_s390x::PrepareTrivialCall (tid = 0x%" PRIx64 ", sp = 0x%" PRIx64
- ", func_addr = 0x%" PRIx64 ", return_addr = 0x%" PRIx64,
- thread.GetID(), (uint64_t)sp, (uint64_t)func_addr, (uint64_t)return_addr);
-
- for (size_t i = 0; i < args.size(); ++i)
- s.Printf(", arg%" PRIu64 " = 0x%" PRIx64, static_cast<uint64_t>(i + 1), args[i]);
- s.PutCString(")");
- log->PutCString(s.GetString().c_str());
- }
-
- RegisterContext *reg_ctx = thread.GetRegisterContext().get();
- if (!reg_ctx)
- return false;
+ABISysV_s390x::CreateInstance(const ArchSpec &arch) {
+ static ABISP g_abi_sp;
+ if (arch.GetTriple().getArch() == llvm::Triple::systemz) {
+ if (!g_abi_sp)
+ g_abi_sp.reset(new ABISysV_s390x);
+ return g_abi_sp;
+ }
+ return ABISP();
+}
+
+bool ABISysV_s390x::PrepareTrivialCall(Thread &thread, addr_t sp,
+ addr_t func_addr, addr_t return_addr,
+ llvm::ArrayRef<addr_t> args) const {
+ Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
+
+ if (log) {
+ StreamString s;
+ s.Printf("ABISysV_s390x::PrepareTrivialCall (tid = 0x%" PRIx64
+ ", sp = 0x%" PRIx64 ", func_addr = 0x%" PRIx64
+ ", return_addr = 0x%" PRIx64,
+ thread.GetID(), (uint64_t)sp, (uint64_t)func_addr,
+ (uint64_t)return_addr);
- const RegisterInfo *pc_reg_info = reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_PC);
- const RegisterInfo *sp_reg_info = reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_SP);
- const RegisterInfo *ra_reg_info = reg_ctx->GetRegisterInfoByName("r14", 0);
- ProcessSP process_sp(thread.GetProcess());
-
- // Allocate a new stack frame and space for stack arguments if necessary
-
- addr_t arg_pos = 0;
- if (args.size() > 5)
- {
- sp -= 8 * (args.size() - 5);
- arg_pos = sp;
- }
-
- sp -= 160;
+ for (size_t i = 0; i < args.size(); ++i)
+ s.Printf(", arg%" PRIu64 " = 0x%" PRIx64, static_cast<uint64_t>(i + 1),
+ args[i]);
+ s.PutCString(")");
+ log->PutCString(s.GetString().c_str());
+ }
- // Process arguments
+ RegisterContext *reg_ctx = thread.GetRegisterContext().get();
+ if (!reg_ctx)
+ return false;
- for (size_t i = 0; i < args.size(); ++i)
- {
- if (i < 5)
- {
- const RegisterInfo *reg_info = reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG1 + i);
- if (log)
- log->Printf("About to write arg%" PRIu64 " (0x%" PRIx64 ") into %s", static_cast<uint64_t>(i + 1),
- args[i], reg_info->name);
- if (!reg_ctx->WriteRegisterFromUnsigned(reg_info, args[i]))
- return false;
- }
- else
- {
- Error error;
- if (log)
- log->Printf("About to write arg%" PRIu64 " (0x%" PRIx64 ") onto stack", static_cast<uint64_t>(i + 1),
- args[i]);
- if (!process_sp->WritePointerToMemory(arg_pos, args[i], error))
- return false;
- arg_pos += 8;
- }
+ const RegisterInfo *pc_reg_info =
+ reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_PC);
+ const RegisterInfo *sp_reg_info =
+ reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_SP);
+ const RegisterInfo *ra_reg_info = reg_ctx->GetRegisterInfoByName("r14", 0);
+ ProcessSP process_sp(thread.GetProcess());
+
+ // Allocate a new stack frame and space for stack arguments if necessary
+
+ addr_t arg_pos = 0;
+ if (args.size() > 5) {
+ sp -= 8 * (args.size() - 5);
+ arg_pos = sp;
+ }
+
+ sp -= 160;
+
+ // Process arguments
+
+ for (size_t i = 0; i < args.size(); ++i) {
+ if (i < 5) {
+ const RegisterInfo *reg_info = reg_ctx->GetRegisterInfo(
+ eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG1 + i);
+ if (log)
+ log->Printf("About to write arg%" PRIu64 " (0x%" PRIx64 ") into %s",
+ static_cast<uint64_t>(i + 1), args[i], reg_info->name);
+ if (!reg_ctx->WriteRegisterFromUnsigned(reg_info, args[i]))
+ return false;
+ } else {
+ Error error;
+ if (log)
+ log->Printf("About to write arg%" PRIu64 " (0x%" PRIx64 ") onto stack",
+ static_cast<uint64_t>(i + 1), args[i]);
+ if (!process_sp->WritePointerToMemory(arg_pos, args[i], error))
+ return false;
+ arg_pos += 8;
}
+ }
- // %r14 is set to the return address
+ // %r14 is set to the return address
- if (log)
- log->Printf("Writing RA: 0x%" PRIx64, (uint64_t)return_addr);
+ if (log)
+ log->Printf("Writing RA: 0x%" PRIx64, (uint64_t)return_addr);
- if (!reg_ctx->WriteRegisterFromUnsigned(ra_reg_info, return_addr))
- return false;
+ if (!reg_ctx->WriteRegisterFromUnsigned(ra_reg_info, return_addr))
+ return false;
- // %r15 is set to the actual stack value.
+ // %r15 is set to the actual stack value.
- if (log)
- log->Printf("Writing SP: 0x%" PRIx64, (uint64_t)sp);
+ if (log)
+ log->Printf("Writing SP: 0x%" PRIx64, (uint64_t)sp);
- if (!reg_ctx->WriteRegisterFromUnsigned(sp_reg_info, sp))
- return false;
+ if (!reg_ctx->WriteRegisterFromUnsigned(sp_reg_info, sp))
+ return false;
- // %pc is set to the address of the called function.
+ // %pc is set to the address of the called function.
- if (log)
- log->Printf("Writing PC: 0x%" PRIx64, (uint64_t)func_addr);
+ if (log)
+ log->Printf("Writing PC: 0x%" PRIx64, (uint64_t)func_addr);
- if (!reg_ctx->WriteRegisterFromUnsigned(pc_reg_info, func_addr))
- return false;
+ if (!reg_ctx->WriteRegisterFromUnsigned(pc_reg_info, func_addr))
+ return false;
- return true;
+ return true;
}
-static bool
-ReadIntegerArgument(Scalar &scalar, unsigned int bit_width, bool is_signed, Thread &thread,
- uint32_t *argument_register_ids, unsigned int ¤t_argument_register,
- addr_t ¤t_stack_argument)
-{
- if (bit_width > 64)
- return false; // Scalar can't hold large integer arguments
-
- if (current_argument_register < 5)
- {
- scalar =
- thread.GetRegisterContext()->ReadRegisterAsUnsigned(argument_register_ids[current_argument_register], 0);
- current_argument_register++;
- if (is_signed)
- scalar.SignExtend(bit_width);
- }
- else
- {
- uint32_t byte_size = (bit_width + (8 - 1)) / 8;
- Error error;
- if (thread.GetProcess()->ReadScalarIntegerFromMemory(current_stack_argument + 8 - byte_size, byte_size,
- is_signed, scalar, error))
- {
- current_stack_argument += 8;
- return true;
- }
- return false;
+static bool ReadIntegerArgument(Scalar &scalar, unsigned int bit_width,
+ bool is_signed, Thread &thread,
+ uint32_t *argument_register_ids,
+ unsigned int ¤t_argument_register,
+ addr_t ¤t_stack_argument) {
+ if (bit_width > 64)
+ return false; // Scalar can't hold large integer arguments
+
+ if (current_argument_register < 5) {
+ scalar = thread.GetRegisterContext()->ReadRegisterAsUnsigned(
+ argument_register_ids[current_argument_register], 0);
+ current_argument_register++;
+ if (is_signed)
+ scalar.SignExtend(bit_width);
+ } else {
+ uint32_t byte_size = (bit_width + (8 - 1)) / 8;
+ Error error;
+ if (thread.GetProcess()->ReadScalarIntegerFromMemory(
+ current_stack_argument + 8 - byte_size, byte_size, is_signed,
+ scalar, error)) {
+ current_stack_argument += 8;
+ return true;
}
- return true;
+ return false;
+ }
+ return true;
}
-bool
-ABISysV_s390x::GetArgumentValues(Thread &thread, ValueList &values) const
-{
- unsigned int num_values = values.GetSize();
- unsigned int value_index;
+bool ABISysV_s390x::GetArgumentValues(Thread &thread, ValueList &values) const {
+ unsigned int num_values = values.GetSize();
+ unsigned int value_index;
- // Extract the register context so we can read arguments from registers
+ // Extract the register context so we can read arguments from registers
- RegisterContext *reg_ctx = thread.GetRegisterContext().get();
+ RegisterContext *reg_ctx = thread.GetRegisterContext().get();
- if (!reg_ctx)
- return false;
-
- // Get the pointer to the first stack argument so we have a place to start
- // when reading data
-
- addr_t sp = reg_ctx->GetSP(0);
-
- if (!sp)
- return false;
+ if (!reg_ctx)
+ return false;
- addr_t current_stack_argument = sp + 160;
+ // Get the pointer to the first stack argument so we have a place to start
+ // when reading data
- uint32_t argument_register_ids[5];
+ addr_t sp = reg_ctx->GetSP(0);
- argument_register_ids[0] =
- reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG1)->kinds[eRegisterKindLLDB];
- argument_register_ids[1] =
- reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG2)->kinds[eRegisterKindLLDB];
- argument_register_ids[2] =
- reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG3)->kinds[eRegisterKindLLDB];
- argument_register_ids[3] =
- reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG4)->kinds[eRegisterKindLLDB];
- argument_register_ids[4] =
- reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG5)->kinds[eRegisterKindLLDB];
-
- unsigned int current_argument_register = 0;
-
- for (value_index = 0; value_index < num_values; ++value_index)
- {
- Value *value = values.GetValueAtIndex(value_index);
-
- if (!value)
- return false;
-
- // We currently only support extracting values with Clang QualTypes.
- // Do we care about others?
- CompilerType compiler_type = value->GetCompilerType();
- if (!compiler_type)
- return false;
- bool is_signed;
-
- if (compiler_type.IsIntegerOrEnumerationType(is_signed))
- {
- ReadIntegerArgument(value->GetScalar(), compiler_type.GetBitSize(&thread), is_signed, thread,
- argument_register_ids, current_argument_register, current_stack_argument);
- }
- else if (compiler_type.IsPointerType())
- {
- ReadIntegerArgument(value->GetScalar(), compiler_type.GetBitSize(&thread), false, thread,
- argument_register_ids, current_argument_register, current_stack_argument);
- }
- }
+ if (!sp)
+ return false;
- return true;
-}
+ addr_t current_stack_argument = sp + 160;
-Error
-ABISysV_s390x::SetReturnValueObject(lldb::StackFrameSP &frame_sp, lldb::ValueObjectSP &new_value_sp)
-{
- Error error;
- if (!new_value_sp)
- {
- error.SetErrorString("Empty value object for return value.");
- return error;
- }
+ uint32_t argument_register_ids[5];
- CompilerType compiler_type = new_value_sp->GetCompilerType();
+ argument_register_ids[0] =
+ reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG1)
+ ->kinds[eRegisterKindLLDB];
+ argument_register_ids[1] =
+ reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG2)
+ ->kinds[eRegisterKindLLDB];
+ argument_register_ids[2] =
+ reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG3)
+ ->kinds[eRegisterKindLLDB];
+ argument_register_ids[3] =
+ reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG4)
+ ->kinds[eRegisterKindLLDB];
+ argument_register_ids[4] =
+ reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG5)
+ ->kinds[eRegisterKindLLDB];
+
+ unsigned int current_argument_register = 0;
+
+ for (value_index = 0; value_index < num_values; ++value_index) {
+ Value *value = values.GetValueAtIndex(value_index);
+
+ if (!value)
+ return false;
+
+ // We currently only support extracting values with Clang QualTypes.
+ // Do we care about others?
+ CompilerType compiler_type = value->GetCompilerType();
if (!compiler_type)
- {
- error.SetErrorString("Null clang type for return value.");
- return error;
- }
-
- Thread *thread = frame_sp->GetThread().get();
-
+ return false;
bool is_signed;
- uint32_t count;
- bool is_complex;
- RegisterContext *reg_ctx = thread->GetRegisterContext().get();
+ if (compiler_type.IsIntegerOrEnumerationType(is_signed)) {
+ ReadIntegerArgument(value->GetScalar(), compiler_type.GetBitSize(&thread),
+ is_signed, thread, argument_register_ids,
+ current_argument_register, current_stack_argument);
+ } else if (compiler_type.IsPointerType()) {
+ ReadIntegerArgument(value->GetScalar(), compiler_type.GetBitSize(&thread),
+ false, thread, argument_register_ids,
+ current_argument_register, current_stack_argument);
+ }
+ }
+
+ return true;
+}
+
+Error ABISysV_s390x::SetReturnValueObject(lldb::StackFrameSP &frame_sp,
+ lldb::ValueObjectSP &new_value_sp) {
+ Error error;
+ if (!new_value_sp) {
+ error.SetErrorString("Empty value object for return value.");
+ return error;
+ }
- bool set_it_simple = false;
- if (compiler_type.IsIntegerOrEnumerationType(is_signed) || compiler_type.IsPointerType())
- {
- const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoByName("r2", 0);
+ CompilerType compiler_type = new_value_sp->GetCompilerType();
+ if (!compiler_type) {
+ error.SetErrorString("Null clang type for return value.");
+ return error;
+ }
+ Thread *thread = frame_sp->GetThread().get();
+
+ bool is_signed;
+ uint32_t count;
+ bool is_complex;
+
+ RegisterContext *reg_ctx = thread->GetRegisterContext().get();
+
+ bool set_it_simple = false;
+ if (compiler_type.IsIntegerOrEnumerationType(is_signed) ||
+ compiler_type.IsPointerType()) {
+ const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoByName("r2", 0);
+
+ DataExtractor data;
+ Error data_error;
+ size_t num_bytes = new_value_sp->GetData(data, data_error);
+ if (data_error.Fail()) {
+ error.SetErrorStringWithFormat(
+ "Couldn't convert return value to raw data: %s",
+ data_error.AsCString());
+ return error;
+ }
+ lldb::offset_t offset = 0;
+ if (num_bytes <= 8) {
+ uint64_t raw_value = data.GetMaxU64(&offset, num_bytes);
+
+ if (reg_ctx->WriteRegisterFromUnsigned(reg_info, raw_value))
+ set_it_simple = true;
+ } else {
+ error.SetErrorString("We don't support returning longer than 64 bit "
+ "integer values at present.");
+ }
+ } else if (compiler_type.IsFloatingPointType(count, is_complex)) {
+ if (is_complex)
+ error.SetErrorString(
+ "We don't support returning complex values at present");
+ else {
+ size_t bit_width = compiler_type.GetBitSize(frame_sp.get());
+ if (bit_width <= 64) {
+ const RegisterInfo *f0_info = reg_ctx->GetRegisterInfoByName("f0", 0);
+ RegisterValue f0_value;
DataExtractor data;
Error data_error;
size_t num_bytes = new_value_sp->GetData(data, data_error);
- if (data_error.Fail())
- {
- error.SetErrorStringWithFormat("Couldn't convert return value to raw data: %s", data_error.AsCString());
- return error;
- }
- lldb::offset_t offset = 0;
- if (num_bytes <= 8)
- {
- uint64_t raw_value = data.GetMaxU64(&offset, num_bytes);
+ if (data_error.Fail()) {
+ error.SetErrorStringWithFormat(
+ "Couldn't convert return value to raw data: %s",
+ data_error.AsCString());
+ return error;
+ }
+
+ unsigned char buffer[8];
+ ByteOrder byte_order = data.GetByteOrder();
+
+ data.CopyByteOrderedData(0, num_bytes, buffer, 8, byte_order);
+ f0_value.SetBytes(buffer, 8, byte_order);
+ reg_ctx->WriteRegister(f0_info, f0_value);
+ set_it_simple = true;
+ } else {
+ // FIXME - don't know how to do long doubles yet.
+ error.SetErrorString(
+ "We don't support returning float values > 64 bits at present");
+ }
+ }
+ }
+
+ if (!set_it_simple) {
+ // Okay we've got a structure or something that doesn't fit in a simple
+ // register.
+ // We should figure out where it really goes, but we don't support this yet.
+ error.SetErrorString("We only support setting simple integer and float "
+ "return types at present.");
+ }
+
+ return error;
+}
+
+ValueObjectSP ABISysV_s390x::GetReturnValueObjectSimple(
+ Thread &thread, CompilerType &return_compiler_type) const {
+ ValueObjectSP return_valobj_sp;
+ Value value;
- if (reg_ctx->WriteRegisterFromUnsigned(reg_info, raw_value))
- set_it_simple = true;
- }
+ if (!return_compiler_type)
+ return return_valobj_sp;
+
+ // value.SetContext (Value::eContextTypeClangType, return_value_type);
+ value.SetCompilerType(return_compiler_type);
+
+ RegisterContext *reg_ctx = thread.GetRegisterContext().get();
+ if (!reg_ctx)
+ return return_valobj_sp;
+
+ const uint32_t type_flags = return_compiler_type.GetTypeInfo();
+ if (type_flags & eTypeIsScalar) {
+ value.SetValueType(Value::eValueTypeScalar);
+
+ bool success = false;
+ if (type_flags & eTypeIsInteger) {
+ // Extract the register context so we can read arguments from registers
+
+ const size_t byte_size = return_compiler_type.GetByteSize(nullptr);
+ uint64_t raw_value = thread.GetRegisterContext()->ReadRegisterAsUnsigned(
+ reg_ctx->GetRegisterInfoByName("r2", 0), 0);
+ const bool is_signed = (type_flags & eTypeIsSigned) != 0;
+ switch (byte_size) {
+ default:
+ break;
+
+ case sizeof(uint64_t):
+ if (is_signed)
+ value.GetScalar() = (int64_t)(raw_value);
else
- {
- error.SetErrorString("We don't support returning longer than 64 bit integer values at present.");
- }
- }
- else if (compiler_type.IsFloatingPointType(count, is_complex))
- {
- if (is_complex)
- error.SetErrorString("We don't support returning complex values at present");
+ value.GetScalar() = (uint64_t)(raw_value);
+ success = true;
+ break;
+
+ case sizeof(uint32_t):
+ if (is_signed)
+ value.GetScalar() = (int32_t)(raw_value & UINT32_MAX);
else
- {
- size_t bit_width = compiler_type.GetBitSize(frame_sp.get());
- if (bit_width <= 64)
- {
- const RegisterInfo *f0_info = reg_ctx->GetRegisterInfoByName("f0", 0);
- RegisterValue f0_value;
- DataExtractor data;
- Error data_error;
- size_t num_bytes = new_value_sp->GetData(data, data_error);
- if (data_error.Fail())
- {
- error.SetErrorStringWithFormat("Couldn't convert return value to raw data: %s",
- data_error.AsCString());
- return error;
- }
-
- unsigned char buffer[8];
- ByteOrder byte_order = data.GetByteOrder();
-
- data.CopyByteOrderedData(0, num_bytes, buffer, 8, byte_order);
- f0_value.SetBytes(buffer, 8, byte_order);
- reg_ctx->WriteRegister(f0_info, f0_value);
- set_it_simple = true;
- }
- else
- {
- // FIXME - don't know how to do long doubles yet.
- error.SetErrorString("We don't support returning float values > 64 bits at present");
+ value.GetScalar() = (uint32_t)(raw_value & UINT32_MAX);
+ success = true;
+ break;
+
+ case sizeof(uint16_t):
+ if (is_signed)
+ value.GetScalar() = (int16_t)(raw_value & UINT16_MAX);
+ else
+ value.GetScalar() = (uint16_t)(raw_value & UINT16_MAX);
+ success = true;
+ break;
+
+ case sizeof(uint8_t):
+ if (is_signed)
+ value.GetScalar() = (int8_t)(raw_value & UINT8_MAX);
+ else
+ value.GetScalar() = (uint8_t)(raw_value & UINT8_MAX);
+ success = true;
+ break;
+ }
+ } else if (type_flags & eTypeIsFloat) {
+ if (type_flags & eTypeIsComplex) {
+ // Don't handle complex yet.
+ } else {
+ const size_t byte_size = return_compiler_type.GetByteSize(nullptr);
+ if (byte_size <= sizeof(long double)) {
+ const RegisterInfo *f0_info = reg_ctx->GetRegisterInfoByName("f0", 0);
+ RegisterValue f0_value;
+ if (reg_ctx->ReadRegister(f0_info, f0_value)) {
+ DataExtractor data;
+ if (f0_value.GetData(data)) {
+ lldb::offset_t offset = 0;
+ if (byte_size == sizeof(float)) {
+ value.GetScalar() = (float)data.GetFloat(&offset);
+ success = true;
+ } else if (byte_size == sizeof(double)) {
+ value.GetScalar() = (double)data.GetDouble(&offset);
+ success = true;
+ } else if (byte_size == sizeof(long double)) {
+ // Don't handle long double yet.
+ }
}
+ }
}
+ }
}
- if (!set_it_simple)
- {
- // Okay we've got a structure or something that doesn't fit in a simple register.
- // We should figure out where it really goes, but we don't support this yet.
- error.SetErrorString("We only support setting simple integer and float return types at present.");
- }
+ if (success)
+ return_valobj_sp = ValueObjectConstResult::Create(
+ thread.GetStackFrameAtIndex(0).get(), value, ConstString(""));
+ } else if (type_flags & eTypeIsPointer) {
+ unsigned r2_id =
+ reg_ctx->GetRegisterInfoByName("r2", 0)->kinds[eRegisterKindLLDB];
+ value.GetScalar() =
+ (uint64_t)thread.GetRegisterContext()->ReadRegisterAsUnsigned(r2_id, 0);
+ value.SetValueType(Value::eValueTypeScalar);
+ return_valobj_sp = ValueObjectConstResult::Create(
+ thread.GetStackFrameAtIndex(0).get(), value, ConstString(""));
+ }
- return error;
+ return return_valobj_sp;
}
-ValueObjectSP
-ABISysV_s390x::GetReturnValueObjectSimple(Thread &thread, CompilerType &return_compiler_type) const
-{
- ValueObjectSP return_valobj_sp;
- Value value;
-
- if (!return_compiler_type)
- return return_valobj_sp;
-
- // value.SetContext (Value::eContextTypeClangType, return_value_type);
- value.SetCompilerType(return_compiler_type);
-
- RegisterContext *reg_ctx = thread.GetRegisterContext().get();
- if (!reg_ctx)
- return return_valobj_sp;
-
- const uint32_t type_flags = return_compiler_type.GetTypeInfo();
- if (type_flags & eTypeIsScalar)
- {
- value.SetValueType(Value::eValueTypeScalar);
-
- bool success = false;
- if (type_flags & eTypeIsInteger)
- {
- // Extract the register context so we can read arguments from registers
-
- const size_t byte_size = return_compiler_type.GetByteSize(nullptr);
- uint64_t raw_value =
- thread.GetRegisterContext()->ReadRegisterAsUnsigned(reg_ctx->GetRegisterInfoByName("r2", 0), 0);
- const bool is_signed = (type_flags & eTypeIsSigned) != 0;
- switch (byte_size)
- {
- default:
- break;
-
- case sizeof(uint64_t):
- if (is_signed)
- value.GetScalar() = (int64_t)(raw_value);
- else
- value.GetScalar() = (uint64_t)(raw_value);
- success = true;
- break;
-
- case sizeof(uint32_t):
- if (is_signed)
- value.GetScalar() = (int32_t)(raw_value & UINT32_MAX);
- else
- value.GetScalar() = (uint32_t)(raw_value & UINT32_MAX);
- success = true;
- break;
-
- case sizeof(uint16_t):
- if (is_signed)
- value.GetScalar() = (int16_t)(raw_value & UINT16_MAX);
- else
- value.GetScalar() = (uint16_t)(raw_value & UINT16_MAX);
- success = true;
- break;
-
- case sizeof(uint8_t):
- if (is_signed)
- value.GetScalar() = (int8_t)(raw_value & UINT8_MAX);
- else
- value.GetScalar() = (uint8_t)(raw_value & UINT8_MAX);
- success = true;
- break;
- }
- }
- else if (type_flags & eTypeIsFloat)
- {
- if (type_flags & eTypeIsComplex)
- {
- // Don't handle complex yet.
- }
- else
- {
- const size_t byte_size = return_compiler_type.GetByteSize(nullptr);
- if (byte_size <= sizeof(long double))
- {
- const RegisterInfo *f0_info = reg_ctx->GetRegisterInfoByName("f0", 0);
- RegisterValue f0_value;
- if (reg_ctx->ReadRegister(f0_info, f0_value))
- {
- DataExtractor data;
- if (f0_value.GetData(data))
- {
- lldb::offset_t offset = 0;
- if (byte_size == sizeof(float))
- {
- value.GetScalar() = (float)data.GetFloat(&offset);
- success = true;
- }
- else if (byte_size == sizeof(double))
- {
- value.GetScalar() = (double)data.GetDouble(&offset);
- success = true;
- }
- else if (byte_size == sizeof(long double))
- {
- // Don't handle long double yet.
- }
- }
- }
- }
- }
- }
-
- if (success)
- return_valobj_sp =
- ValueObjectConstResult::Create(thread.GetStackFrameAtIndex(0).get(), value, ConstString(""));
- }
- else if (type_flags & eTypeIsPointer)
- {
- unsigned r2_id = reg_ctx->GetRegisterInfoByName("r2", 0)->kinds[eRegisterKindLLDB];
- value.GetScalar() = (uint64_t)thread.GetRegisterContext()->ReadRegisterAsUnsigned(r2_id, 0);
- value.SetValueType(Value::eValueTypeScalar);
- return_valobj_sp = ValueObjectConstResult::Create(thread.GetStackFrameAtIndex(0).get(), value, ConstString(""));
- }
+ValueObjectSP ABISysV_s390x::GetReturnValueObjectImpl(
+ Thread &thread, CompilerType &return_compiler_type) const {
+ ValueObjectSP return_valobj_sp;
+ if (!return_compiler_type)
return return_valobj_sp;
-}
-ValueObjectSP
-ABISysV_s390x::GetReturnValueObjectImpl(Thread &thread, CompilerType &return_compiler_type) const
-{
- ValueObjectSP return_valobj_sp;
-
- if (!return_compiler_type)
- return return_valobj_sp;
-
- ExecutionContext exe_ctx(thread.shared_from_this());
- return_valobj_sp = GetReturnValueObjectSimple(thread, return_compiler_type);
- if (return_valobj_sp)
- return return_valobj_sp;
-
- RegisterContextSP reg_ctx_sp = thread.GetRegisterContext();
- if (!reg_ctx_sp)
- return return_valobj_sp;
-
- if (return_compiler_type.IsAggregateType())
- {
- // FIXME: This is just taking a guess, r2 may very well no longer hold the return storage location.
- // If we are going to do this right, when we make a new frame we should check to see if it uses a memory
- // return, and if we are at the first instruction and if so stash away the return location. Then we would
- // only return the memory return value if we know it is valid.
-
- unsigned r2_id = reg_ctx_sp->GetRegisterInfoByName("r2", 0)->kinds[eRegisterKindLLDB];
- lldb::addr_t storage_addr = (uint64_t)thread.GetRegisterContext()->ReadRegisterAsUnsigned(r2_id, 0);
- return_valobj_sp = ValueObjectMemory::Create(&thread, "", Address(storage_addr, nullptr), return_compiler_type);
- }
+ ExecutionContext exe_ctx(thread.shared_from_this());
+ return_valobj_sp = GetReturnValueObjectSimple(thread, return_compiler_type);
+ if (return_valobj_sp)
+ return return_valobj_sp;
+ RegisterContextSP reg_ctx_sp = thread.GetRegisterContext();
+ if (!reg_ctx_sp)
return return_valobj_sp;
-}
-bool
-ABISysV_s390x::CreateFunctionEntryUnwindPlan(UnwindPlan &unwind_plan)
-{
- unwind_plan.Clear();
- unwind_plan.SetRegisterKind(eRegisterKindDWARF);
-
- UnwindPlan::RowSP row(new UnwindPlan::Row);
-
- // Our Call Frame Address is the stack pointer value + 160
- row->GetCFAValue().SetIsRegisterPlusOffset(dwarf_r15_s390x, 160);
-
- // The previous PC is in r14
- row->SetRegisterLocationToRegister(dwarf_pswa_s390x, dwarf_r14_s390x, true);
-
- // All other registers are the same.
- unwind_plan.AppendRow(row);
- unwind_plan.SetSourceName("s390x at-func-entry default");
- unwind_plan.SetSourcedFromCompiler(eLazyBoolNo);
+ if (return_compiler_type.IsAggregateType()) {
+ // FIXME: This is just taking a guess, r2 may very well no longer hold the
+ // return storage location.
+ // If we are going to do this right, when we make a new frame we should
+ // check to see if it uses a memory
+ // return, and if we are at the first instruction and if so stash away the
+ // return location. Then we would
+ // only return the memory return value if we know it is valid.
+
+ unsigned r2_id =
+ reg_ctx_sp->GetRegisterInfoByName("r2", 0)->kinds[eRegisterKindLLDB];
+ lldb::addr_t storage_addr =
+ (uint64_t)thread.GetRegisterContext()->ReadRegisterAsUnsigned(r2_id, 0);
+ return_valobj_sp = ValueObjectMemory::Create(
+ &thread, "", Address(storage_addr, nullptr), return_compiler_type);
+ }
+
+ return return_valobj_sp;
+}
+
+bool ABISysV_s390x::CreateFunctionEntryUnwindPlan(UnwindPlan &unwind_plan) {
+ unwind_plan.Clear();
+ unwind_plan.SetRegisterKind(eRegisterKindDWARF);
+
+ UnwindPlan::RowSP row(new UnwindPlan::Row);
+
+ // Our Call Frame Address is the stack pointer value + 160
+ row->GetCFAValue().SetIsRegisterPlusOffset(dwarf_r15_s390x, 160);
+
+ // The previous PC is in r14
+ row->SetRegisterLocationToRegister(dwarf_pswa_s390x, dwarf_r14_s390x, true);
+
+ // All other registers are the same.
+ unwind_plan.AppendRow(row);
+ unwind_plan.SetSourceName("s390x at-func-entry default");
+ unwind_plan.SetSourcedFromCompiler(eLazyBoolNo);
+ return true;
+}
+
+bool ABISysV_s390x::CreateDefaultUnwindPlan(UnwindPlan &unwind_plan) {
+ // There's really no default way to unwind on s390x.
+ // Trust the .eh_frame CFI, which should always be good.
+ return false;
+}
+
+bool ABISysV_s390x::GetFallbackRegisterLocation(
+ const RegisterInfo *reg_info,
+ UnwindPlan::Row::RegisterLocation &unwind_regloc) {
+ // If a volatile register is being requested, we don't want to forward the
+ // next frame's register contents
+ // up the stack -- the register is not retrievable at this frame.
+ if (RegisterIsVolatile(reg_info)) {
+ unwind_regloc.SetUndefined();
return true;
+ }
+
+ return false;
}
-bool
-ABISysV_s390x::CreateDefaultUnwindPlan(UnwindPlan &unwind_plan)
-{
- // There's really no default way to unwind on s390x.
- // Trust the .eh_frame CFI, which should always be good.
- return false;
+bool ABISysV_s390x::RegisterIsVolatile(const RegisterInfo *reg_info) {
+ return !RegisterIsCalleeSaved(reg_info);
}
-bool
-ABISysV_s390x::GetFallbackRegisterLocation (const RegisterInfo *reg_info,
- UnwindPlan::Row::RegisterLocation &unwind_regloc)
-{
- // If a volatile register is being requested, we don't want to forward the next frame's register contents
- // up the stack -- the register is not retrievable at this frame.
- if (RegisterIsVolatile(reg_info))
- {
- unwind_regloc.SetUndefined();
- return true;
- }
+bool ABISysV_s390x::RegisterIsCalleeSaved(const RegisterInfo *reg_info) {
+ if (reg_info) {
+ // Preserved registers are :
+ // r6-r13, r15
+ // f8-f15
- return false;
-}
+ const char *name = reg_info->name;
+ if (name[0] == 'r') {
+ switch (name[1]) {
+ case '6': // r6
+ case '7': // r7
+ case '8': // r8
+ case '9': // r9
+ return name[2] == '\0';
-bool
-ABISysV_s390x::RegisterIsVolatile(const RegisterInfo *reg_info)
-{
- return !RegisterIsCalleeSaved(reg_info);
-}
-
-bool
-ABISysV_s390x::RegisterIsCalleeSaved(const RegisterInfo *reg_info)
-{
- if (reg_info)
- {
- // Preserved registers are :
- // r6-r13, r15
- // f8-f15
-
- const char *name = reg_info->name;
- if (name[0] == 'r')
- {
- switch (name[1])
- {
- case '6': // r6
- case '7': // r7
- case '8': // r8
- case '9': // r9
- return name[2] == '\0';
-
- case '1': // r10, r11, r12, r13, r15
- if ((name[2] >= '0' && name[2] <= '3') || name[2] == '5')
- return name[3] == '\0';
- break;
+ case '1': // r10, r11, r12, r13, r15
+ if ((name[2] >= '0' && name[2] <= '3') || name[2] == '5')
+ return name[3] == '\0';
+ break;
- default:
- break;
- }
- }
- if (name[0] == 'f')
- {
- switch (name[1])
- {
- case '8': // r8
- case '9': // r9
- return name[2] == '\0';
-
- case '1': // r10, r11, r12, r13, r14, r15
- if (name[2] >= '0' && name[2] <= '5')
- return name[3] == '\0';
- break;
+ default:
+ break;
+ }
+ }
+ if (name[0] == 'f') {
+ switch (name[1]) {
+ case '8': // r8
+ case '9': // r9
+ return name[2] == '\0';
- default:
- break;
- }
- }
+ case '1': // r10, r11, r12, r13, r14, r15
+ if (name[2] >= '0' && name[2] <= '5')
+ return name[3] == '\0';
+ break;
- // Accept shorter-variant versions
- if (name[0] == 's' && name[1] == 'p' && name[2] == '\0') // sp
- return true;
- if (name[0] == 'f' && name[1] == 'p' && name[2] == '\0') // fp
- return true;
- if (name[0] == 'p' && name[1] == 'c' && name[2] == '\0') // pc
- return true;
+ default:
+ break;
+ }
}
- return false;
+
+ // Accept shorter-variant versions
+ if (name[0] == 's' && name[1] == 'p' && name[2] == '\0') // sp
+ return true;
+ if (name[0] == 'f' && name[1] == 'p' && name[2] == '\0') // fp
+ return true;
+ if (name[0] == 'p' && name[1] == 'c' && name[2] == '\0') // pc
+ return true;
+ }
+ return false;
+}
+
+void ABISysV_s390x::Initialize() {
+ PluginManager::RegisterPlugin(
+ GetPluginNameStatic(), "System V ABI for s390x targets", CreateInstance);
}
-void
-ABISysV_s390x::Initialize()
-{
- PluginManager::RegisterPlugin(GetPluginNameStatic(), "System V ABI for s390x targets", CreateInstance);
-}
-
-void
-ABISysV_s390x::Terminate()
-{
- PluginManager::UnregisterPlugin(CreateInstance);
-}
-
-lldb_private::ConstString
-ABISysV_s390x::GetPluginNameStatic()
-{
- static ConstString g_name("sysv-s390x");
- return g_name;
+void ABISysV_s390x::Terminate() {
+ PluginManager::UnregisterPlugin(CreateInstance);
+}
+
+lldb_private::ConstString ABISysV_s390x::GetPluginNameStatic() {
+ static ConstString g_name("sysv-s390x");
+ return g_name;
}
//------------------------------------------------------------------
// PluginInterface protocol
//------------------------------------------------------------------
-lldb_private::ConstString
-ABISysV_s390x::GetPluginName()
-{
- return GetPluginNameStatic();
+lldb_private::ConstString ABISysV_s390x::GetPluginName() {
+ return GetPluginNameStatic();
}
-uint32_t
-ABISysV_s390x::GetPluginVersion()
-{
- return 1;
-}
+uint32_t ABISysV_s390x::GetPluginVersion() { return 1; }
Modified: lldb/trunk/source/Plugins/ABI/SysV-s390x/ABISysV_s390x.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ABI/SysV-s390x/ABISysV_s390x.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ABI/SysV-s390x/ABISysV_s390x.h (original)
+++ lldb/trunk/source/Plugins/ABI/SysV-s390x/ABISysV_s390x.h Tue Sep 6 15:57:50 2016
@@ -14,107 +14,94 @@
// C++ Includes
// Other libraries and framework includes
// Project includes
-#include "lldb/lldb-private.h"
#include "lldb/Target/ABI.h"
+#include "lldb/lldb-private.h"
-class ABISysV_s390x : public lldb_private::ABI
-{
+class ABISysV_s390x : public lldb_private::ABI {
public:
- ~ABISysV_s390x() override = default;
+ ~ABISysV_s390x() override = default;
- size_t
- GetRedZoneSize() const override;
+ size_t GetRedZoneSize() const override;
- bool
- PrepareTrivialCall(lldb_private::Thread &thread, lldb::addr_t sp, lldb::addr_t functionAddress,
- lldb::addr_t returnAddress, llvm::ArrayRef<lldb::addr_t> args) const override;
+ bool PrepareTrivialCall(lldb_private::Thread &thread, lldb::addr_t sp,
+ lldb::addr_t functionAddress,
+ lldb::addr_t returnAddress,
+ llvm::ArrayRef<lldb::addr_t> args) const override;
- bool
- GetArgumentValues(lldb_private::Thread &thread, lldb_private::ValueList &values) const override;
+ bool GetArgumentValues(lldb_private::Thread &thread,
+ lldb_private::ValueList &values) const override;
- lldb_private::Error
- SetReturnValueObject(lldb::StackFrameSP &frame_sp, lldb::ValueObjectSP &new_value) override;
+ lldb_private::Error
+ SetReturnValueObject(lldb::StackFrameSP &frame_sp,
+ lldb::ValueObjectSP &new_value) override;
- lldb::ValueObjectSP
- GetReturnValueObjectImpl(lldb_private::Thread &thread, lldb_private::CompilerType &type) const override;
+ lldb::ValueObjectSP
+ GetReturnValueObjectImpl(lldb_private::Thread &thread,
+ lldb_private::CompilerType &type) const override;
- bool
- CreateFunctionEntryUnwindPlan(lldb_private::UnwindPlan &unwind_plan) override;
+ bool
+ CreateFunctionEntryUnwindPlan(lldb_private::UnwindPlan &unwind_plan) override;
- bool
- CreateDefaultUnwindPlan(lldb_private::UnwindPlan &unwind_plan) override;
+ bool CreateDefaultUnwindPlan(lldb_private::UnwindPlan &unwind_plan) override;
- bool
- RegisterIsVolatile(const lldb_private::RegisterInfo *reg_info) override;
+ bool RegisterIsVolatile(const lldb_private::RegisterInfo *reg_info) override;
- bool
- GetFallbackRegisterLocation (const lldb_private::RegisterInfo *reg_info,
- lldb_private::UnwindPlan::Row::RegisterLocation &unwind_regloc) override;
+ bool GetFallbackRegisterLocation(
+ const lldb_private::RegisterInfo *reg_info,
+ lldb_private::UnwindPlan::Row::RegisterLocation &unwind_regloc) override;
- bool
- CallFrameAddressIsValid(lldb::addr_t cfa) override
- {
- // Make sure the stack call frame addresses are 8 byte aligned
- if (cfa & (8ull - 1ull))
- return false; // Not 8 byte aligned
- if (cfa == 0)
- return false; // Zero is not a valid stack address
- return true;
- }
+ bool CallFrameAddressIsValid(lldb::addr_t cfa) override {
+ // Make sure the stack call frame addresses are 8 byte aligned
+ if (cfa & (8ull - 1ull))
+ return false; // Not 8 byte aligned
+ if (cfa == 0)
+ return false; // Zero is not a valid stack address
+ return true;
+ }
- bool
- CodeAddressIsValid(lldb::addr_t pc) override
- {
- // Code addressed must be 2 byte aligned
- if (pc & 1ull)
- return false;
- return true;
- }
+ bool CodeAddressIsValid(lldb::addr_t pc) override {
+ // Code addressed must be 2 byte aligned
+ if (pc & 1ull)
+ return false;
+ return true;
+ }
- const lldb_private::RegisterInfo *
- GetRegisterInfoArray(uint32_t &count) override;
+ const lldb_private::RegisterInfo *
+ GetRegisterInfoArray(uint32_t &count) override;
- //------------------------------------------------------------------
- // Static Functions
- //------------------------------------------------------------------
+ //------------------------------------------------------------------
+ // Static Functions
+ //------------------------------------------------------------------
- static void
- Initialize();
+ static void Initialize();
- static void
- Terminate();
+ static void Terminate();
- static lldb::ABISP
- CreateInstance(const lldb_private::ArchSpec &arch);
+ static lldb::ABISP CreateInstance(const lldb_private::ArchSpec &arch);
- static lldb_private::ConstString
- GetPluginNameStatic();
+ static lldb_private::ConstString GetPluginNameStatic();
- //------------------------------------------------------------------
- // PluginInterface protocol
- //------------------------------------------------------------------
+ //------------------------------------------------------------------
+ // PluginInterface protocol
+ //------------------------------------------------------------------
- lldb_private::ConstString
- GetPluginName() override;
+ lldb_private::ConstString GetPluginName() override;
- uint32_t
- GetPluginVersion() override;
+ uint32_t GetPluginVersion() override;
protected:
- void
- CreateRegisterMapIfNeeded();
+ void CreateRegisterMapIfNeeded();
- lldb::ValueObjectSP
- GetReturnValueObjectSimple(lldb_private::Thread &thread, lldb_private::CompilerType &ast_type) const;
+ lldb::ValueObjectSP
+ GetReturnValueObjectSimple(lldb_private::Thread &thread,
+ lldb_private::CompilerType &ast_type) const;
- bool
- RegisterIsCalleeSaved(const lldb_private::RegisterInfo *reg_info);
+ bool RegisterIsCalleeSaved(const lldb_private::RegisterInfo *reg_info);
private:
- ABISysV_s390x() : lldb_private::ABI()
- {
- // Call CreateInstance instead.
- }
+ ABISysV_s390x() : lldb_private::ABI() {
+ // Call CreateInstance instead.
+ }
};
#endif // liblldb_ABISysV_s390x_h_
Modified: lldb/trunk/source/Plugins/ABI/SysV-x86_64/ABISysV_x86_64.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ABI/SysV-x86_64/ABISysV_x86_64.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ABI/SysV-x86_64/ABISysV_x86_64.cpp (original)
+++ lldb/trunk/source/Plugins/ABI/SysV-x86_64/ABISysV_x86_64.cpp Tue Sep 6 15:57:50 2016
@@ -25,269 +25,1065 @@
#include "lldb/Core/RegisterValue.h"
#include "lldb/Core/Value.h"
#include "lldb/Core/ValueObjectConstResult.h"
-#include "lldb/Core/ValueObjectRegister.h"
#include "lldb/Core/ValueObjectMemory.h"
+#include "lldb/Core/ValueObjectRegister.h"
#include "lldb/Symbol/UnwindPlan.h"
-#include "lldb/Target/Target.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/RegisterContext.h"
#include "lldb/Target/StackFrame.h"
+#include "lldb/Target/Target.h"
#include "lldb/Target/Thread.h"
using namespace lldb;
using namespace lldb_private;
-enum dwarf_regnums
-{
- dwarf_rax = 0,
- dwarf_rdx,
- dwarf_rcx,
- dwarf_rbx,
- dwarf_rsi,
- dwarf_rdi,
- dwarf_rbp,
- dwarf_rsp,
- dwarf_r8,
- dwarf_r9,
- dwarf_r10,
- dwarf_r11,
- dwarf_r12,
- dwarf_r13,
- dwarf_r14,
- dwarf_r15,
- dwarf_rip,
- dwarf_xmm0,
- dwarf_xmm1,
- dwarf_xmm2,
- dwarf_xmm3,
- dwarf_xmm4,
- dwarf_xmm5,
- dwarf_xmm6,
- dwarf_xmm7,
- dwarf_xmm8,
- dwarf_xmm9,
- dwarf_xmm10,
- dwarf_xmm11,
- dwarf_xmm12,
- dwarf_xmm13,
- dwarf_xmm14,
- dwarf_xmm15,
- dwarf_stmm0,
- dwarf_stmm1,
- dwarf_stmm2,
- dwarf_stmm3,
- dwarf_stmm4,
- dwarf_stmm5,
- dwarf_stmm6,
- dwarf_stmm7,
- dwarf_ymm0,
- dwarf_ymm1,
- dwarf_ymm2,
- dwarf_ymm3,
- dwarf_ymm4,
- dwarf_ymm5,
- dwarf_ymm6,
- dwarf_ymm7,
- dwarf_ymm8,
- dwarf_ymm9,
- dwarf_ymm10,
- dwarf_ymm11,
- dwarf_ymm12,
- dwarf_ymm13,
- dwarf_ymm14,
- dwarf_ymm15
+enum dwarf_regnums {
+ dwarf_rax = 0,
+ dwarf_rdx,
+ dwarf_rcx,
+ dwarf_rbx,
+ dwarf_rsi,
+ dwarf_rdi,
+ dwarf_rbp,
+ dwarf_rsp,
+ dwarf_r8,
+ dwarf_r9,
+ dwarf_r10,
+ dwarf_r11,
+ dwarf_r12,
+ dwarf_r13,
+ dwarf_r14,
+ dwarf_r15,
+ dwarf_rip,
+ dwarf_xmm0,
+ dwarf_xmm1,
+ dwarf_xmm2,
+ dwarf_xmm3,
+ dwarf_xmm4,
+ dwarf_xmm5,
+ dwarf_xmm6,
+ dwarf_xmm7,
+ dwarf_xmm8,
+ dwarf_xmm9,
+ dwarf_xmm10,
+ dwarf_xmm11,
+ dwarf_xmm12,
+ dwarf_xmm13,
+ dwarf_xmm14,
+ dwarf_xmm15,
+ dwarf_stmm0,
+ dwarf_stmm1,
+ dwarf_stmm2,
+ dwarf_stmm3,
+ dwarf_stmm4,
+ dwarf_stmm5,
+ dwarf_stmm6,
+ dwarf_stmm7,
+ dwarf_ymm0,
+ dwarf_ymm1,
+ dwarf_ymm2,
+ dwarf_ymm3,
+ dwarf_ymm4,
+ dwarf_ymm5,
+ dwarf_ymm6,
+ dwarf_ymm7,
+ dwarf_ymm8,
+ dwarf_ymm9,
+ dwarf_ymm10,
+ dwarf_ymm11,
+ dwarf_ymm12,
+ dwarf_ymm13,
+ dwarf_ymm14,
+ dwarf_ymm15
};
-static RegisterInfo g_register_infos[] =
-{
- // NAME ALT SZ OFF ENCODING FORMAT EH_FRAME DWARF GENERIC PROCESS PLUGIN LLDB NATIVE
- // ======== ======= == === ============= =================== ======================= ===================== =========================== ===================== ======================
- { "rax" , nullptr, 8, 0, eEncodingUint , eFormatHex , { dwarf_rax , dwarf_rax , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "rbx" , nullptr, 8, 0, eEncodingUint , eFormatHex , { dwarf_rbx , dwarf_rbx , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "rcx" , "arg4", 8, 0, eEncodingUint , eFormatHex , { dwarf_rcx , dwarf_rcx , LLDB_REGNUM_GENERIC_ARG4 , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "rdx" , "arg3", 8, 0, eEncodingUint , eFormatHex , { dwarf_rdx , dwarf_rdx , LLDB_REGNUM_GENERIC_ARG3 , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "rsi" , "arg2", 8, 0, eEncodingUint , eFormatHex , { dwarf_rsi , dwarf_rsi , LLDB_REGNUM_GENERIC_ARG2 , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "rdi" , "arg1", 8, 0, eEncodingUint , eFormatHex , { dwarf_rdi , dwarf_rdi , LLDB_REGNUM_GENERIC_ARG1 , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "rbp" , "fp", 8, 0, eEncodingUint , eFormatHex , { dwarf_rbp , dwarf_rbp , LLDB_REGNUM_GENERIC_FP , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "rsp" , "sp", 8, 0, eEncodingUint , eFormatHex , { dwarf_rsp , dwarf_rsp , LLDB_REGNUM_GENERIC_SP , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r8" , "arg5", 8, 0, eEncodingUint , eFormatHex , { dwarf_r8 , dwarf_r8 , LLDB_REGNUM_GENERIC_ARG5 , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r9" , "arg6", 8, 0, eEncodingUint , eFormatHex , { dwarf_r9 , dwarf_r9 , LLDB_REGNUM_GENERIC_ARG6 , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r10" , nullptr, 8, 0, eEncodingUint , eFormatHex , { dwarf_r10 , dwarf_r10 , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r11" , nullptr, 8, 0, eEncodingUint , eFormatHex , { dwarf_r11 , dwarf_r11 , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r12" , nullptr, 8, 0, eEncodingUint , eFormatHex , { dwarf_r12 , dwarf_r12 , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r13" , nullptr, 8, 0, eEncodingUint , eFormatHex , { dwarf_r13 , dwarf_r13 , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r14" , nullptr, 8, 0, eEncodingUint , eFormatHex , { dwarf_r14 , dwarf_r14 , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "r15" , nullptr, 8, 0, eEncodingUint , eFormatHex , { dwarf_r15 , dwarf_r15 , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "rip" , "pc", 8, 0, eEncodingUint , eFormatHex , { dwarf_rip , dwarf_rip , LLDB_REGNUM_GENERIC_PC , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "rflags", nullptr, 4, 0, eEncodingUint , eFormatHex , { LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM , LLDB_REGNUM_GENERIC_FLAGS , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "cs" , nullptr, 4, 0, eEncodingUint , eFormatHex , { LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "ss" , nullptr, 4, 0, eEncodingUint , eFormatHex , { LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "ds" , nullptr, 4, 0, eEncodingUint , eFormatHex , { LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "es" , nullptr, 4, 0, eEncodingUint , eFormatHex , { LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "fs" , nullptr, 4, 0, eEncodingUint , eFormatHex , { LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "gs" , nullptr, 4, 0, eEncodingUint , eFormatHex , { LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "stmm0" , nullptr,10, 0, eEncodingVector, eFormatVectorOfUInt8, { dwarf_stmm0 , dwarf_stmm0 , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "stmm1" , nullptr,10, 0, eEncodingVector, eFormatVectorOfUInt8, { dwarf_stmm1 , dwarf_stmm1 , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "stmm2" , nullptr,10, 0, eEncodingVector, eFormatVectorOfUInt8, { dwarf_stmm2 , dwarf_stmm2 , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "stmm3" , nullptr,10, 0, eEncodingVector, eFormatVectorOfUInt8, { dwarf_stmm3 , dwarf_stmm3 , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "stmm4" , nullptr,10, 0, eEncodingVector, eFormatVectorOfUInt8, { dwarf_stmm4 , dwarf_stmm4 , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "stmm5" , nullptr,10, 0, eEncodingVector, eFormatVectorOfUInt8, { dwarf_stmm5 , dwarf_stmm5 , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "stmm6" , nullptr,10, 0, eEncodingVector, eFormatVectorOfUInt8, { dwarf_stmm6 , dwarf_stmm6 , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "stmm7" , nullptr,10, 0, eEncodingVector, eFormatVectorOfUInt8, { dwarf_stmm7 , dwarf_stmm7 , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "fctrl" , nullptr, 4, 0, eEncodingUint , eFormatHex , { LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "fstat" , nullptr, 4, 0, eEncodingUint , eFormatHex , { LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "ftag" , nullptr, 4, 0, eEncodingUint , eFormatHex , { LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "fiseg" , nullptr, 4, 0, eEncodingUint , eFormatHex , { LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "fioff" , nullptr, 4, 0, eEncodingUint , eFormatHex , { LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "foseg" , nullptr, 4, 0, eEncodingUint , eFormatHex , { LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "fooff" , nullptr, 4, 0, eEncodingUint , eFormatHex , { LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "fop" , nullptr, 4, 0, eEncodingUint , eFormatHex , { LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "xmm0" , nullptr,16, 0, eEncodingVector, eFormatVectorOfUInt8, { dwarf_xmm0 , dwarf_xmm0 , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "xmm1" , nullptr,16, 0, eEncodingVector, eFormatVectorOfUInt8, { dwarf_xmm1 , dwarf_xmm1 , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "xmm2" , nullptr,16, 0, eEncodingVector, eFormatVectorOfUInt8, { dwarf_xmm2 , dwarf_xmm2 , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "xmm3" , nullptr,16, 0, eEncodingVector, eFormatVectorOfUInt8, { dwarf_xmm3 , dwarf_xmm3 , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "xmm4" , nullptr,16, 0, eEncodingVector, eFormatVectorOfUInt8, { dwarf_xmm4 , dwarf_xmm4 , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "xmm5" , nullptr,16, 0, eEncodingVector, eFormatVectorOfUInt8, { dwarf_xmm5 , dwarf_xmm5 , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "xmm6" , nullptr,16, 0, eEncodingVector, eFormatVectorOfUInt8, { dwarf_xmm6 , dwarf_xmm6 , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "xmm7" , nullptr,16, 0, eEncodingVector, eFormatVectorOfUInt8, { dwarf_xmm7 , dwarf_xmm7 , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "xmm8" , nullptr,16, 0, eEncodingVector, eFormatVectorOfUInt8, { dwarf_xmm8 , dwarf_xmm8 , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "xmm9" , nullptr,16, 0, eEncodingVector, eFormatVectorOfUInt8, { dwarf_xmm9 , dwarf_xmm9 , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "xmm10" , nullptr,16, 0, eEncodingVector, eFormatVectorOfUInt8, { dwarf_xmm10 , dwarf_xmm10 , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "xmm11" , nullptr,16, 0, eEncodingVector, eFormatVectorOfUInt8, { dwarf_xmm11 , dwarf_xmm11 , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "xmm12" , nullptr,16, 0, eEncodingVector, eFormatVectorOfUInt8, { dwarf_xmm12 , dwarf_xmm12 , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "xmm13" , nullptr,16, 0, eEncodingVector, eFormatVectorOfUInt8, { dwarf_xmm13 , dwarf_xmm13 , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "xmm14" , nullptr,16, 0, eEncodingVector, eFormatVectorOfUInt8, { dwarf_xmm14 , dwarf_xmm14 , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "xmm15" , nullptr,16, 0, eEncodingVector, eFormatVectorOfUInt8, { dwarf_xmm15 , dwarf_xmm15 , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "mxcsr" , nullptr, 4, 0, eEncodingUint , eFormatHex , { LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "ymm0" , nullptr,32, 0, eEncodingVector, eFormatVectorOfUInt8, { dwarf_ymm0 , dwarf_ymm0 , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "ymm1" , nullptr,32, 0, eEncodingVector, eFormatVectorOfUInt8, { dwarf_ymm1 , dwarf_ymm1 , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "ymm2" , nullptr,32, 0, eEncodingVector, eFormatVectorOfUInt8, { dwarf_ymm2 , dwarf_ymm2 , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "ymm3" , nullptr,32, 0, eEncodingVector, eFormatVectorOfUInt8, { dwarf_ymm3 , dwarf_ymm3 , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "ymm4" , nullptr,32, 0, eEncodingVector, eFormatVectorOfUInt8, { dwarf_ymm4 , dwarf_ymm4 , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "ymm5" , nullptr,32, 0, eEncodingVector, eFormatVectorOfUInt8, { dwarf_ymm5 , dwarf_ymm5 , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "ymm6" , nullptr,32, 0, eEncodingVector, eFormatVectorOfUInt8, { dwarf_ymm6 , dwarf_ymm6 , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "ymm7" , nullptr,32, 0, eEncodingVector, eFormatVectorOfUInt8, { dwarf_ymm7 , dwarf_ymm7 , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "ymm8" , nullptr,32, 0, eEncodingVector, eFormatVectorOfUInt8, { dwarf_ymm8 , dwarf_ymm8 , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "ymm9" , nullptr,32, 0, eEncodingVector, eFormatVectorOfUInt8, { dwarf_ymm9 , dwarf_ymm9 , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "ymm10" , nullptr,32, 0, eEncodingVector, eFormatVectorOfUInt8, { dwarf_ymm10 , dwarf_ymm10 , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "ymm11" , nullptr,32, 0, eEncodingVector, eFormatVectorOfUInt8, { dwarf_ymm11 , dwarf_ymm11 , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "ymm12" , nullptr,32, 0, eEncodingVector, eFormatVectorOfUInt8, { dwarf_ymm12 , dwarf_ymm12 , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "ymm13" , nullptr,32, 0, eEncodingVector, eFormatVectorOfUInt8, { dwarf_ymm13 , dwarf_ymm13 , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "ymm14" , nullptr,32, 0, eEncodingVector, eFormatVectorOfUInt8, { dwarf_ymm14 , dwarf_ymm14 , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 },
- { "ymm15" , nullptr,32, 0, eEncodingVector, eFormatVectorOfUInt8, { dwarf_ymm15 , dwarf_ymm15 , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, nullptr, nullptr, nullptr, 0 }
-};
+static RegisterInfo g_register_infos[] = {
+ // NAME ALT SZ OFF ENCODING FORMAT EH_FRAME
+ // DWARF GENERIC PROCESS PLUGIN
+ // LLDB NATIVE
+ // ======== ======= == === ============= ===================
+ // ======================= =====================
+ // =========================== ===================== ======================
+ {"rax",
+ nullptr,
+ 8,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_rax, dwarf_rax, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"rbx",
+ nullptr,
+ 8,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_rbx, dwarf_rbx, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"rcx",
+ "arg4",
+ 8,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_rcx, dwarf_rcx, LLDB_REGNUM_GENERIC_ARG4, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"rdx",
+ "arg3",
+ 8,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_rdx, dwarf_rdx, LLDB_REGNUM_GENERIC_ARG3, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"rsi",
+ "arg2",
+ 8,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_rsi, dwarf_rsi, LLDB_REGNUM_GENERIC_ARG2, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"rdi",
+ "arg1",
+ 8,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_rdi, dwarf_rdi, LLDB_REGNUM_GENERIC_ARG1, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"rbp",
+ "fp",
+ 8,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_rbp, dwarf_rbp, LLDB_REGNUM_GENERIC_FP, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"rsp",
+ "sp",
+ 8,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_rsp, dwarf_rsp, LLDB_REGNUM_GENERIC_SP, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r8",
+ "arg5",
+ 8,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r8, dwarf_r8, LLDB_REGNUM_GENERIC_ARG5, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r9",
+ "arg6",
+ 8,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r9, dwarf_r9, LLDB_REGNUM_GENERIC_ARG6, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r10",
+ nullptr,
+ 8,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r10, dwarf_r10, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r11",
+ nullptr,
+ 8,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r11, dwarf_r11, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r12",
+ nullptr,
+ 8,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r12, dwarf_r12, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r13",
+ nullptr,
+ 8,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r13, dwarf_r13, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r14",
+ nullptr,
+ 8,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r14, dwarf_r14, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"r15",
+ nullptr,
+ 8,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_r15, dwarf_r15, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"rip",
+ "pc",
+ 8,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {dwarf_rip, dwarf_rip, LLDB_REGNUM_GENERIC_PC, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"rflags",
+ nullptr,
+ 4,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_REGNUM_GENERIC_FLAGS,
+ LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"cs",
+ nullptr,
+ 4,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"ss",
+ nullptr,
+ 4,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"ds",
+ nullptr,
+ 4,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"es",
+ nullptr,
+ 4,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"fs",
+ nullptr,
+ 4,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"gs",
+ nullptr,
+ 4,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"stmm0",
+ nullptr,
+ 10,
+ 0,
+ eEncodingVector,
+ eFormatVectorOfUInt8,
+ {dwarf_stmm0, dwarf_stmm0, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"stmm1",
+ nullptr,
+ 10,
+ 0,
+ eEncodingVector,
+ eFormatVectorOfUInt8,
+ {dwarf_stmm1, dwarf_stmm1, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"stmm2",
+ nullptr,
+ 10,
+ 0,
+ eEncodingVector,
+ eFormatVectorOfUInt8,
+ {dwarf_stmm2, dwarf_stmm2, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"stmm3",
+ nullptr,
+ 10,
+ 0,
+ eEncodingVector,
+ eFormatVectorOfUInt8,
+ {dwarf_stmm3, dwarf_stmm3, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"stmm4",
+ nullptr,
+ 10,
+ 0,
+ eEncodingVector,
+ eFormatVectorOfUInt8,
+ {dwarf_stmm4, dwarf_stmm4, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"stmm5",
+ nullptr,
+ 10,
+ 0,
+ eEncodingVector,
+ eFormatVectorOfUInt8,
+ {dwarf_stmm5, dwarf_stmm5, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"stmm6",
+ nullptr,
+ 10,
+ 0,
+ eEncodingVector,
+ eFormatVectorOfUInt8,
+ {dwarf_stmm6, dwarf_stmm6, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"stmm7",
+ nullptr,
+ 10,
+ 0,
+ eEncodingVector,
+ eFormatVectorOfUInt8,
+ {dwarf_stmm7, dwarf_stmm7, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"fctrl",
+ nullptr,
+ 4,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"fstat",
+ nullptr,
+ 4,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"ftag",
+ nullptr,
+ 4,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"fiseg",
+ nullptr,
+ 4,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"fioff",
+ nullptr,
+ 4,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"foseg",
+ nullptr,
+ 4,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"fooff",
+ nullptr,
+ 4,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"fop",
+ nullptr,
+ 4,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"xmm0",
+ nullptr,
+ 16,
+ 0,
+ eEncodingVector,
+ eFormatVectorOfUInt8,
+ {dwarf_xmm0, dwarf_xmm0, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"xmm1",
+ nullptr,
+ 16,
+ 0,
+ eEncodingVector,
+ eFormatVectorOfUInt8,
+ {dwarf_xmm1, dwarf_xmm1, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"xmm2",
+ nullptr,
+ 16,
+ 0,
+ eEncodingVector,
+ eFormatVectorOfUInt8,
+ {dwarf_xmm2, dwarf_xmm2, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"xmm3",
+ nullptr,
+ 16,
+ 0,
+ eEncodingVector,
+ eFormatVectorOfUInt8,
+ {dwarf_xmm3, dwarf_xmm3, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"xmm4",
+ nullptr,
+ 16,
+ 0,
+ eEncodingVector,
+ eFormatVectorOfUInt8,
+ {dwarf_xmm4, dwarf_xmm4, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"xmm5",
+ nullptr,
+ 16,
+ 0,
+ eEncodingVector,
+ eFormatVectorOfUInt8,
+ {dwarf_xmm5, dwarf_xmm5, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"xmm6",
+ nullptr,
+ 16,
+ 0,
+ eEncodingVector,
+ eFormatVectorOfUInt8,
+ {dwarf_xmm6, dwarf_xmm6, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"xmm7",
+ nullptr,
+ 16,
+ 0,
+ eEncodingVector,
+ eFormatVectorOfUInt8,
+ {dwarf_xmm7, dwarf_xmm7, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"xmm8",
+ nullptr,
+ 16,
+ 0,
+ eEncodingVector,
+ eFormatVectorOfUInt8,
+ {dwarf_xmm8, dwarf_xmm8, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"xmm9",
+ nullptr,
+ 16,
+ 0,
+ eEncodingVector,
+ eFormatVectorOfUInt8,
+ {dwarf_xmm9, dwarf_xmm9, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"xmm10",
+ nullptr,
+ 16,
+ 0,
+ eEncodingVector,
+ eFormatVectorOfUInt8,
+ {dwarf_xmm10, dwarf_xmm10, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"xmm11",
+ nullptr,
+ 16,
+ 0,
+ eEncodingVector,
+ eFormatVectorOfUInt8,
+ {dwarf_xmm11, dwarf_xmm11, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"xmm12",
+ nullptr,
+ 16,
+ 0,
+ eEncodingVector,
+ eFormatVectorOfUInt8,
+ {dwarf_xmm12, dwarf_xmm12, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"xmm13",
+ nullptr,
+ 16,
+ 0,
+ eEncodingVector,
+ eFormatVectorOfUInt8,
+ {dwarf_xmm13, dwarf_xmm13, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"xmm14",
+ nullptr,
+ 16,
+ 0,
+ eEncodingVector,
+ eFormatVectorOfUInt8,
+ {dwarf_xmm14, dwarf_xmm14, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"xmm15",
+ nullptr,
+ 16,
+ 0,
+ eEncodingVector,
+ eFormatVectorOfUInt8,
+ {dwarf_xmm15, dwarf_xmm15, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"mxcsr",
+ nullptr,
+ 4,
+ 0,
+ eEncodingUint,
+ eFormatHex,
+ {LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"ymm0",
+ nullptr,
+ 32,
+ 0,
+ eEncodingVector,
+ eFormatVectorOfUInt8,
+ {dwarf_ymm0, dwarf_ymm0, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"ymm1",
+ nullptr,
+ 32,
+ 0,
+ eEncodingVector,
+ eFormatVectorOfUInt8,
+ {dwarf_ymm1, dwarf_ymm1, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"ymm2",
+ nullptr,
+ 32,
+ 0,
+ eEncodingVector,
+ eFormatVectorOfUInt8,
+ {dwarf_ymm2, dwarf_ymm2, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"ymm3",
+ nullptr,
+ 32,
+ 0,
+ eEncodingVector,
+ eFormatVectorOfUInt8,
+ {dwarf_ymm3, dwarf_ymm3, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"ymm4",
+ nullptr,
+ 32,
+ 0,
+ eEncodingVector,
+ eFormatVectorOfUInt8,
+ {dwarf_ymm4, dwarf_ymm4, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"ymm5",
+ nullptr,
+ 32,
+ 0,
+ eEncodingVector,
+ eFormatVectorOfUInt8,
+ {dwarf_ymm5, dwarf_ymm5, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"ymm6",
+ nullptr,
+ 32,
+ 0,
+ eEncodingVector,
+ eFormatVectorOfUInt8,
+ {dwarf_ymm6, dwarf_ymm6, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"ymm7",
+ nullptr,
+ 32,
+ 0,
+ eEncodingVector,
+ eFormatVectorOfUInt8,
+ {dwarf_ymm7, dwarf_ymm7, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"ymm8",
+ nullptr,
+ 32,
+ 0,
+ eEncodingVector,
+ eFormatVectorOfUInt8,
+ {dwarf_ymm8, dwarf_ymm8, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"ymm9",
+ nullptr,
+ 32,
+ 0,
+ eEncodingVector,
+ eFormatVectorOfUInt8,
+ {dwarf_ymm9, dwarf_ymm9, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"ymm10",
+ nullptr,
+ 32,
+ 0,
+ eEncodingVector,
+ eFormatVectorOfUInt8,
+ {dwarf_ymm10, dwarf_ymm10, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"ymm11",
+ nullptr,
+ 32,
+ 0,
+ eEncodingVector,
+ eFormatVectorOfUInt8,
+ {dwarf_ymm11, dwarf_ymm11, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"ymm12",
+ nullptr,
+ 32,
+ 0,
+ eEncodingVector,
+ eFormatVectorOfUInt8,
+ {dwarf_ymm12, dwarf_ymm12, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"ymm13",
+ nullptr,
+ 32,
+ 0,
+ eEncodingVector,
+ eFormatVectorOfUInt8,
+ {dwarf_ymm13, dwarf_ymm13, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"ymm14",
+ nullptr,
+ 32,
+ 0,
+ eEncodingVector,
+ eFormatVectorOfUInt8,
+ {dwarf_ymm14, dwarf_ymm14, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0},
+ {"ymm15",
+ nullptr,
+ 32,
+ 0,
+ eEncodingVector,
+ eFormatVectorOfUInt8,
+ {dwarf_ymm15, dwarf_ymm15, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+ LLDB_INVALID_REGNUM},
+ nullptr,
+ nullptr,
+ nullptr,
+ 0}};
-static const uint32_t k_num_register_infos = llvm::array_lengthof(g_register_infos);
+static const uint32_t k_num_register_infos =
+ llvm::array_lengthof(g_register_infos);
static bool g_register_info_names_constified = false;
const lldb_private::RegisterInfo *
-ABISysV_x86_64::GetRegisterInfoArray (uint32_t &count)
-{
- // Make the C-string names and alt_names for the register infos into const
- // C-string values by having the ConstString unique the names in the global
- // constant C-string pool.
- if (!g_register_info_names_constified)
- {
- g_register_info_names_constified = true;
- for (uint32_t i=0; i<k_num_register_infos; ++i)
- {
- if (g_register_infos[i].name)
- g_register_infos[i].name = ConstString(g_register_infos[i].name).GetCString();
- if (g_register_infos[i].alt_name)
- g_register_infos[i].alt_name = ConstString(g_register_infos[i].alt_name).GetCString();
- }
+ABISysV_x86_64::GetRegisterInfoArray(uint32_t &count) {
+ // Make the C-string names and alt_names for the register infos into const
+ // C-string values by having the ConstString unique the names in the global
+ // constant C-string pool.
+ if (!g_register_info_names_constified) {
+ g_register_info_names_constified = true;
+ for (uint32_t i = 0; i < k_num_register_infos; ++i) {
+ if (g_register_infos[i].name)
+ g_register_infos[i].name =
+ ConstString(g_register_infos[i].name).GetCString();
+ if (g_register_infos[i].alt_name)
+ g_register_infos[i].alt_name =
+ ConstString(g_register_infos[i].alt_name).GetCString();
}
- count = k_num_register_infos;
- return g_register_infos;
+ }
+ count = k_num_register_infos;
+ return g_register_infos;
}
-bool
-ABISysV_x86_64::GetPointerReturnRegister (const char *&name)
-{
- name = "rax";
- return true;
+bool ABISysV_x86_64::GetPointerReturnRegister(const char *&name) {
+ name = "rax";
+ return true;
}
-size_t
-ABISysV_x86_64::GetRedZoneSize () const
-{
- return 128;
-}
+size_t ABISysV_x86_64::GetRedZoneSize() const { return 128; }
//------------------------------------------------------------------
// Static Functions
//------------------------------------------------------------------
ABISP
-ABISysV_x86_64::CreateInstance (const ArchSpec &arch)
-{
- static ABISP g_abi_sp;
- if (arch.GetTriple().getArch() == llvm::Triple::x86_64)
- {
- if (!g_abi_sp)
- g_abi_sp.reset (new ABISysV_x86_64);
- return g_abi_sp;
- }
- return ABISP();
+ABISysV_x86_64::CreateInstance(const ArchSpec &arch) {
+ static ABISP g_abi_sp;
+ if (arch.GetTriple().getArch() == llvm::Triple::x86_64) {
+ if (!g_abi_sp)
+ g_abi_sp.reset(new ABISysV_x86_64);
+ return g_abi_sp;
+ }
+ return ABISP();
}
-bool
-ABISysV_x86_64::PrepareTrivialCall (Thread &thread,
- addr_t sp,
- addr_t func_addr,
- addr_t return_addr,
- llvm::ArrayRef<addr_t> args) const
-{
- Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
-
- if (log)
- {
- StreamString s;
- s.Printf("ABISysV_x86_64::PrepareTrivialCall (tid = 0x%" PRIx64 ", sp = 0x%" PRIx64 ", func_addr = 0x%" PRIx64 ", return_addr = 0x%" PRIx64,
- thread.GetID(),
- (uint64_t)sp,
- (uint64_t)func_addr,
- (uint64_t)return_addr);
-
- for (size_t i = 0; i < args.size(); ++i)
- s.Printf (", arg%" PRIu64 " = 0x%" PRIx64, static_cast<uint64_t>(i + 1), args[i]);
- s.PutCString (")");
- log->PutCString(s.GetString().c_str());
- }
-
- RegisterContext *reg_ctx = thread.GetRegisterContext().get();
- if (!reg_ctx)
- return false;
-
- const RegisterInfo *reg_info = nullptr;
-
- if (args.size() > 6) // TODO handle more than 6 arguments
- return false;
-
- for (size_t i = 0; i < args.size(); ++i)
- {
- reg_info = reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG1 + i);
- if (log)
- log->Printf("About to write arg%" PRIu64 " (0x%" PRIx64 ") into %s", static_cast<uint64_t>(i + 1), args[i], reg_info->name);
- if (!reg_ctx->WriteRegisterFromUnsigned(reg_info, args[i]))
- return false;
- }
+bool ABISysV_x86_64::PrepareTrivialCall(Thread &thread, addr_t sp,
+ addr_t func_addr, addr_t return_addr,
+ llvm::ArrayRef<addr_t> args) const {
+ Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
+
+ if (log) {
+ StreamString s;
+ s.Printf("ABISysV_x86_64::PrepareTrivialCall (tid = 0x%" PRIx64
+ ", sp = 0x%" PRIx64 ", func_addr = 0x%" PRIx64
+ ", return_addr = 0x%" PRIx64,
+ thread.GetID(), (uint64_t)sp, (uint64_t)func_addr,
+ (uint64_t)return_addr);
- // First, align the SP
+ for (size_t i = 0; i < args.size(); ++i)
+ s.Printf(", arg%" PRIu64 " = 0x%" PRIx64, static_cast<uint64_t>(i + 1),
+ args[i]);
+ s.PutCString(")");
+ log->PutCString(s.GetString().c_str());
+ }
- if (log)
- log->Printf("16-byte aligning SP: 0x%" PRIx64 " to 0x%" PRIx64, (uint64_t)sp, (uint64_t)(sp & ~0xfull));
+ RegisterContext *reg_ctx = thread.GetRegisterContext().get();
+ if (!reg_ctx)
+ return false;
- sp &= ~(0xfull); // 16-byte alignment
+ const RegisterInfo *reg_info = nullptr;
- sp -= 8;
+ if (args.size() > 6) // TODO handle more than 6 arguments
+ return false;
- Error error;
- const RegisterInfo *pc_reg_info = reg_ctx->GetRegisterInfo (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_PC);
- const RegisterInfo *sp_reg_info = reg_ctx->GetRegisterInfo (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_SP);
- ProcessSP process_sp (thread.GetProcess());
+ for (size_t i = 0; i < args.size(); ++i) {
+ reg_info = reg_ctx->GetRegisterInfo(eRegisterKindGeneric,
+ LLDB_REGNUM_GENERIC_ARG1 + i);
+ if (log)
+ log->Printf("About to write arg%" PRIu64 " (0x%" PRIx64 ") into %s",
+ static_cast<uint64_t>(i + 1), args[i], reg_info->name);
+ if (!reg_ctx->WriteRegisterFromUnsigned(reg_info, args[i]))
+ return false;
+ }
+
+ // First, align the SP
+
+ if (log)
+ log->Printf("16-byte aligning SP: 0x%" PRIx64 " to 0x%" PRIx64,
+ (uint64_t)sp, (uint64_t)(sp & ~0xfull));
+
+ sp &= ~(0xfull); // 16-byte alignment
+
+ sp -= 8;
+
+ Error error;
+ const RegisterInfo *pc_reg_info =
+ reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_PC);
+ const RegisterInfo *sp_reg_info =
+ reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_SP);
+ ProcessSP process_sp(thread.GetProcess());
- RegisterValue reg_value;
+ RegisterValue reg_value;
#if 0
// This code adds an extra frame so that we don't lose the function that we came from
@@ -328,731 +1124,667 @@ ABISysV_x86_64::PrepareTrivialCall (Thre
sp -= 8;
}
-#endif
-
- if (log)
- log->Printf("Pushing the return address onto the stack: 0x%" PRIx64 ": 0x%" PRIx64, (uint64_t)sp, (uint64_t)return_addr);
+#endif
- // Save return address onto the stack
- if (!process_sp->WritePointerToMemory(sp, return_addr, error))
- return false;
+ if (log)
+ log->Printf("Pushing the return address onto the stack: 0x%" PRIx64
+ ": 0x%" PRIx64,
+ (uint64_t)sp, (uint64_t)return_addr);
- // %rsp is set to the actual stack value.
+ // Save return address onto the stack
+ if (!process_sp->WritePointerToMemory(sp, return_addr, error))
+ return false;
- if (log)
- log->Printf("Writing SP: 0x%" PRIx64, (uint64_t)sp);
-
- if (!reg_ctx->WriteRegisterFromUnsigned (sp_reg_info, sp))
- return false;
+ // %rsp is set to the actual stack value.
- // %rip is set to the address of the called function.
-
- if (log)
- log->Printf("Writing IP: 0x%" PRIx64, (uint64_t)func_addr);
+ if (log)
+ log->Printf("Writing SP: 0x%" PRIx64, (uint64_t)sp);
- if (!reg_ctx->WriteRegisterFromUnsigned (pc_reg_info, func_addr))
- return false;
+ if (!reg_ctx->WriteRegisterFromUnsigned(sp_reg_info, sp))
+ return false;
- return true;
-}
+ // %rip is set to the address of the called function.
-static bool ReadIntegerArgument(Scalar &scalar,
- unsigned int bit_width,
- bool is_signed,
- Thread &thread,
- uint32_t *argument_register_ids,
- unsigned int ¤t_argument_register,
- addr_t ¤t_stack_argument)
-{
- if (bit_width > 64)
- return false; // Scalar can't hold large integer arguments
-
- if (current_argument_register < 6)
- {
- scalar = thread.GetRegisterContext()->ReadRegisterAsUnsigned(argument_register_ids[current_argument_register], 0);
- current_argument_register++;
- if (is_signed)
- scalar.SignExtend (bit_width);
- }
- else
- {
- uint32_t byte_size = (bit_width + (8-1))/8;
- Error error;
- if (thread.GetProcess()->ReadScalarIntegerFromMemory(current_stack_argument, byte_size, is_signed, scalar, error))
- {
- current_stack_argument += byte_size;
- return true;
- }
- return false;
- }
- return true;
-}
+ if (log)
+ log->Printf("Writing IP: 0x%" PRIx64, (uint64_t)func_addr);
-bool
-ABISysV_x86_64::GetArgumentValues (Thread &thread,
- ValueList &values) const
-{
- unsigned int num_values = values.GetSize();
- unsigned int value_index;
-
- // Extract the register context so we can read arguments from registers
-
- RegisterContext *reg_ctx = thread.GetRegisterContext().get();
-
- if (!reg_ctx)
- return false;
-
- // Get the pointer to the first stack argument so we have a place to start
- // when reading data
-
- addr_t sp = reg_ctx->GetSP(0);
-
- if (!sp)
- return false;
-
- addr_t current_stack_argument = sp + 8; // jump over return address
-
- uint32_t argument_register_ids[6];
-
- argument_register_ids[0] = reg_ctx->GetRegisterInfo (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG1)->kinds[eRegisterKindLLDB];
- argument_register_ids[1] = reg_ctx->GetRegisterInfo (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG2)->kinds[eRegisterKindLLDB];
- argument_register_ids[2] = reg_ctx->GetRegisterInfo (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG3)->kinds[eRegisterKindLLDB];
- argument_register_ids[3] = reg_ctx->GetRegisterInfo (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG4)->kinds[eRegisterKindLLDB];
- argument_register_ids[4] = reg_ctx->GetRegisterInfo (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG5)->kinds[eRegisterKindLLDB];
- argument_register_ids[5] = reg_ctx->GetRegisterInfo (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG6)->kinds[eRegisterKindLLDB];
-
- unsigned int current_argument_register = 0;
-
- for (value_index = 0;
- value_index < num_values;
- ++value_index)
- {
- Value *value = values.GetValueAtIndex(value_index);
-
- if (!value)
- return false;
-
- // We currently only support extracting values with Clang QualTypes.
- // Do we care about others?
- CompilerType compiler_type = value->GetCompilerType();
- if (!compiler_type)
- return false;
- bool is_signed;
-
- if (compiler_type.IsIntegerOrEnumerationType (is_signed))
- {
- ReadIntegerArgument(value->GetScalar(),
- compiler_type.GetBitSize(&thread),
- is_signed,
- thread,
- argument_register_ids,
- current_argument_register,
- current_stack_argument);
- }
- else if (compiler_type.IsPointerType ())
- {
- ReadIntegerArgument(value->GetScalar(),
- compiler_type.GetBitSize(&thread),
- false,
- thread,
- argument_register_ids,
- current_argument_register,
- current_stack_argument);
- }
- }
-
- return true;
+ if (!reg_ctx->WriteRegisterFromUnsigned(pc_reg_info, func_addr))
+ return false;
+
+ return true;
}
-Error
-ABISysV_x86_64::SetReturnValueObject(lldb::StackFrameSP &frame_sp, lldb::ValueObjectSP &new_value_sp)
-{
+static bool ReadIntegerArgument(Scalar &scalar, unsigned int bit_width,
+ bool is_signed, Thread &thread,
+ uint32_t *argument_register_ids,
+ unsigned int ¤t_argument_register,
+ addr_t ¤t_stack_argument) {
+ if (bit_width > 64)
+ return false; // Scalar can't hold large integer arguments
+
+ if (current_argument_register < 6) {
+ scalar = thread.GetRegisterContext()->ReadRegisterAsUnsigned(
+ argument_register_ids[current_argument_register], 0);
+ current_argument_register++;
+ if (is_signed)
+ scalar.SignExtend(bit_width);
+ } else {
+ uint32_t byte_size = (bit_width + (8 - 1)) / 8;
Error error;
- if (!new_value_sp)
- {
- error.SetErrorString("Empty value object for return value.");
- return error;
+ if (thread.GetProcess()->ReadScalarIntegerFromMemory(
+ current_stack_argument, byte_size, is_signed, scalar, error)) {
+ current_stack_argument += byte_size;
+ return true;
}
-
- CompilerType compiler_type = new_value_sp->GetCompilerType();
+ return false;
+ }
+ return true;
+}
+
+bool ABISysV_x86_64::GetArgumentValues(Thread &thread,
+ ValueList &values) const {
+ unsigned int num_values = values.GetSize();
+ unsigned int value_index;
+
+ // Extract the register context so we can read arguments from registers
+
+ RegisterContext *reg_ctx = thread.GetRegisterContext().get();
+
+ if (!reg_ctx)
+ return false;
+
+ // Get the pointer to the first stack argument so we have a place to start
+ // when reading data
+
+ addr_t sp = reg_ctx->GetSP(0);
+
+ if (!sp)
+ return false;
+
+ addr_t current_stack_argument = sp + 8; // jump over return address
+
+ uint32_t argument_register_ids[6];
+
+ argument_register_ids[0] =
+ reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG1)
+ ->kinds[eRegisterKindLLDB];
+ argument_register_ids[1] =
+ reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG2)
+ ->kinds[eRegisterKindLLDB];
+ argument_register_ids[2] =
+ reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG3)
+ ->kinds[eRegisterKindLLDB];
+ argument_register_ids[3] =
+ reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG4)
+ ->kinds[eRegisterKindLLDB];
+ argument_register_ids[4] =
+ reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG5)
+ ->kinds[eRegisterKindLLDB];
+ argument_register_ids[5] =
+ reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG6)
+ ->kinds[eRegisterKindLLDB];
+
+ unsigned int current_argument_register = 0;
+
+ for (value_index = 0; value_index < num_values; ++value_index) {
+ Value *value = values.GetValueAtIndex(value_index);
+
+ if (!value)
+ return false;
+
+ // We currently only support extracting values with Clang QualTypes.
+ // Do we care about others?
+ CompilerType compiler_type = value->GetCompilerType();
if (!compiler_type)
- {
- error.SetErrorString ("Null clang type for return value.");
- return error;
- }
-
- Thread *thread = frame_sp->GetThread().get();
-
+ return false;
bool is_signed;
- uint32_t count;
- bool is_complex;
-
- RegisterContext *reg_ctx = thread->GetRegisterContext().get();
- bool set_it_simple = false;
- if (compiler_type.IsIntegerOrEnumerationType (is_signed) || compiler_type.IsPointerType())
- {
- const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoByName("rax", 0);
+ if (compiler_type.IsIntegerOrEnumerationType(is_signed)) {
+ ReadIntegerArgument(value->GetScalar(), compiler_type.GetBitSize(&thread),
+ is_signed, thread, argument_register_ids,
+ current_argument_register, current_stack_argument);
+ } else if (compiler_type.IsPointerType()) {
+ ReadIntegerArgument(value->GetScalar(), compiler_type.GetBitSize(&thread),
+ false, thread, argument_register_ids,
+ current_argument_register, current_stack_argument);
+ }
+ }
+ return true;
+}
+
+Error ABISysV_x86_64::SetReturnValueObject(lldb::StackFrameSP &frame_sp,
+ lldb::ValueObjectSP &new_value_sp) {
+ Error error;
+ if (!new_value_sp) {
+ error.SetErrorString("Empty value object for return value.");
+ return error;
+ }
+
+ CompilerType compiler_type = new_value_sp->GetCompilerType();
+ if (!compiler_type) {
+ error.SetErrorString("Null clang type for return value.");
+ return error;
+ }
+
+ Thread *thread = frame_sp->GetThread().get();
+
+ bool is_signed;
+ uint32_t count;
+ bool is_complex;
+
+ RegisterContext *reg_ctx = thread->GetRegisterContext().get();
+
+ bool set_it_simple = false;
+ if (compiler_type.IsIntegerOrEnumerationType(is_signed) ||
+ compiler_type.IsPointerType()) {
+ const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoByName("rax", 0);
+
+ DataExtractor data;
+ Error data_error;
+ size_t num_bytes = new_value_sp->GetData(data, data_error);
+ if (data_error.Fail()) {
+ error.SetErrorStringWithFormat(
+ "Couldn't convert return value to raw data: %s",
+ data_error.AsCString());
+ return error;
+ }
+ lldb::offset_t offset = 0;
+ if (num_bytes <= 8) {
+ uint64_t raw_value = data.GetMaxU64(&offset, num_bytes);
+
+ if (reg_ctx->WriteRegisterFromUnsigned(reg_info, raw_value))
+ set_it_simple = true;
+ } else {
+ error.SetErrorString("We don't support returning longer than 64 bit "
+ "integer values at present.");
+ }
+ } else if (compiler_type.IsFloatingPointType(count, is_complex)) {
+ if (is_complex)
+ error.SetErrorString(
+ "We don't support returning complex values at present");
+ else {
+ size_t bit_width = compiler_type.GetBitSize(frame_sp.get());
+ if (bit_width <= 64) {
+ const RegisterInfo *xmm0_info =
+ reg_ctx->GetRegisterInfoByName("xmm0", 0);
+ RegisterValue xmm0_value;
DataExtractor data;
Error data_error;
size_t num_bytes = new_value_sp->GetData(data, data_error);
- if (data_error.Fail())
- {
- error.SetErrorStringWithFormat("Couldn't convert return value to raw data: %s", data_error.AsCString());
- return error;
- }
- lldb::offset_t offset = 0;
- if (num_bytes <= 8)
- {
- uint64_t raw_value = data.GetMaxU64(&offset, num_bytes);
-
- if (reg_ctx->WriteRegisterFromUnsigned (reg_info, raw_value))
- set_it_simple = true;
- }
- else
- {
- error.SetErrorString("We don't support returning longer than 64 bit integer values at present.");
+ if (data_error.Fail()) {
+ error.SetErrorStringWithFormat(
+ "Couldn't convert return value to raw data: %s",
+ data_error.AsCString());
+ return error;
}
+
+ unsigned char buffer[16];
+ ByteOrder byte_order = data.GetByteOrder();
+
+ data.CopyByteOrderedData(0, num_bytes, buffer, 16, byte_order);
+ xmm0_value.SetBytes(buffer, 16, byte_order);
+ reg_ctx->WriteRegister(xmm0_info, xmm0_value);
+ set_it_simple = true;
+ } else {
+ // FIXME - don't know how to do 80 bit long doubles yet.
+ error.SetErrorString(
+ "We don't support returning float values > 64 bits at present");
+ }
}
- else if (compiler_type.IsFloatingPointType (count, is_complex))
- {
- if (is_complex)
- error.SetErrorString ("We don't support returning complex values at present");
- else
- {
- size_t bit_width = compiler_type.GetBitSize(frame_sp.get());
- if (bit_width <= 64)
- {
- const RegisterInfo *xmm0_info = reg_ctx->GetRegisterInfoByName("xmm0", 0);
- RegisterValue xmm0_value;
- DataExtractor data;
- Error data_error;
- size_t num_bytes = new_value_sp->GetData(data, data_error);
- if (data_error.Fail())
- {
- error.SetErrorStringWithFormat("Couldn't convert return value to raw data: %s", data_error.AsCString());
- return error;
- }
-
- unsigned char buffer[16];
- ByteOrder byte_order = data.GetByteOrder();
-
- data.CopyByteOrderedData (0, num_bytes, buffer, 16, byte_order);
- xmm0_value.SetBytes(buffer, 16, byte_order);
- reg_ctx->WriteRegister(xmm0_info, xmm0_value);
- set_it_simple = true;
- }
- else
- {
- // FIXME - don't know how to do 80 bit long doubles yet.
- error.SetErrorString ("We don't support returning float values > 64 bits at present");
- }
- }
- }
-
- if (!set_it_simple)
- {
- // Okay we've got a structure or something that doesn't fit in a simple register.
- // We should figure out where it really goes, but we don't support this yet.
- error.SetErrorString ("We only support setting simple integer and float return types at present.");
- }
-
- return error;
+ }
+
+ if (!set_it_simple) {
+ // Okay we've got a structure or something that doesn't fit in a simple
+ // register.
+ // We should figure out where it really goes, but we don't support this yet.
+ error.SetErrorString("We only support setting simple integer and float "
+ "return types at present.");
+ }
+
+ return error;
}
-ValueObjectSP
-ABISysV_x86_64::GetReturnValueObjectSimple (Thread &thread,
- CompilerType &return_compiler_type) const
-{
- ValueObjectSP return_valobj_sp;
- Value value;
-
- if (!return_compiler_type)
- return return_valobj_sp;
-
- //value.SetContext (Value::eContextTypeClangType, return_value_type);
- value.SetCompilerType (return_compiler_type);
-
- RegisterContext *reg_ctx = thread.GetRegisterContext().get();
- if (!reg_ctx)
- return return_valobj_sp;
-
- const uint32_t type_flags = return_compiler_type.GetTypeInfo ();
- if (type_flags & eTypeIsScalar)
- {
- value.SetValueType(Value::eValueTypeScalar);
+ValueObjectSP ABISysV_x86_64::GetReturnValueObjectSimple(
+ Thread &thread, CompilerType &return_compiler_type) const {
+ ValueObjectSP return_valobj_sp;
+ Value value;
- bool success = false;
- if (type_flags & eTypeIsInteger)
- {
- // Extract the register context so we can read arguments from registers
-
- const size_t byte_size = return_compiler_type.GetByteSize(nullptr);
- uint64_t raw_value = thread.GetRegisterContext()->ReadRegisterAsUnsigned(reg_ctx->GetRegisterInfoByName("rax", 0), 0);
- const bool is_signed = (type_flags & eTypeIsSigned) != 0;
- switch (byte_size)
- {
- default:
- break;
-
- case sizeof(uint64_t):
- if (is_signed)
- value.GetScalar() = (int64_t)(raw_value);
- else
- value.GetScalar() = (uint64_t)(raw_value);
- success = true;
- break;
+ if (!return_compiler_type)
+ return return_valobj_sp;
- case sizeof(uint32_t):
- if (is_signed)
- value.GetScalar() = (int32_t)(raw_value & UINT32_MAX);
- else
- value.GetScalar() = (uint32_t)(raw_value & UINT32_MAX);
- success = true;
- break;
+ // value.SetContext (Value::eContextTypeClangType, return_value_type);
+ value.SetCompilerType(return_compiler_type);
- case sizeof(uint16_t):
- if (is_signed)
- value.GetScalar() = (int16_t)(raw_value & UINT16_MAX);
- else
- value.GetScalar() = (uint16_t)(raw_value & UINT16_MAX);
- success = true;
- break;
+ RegisterContext *reg_ctx = thread.GetRegisterContext().get();
+ if (!reg_ctx)
+ return return_valobj_sp;
+
+ const uint32_t type_flags = return_compiler_type.GetTypeInfo();
+ if (type_flags & eTypeIsScalar) {
+ value.SetValueType(Value::eValueTypeScalar);
+
+ bool success = false;
+ if (type_flags & eTypeIsInteger) {
+ // Extract the register context so we can read arguments from registers
+
+ const size_t byte_size = return_compiler_type.GetByteSize(nullptr);
+ uint64_t raw_value = thread.GetRegisterContext()->ReadRegisterAsUnsigned(
+ reg_ctx->GetRegisterInfoByName("rax", 0), 0);
+ const bool is_signed = (type_flags & eTypeIsSigned) != 0;
+ switch (byte_size) {
+ default:
+ break;
+
+ case sizeof(uint64_t):
+ if (is_signed)
+ value.GetScalar() = (int64_t)(raw_value);
+ else
+ value.GetScalar() = (uint64_t)(raw_value);
+ success = true;
+ break;
+
+ case sizeof(uint32_t):
+ if (is_signed)
+ value.GetScalar() = (int32_t)(raw_value & UINT32_MAX);
+ else
+ value.GetScalar() = (uint32_t)(raw_value & UINT32_MAX);
+ success = true;
+ break;
+
+ case sizeof(uint16_t):
+ if (is_signed)
+ value.GetScalar() = (int16_t)(raw_value & UINT16_MAX);
+ else
+ value.GetScalar() = (uint16_t)(raw_value & UINT16_MAX);
+ success = true;
+ break;
- case sizeof(uint8_t):
- if (is_signed)
- value.GetScalar() = (int8_t)(raw_value & UINT8_MAX);
- else
- value.GetScalar() = (uint8_t)(raw_value & UINT8_MAX);
+ case sizeof(uint8_t):
+ if (is_signed)
+ value.GetScalar() = (int8_t)(raw_value & UINT8_MAX);
+ else
+ value.GetScalar() = (uint8_t)(raw_value & UINT8_MAX);
+ success = true;
+ break;
+ }
+ } else if (type_flags & eTypeIsFloat) {
+ if (type_flags & eTypeIsComplex) {
+ // Don't handle complex yet.
+ } else {
+ const size_t byte_size = return_compiler_type.GetByteSize(nullptr);
+ if (byte_size <= sizeof(long double)) {
+ const RegisterInfo *xmm0_info =
+ reg_ctx->GetRegisterInfoByName("xmm0", 0);
+ RegisterValue xmm0_value;
+ if (reg_ctx->ReadRegister(xmm0_info, xmm0_value)) {
+ DataExtractor data;
+ if (xmm0_value.GetData(data)) {
+ lldb::offset_t offset = 0;
+ if (byte_size == sizeof(float)) {
+ value.GetScalar() = (float)data.GetFloat(&offset);
success = true;
- break;
- }
- }
- else if (type_flags & eTypeIsFloat)
- {
- if (type_flags & eTypeIsComplex)
- {
- // Don't handle complex yet.
- }
- else
- {
- const size_t byte_size = return_compiler_type.GetByteSize(nullptr);
- if (byte_size <= sizeof(long double))
- {
- const RegisterInfo *xmm0_info = reg_ctx->GetRegisterInfoByName("xmm0", 0);
- RegisterValue xmm0_value;
- if (reg_ctx->ReadRegister (xmm0_info, xmm0_value))
- {
- DataExtractor data;
- if (xmm0_value.GetData(data))
- {
- lldb::offset_t offset = 0;
- if (byte_size == sizeof(float))
- {
- value.GetScalar() = (float) data.GetFloat(&offset);
- success = true;
- }
- else if (byte_size == sizeof(double))
- {
- value.GetScalar() = (double) data.GetDouble(&offset);
- success = true;
- }
- else if (byte_size == sizeof(long double))
- {
- // Don't handle long double since that can be encoded as 80 bit floats...
- }
- }
- }
- }
+ } else if (byte_size == sizeof(double)) {
+ value.GetScalar() = (double)data.GetDouble(&offset);
+ success = true;
+ } else if (byte_size == sizeof(long double)) {
+ // Don't handle long double since that can be encoded as 80 bit
+ // floats...
+ }
}
+ }
}
-
- if (success)
- return_valobj_sp = ValueObjectConstResult::Create (thread.GetStackFrameAtIndex(0).get(),
- value,
- ConstString(""));
- }
- else if (type_flags & eTypeIsPointer)
- {
- unsigned rax_id = reg_ctx->GetRegisterInfoByName("rax", 0)->kinds[eRegisterKindLLDB];
- value.GetScalar() = (uint64_t)thread.GetRegisterContext()->ReadRegisterAsUnsigned(rax_id, 0);
- value.SetValueType(Value::eValueTypeScalar);
- return_valobj_sp = ValueObjectConstResult::Create (thread.GetStackFrameAtIndex(0).get(),
- value,
- ConstString(""));
+ }
}
- else if (type_flags & eTypeIsVector)
- {
- const size_t byte_size = return_compiler_type.GetByteSize(nullptr);
- if (byte_size > 0)
- {
- const RegisterInfo *altivec_reg = reg_ctx->GetRegisterInfoByName("xmm0", 0);
- if (altivec_reg == nullptr)
- altivec_reg = reg_ctx->GetRegisterInfoByName("mm0", 0);
-
- if (altivec_reg)
- {
- if (byte_size <= altivec_reg->byte_size)
- {
- ProcessSP process_sp (thread.GetProcess());
- if (process_sp)
- {
- std::unique_ptr<DataBufferHeap> heap_data_ap (new DataBufferHeap(byte_size, 0));
- const ByteOrder byte_order = process_sp->GetByteOrder();
- RegisterValue reg_value;
- if (reg_ctx->ReadRegister(altivec_reg, reg_value))
- {
- Error error;
- if (reg_value.GetAsMemoryData (altivec_reg,
- heap_data_ap->GetBytes(),
- heap_data_ap->GetByteSize(),
- byte_order,
- error))
- {
- DataExtractor data (DataBufferSP (heap_data_ap.release()),
- byte_order,
- process_sp->GetTarget().GetArchitecture().GetAddressByteSize());
- return_valobj_sp = ValueObjectConstResult::Create (&thread,
- return_compiler_type,
- ConstString(""),
- data);
- }
- }
- }
- }
- else if (byte_size <= altivec_reg->byte_size*2)
- {
- const RegisterInfo *altivec_reg2 = reg_ctx->GetRegisterInfoByName("xmm1", 0);
- if (altivec_reg2)
- {
- ProcessSP process_sp (thread.GetProcess());
- if (process_sp)
- {
- std::unique_ptr<DataBufferHeap> heap_data_ap (new DataBufferHeap(byte_size, 0));
- const ByteOrder byte_order = process_sp->GetByteOrder();
- RegisterValue reg_value;
- RegisterValue reg_value2;
- if (reg_ctx->ReadRegister(altivec_reg, reg_value) && reg_ctx->ReadRegister(altivec_reg2, reg_value2))
- {
-
- Error error;
- if (reg_value.GetAsMemoryData (altivec_reg,
- heap_data_ap->GetBytes(),
- altivec_reg->byte_size,
- byte_order,
- error) &&
- reg_value2.GetAsMemoryData (altivec_reg2,
- heap_data_ap->GetBytes() + altivec_reg->byte_size,
- heap_data_ap->GetByteSize() - altivec_reg->byte_size,
- byte_order,
- error))
- {
- DataExtractor data (DataBufferSP (heap_data_ap.release()),
- byte_order,
- process_sp->GetTarget().GetArchitecture().GetAddressByteSize());
- return_valobj_sp = ValueObjectConstResult::Create (&thread,
- return_compiler_type,
- ConstString(""),
- data);
- }
- }
- }
- }
+
+ if (success)
+ return_valobj_sp = ValueObjectConstResult::Create(
+ thread.GetStackFrameAtIndex(0).get(), value, ConstString(""));
+ } else if (type_flags & eTypeIsPointer) {
+ unsigned rax_id =
+ reg_ctx->GetRegisterInfoByName("rax", 0)->kinds[eRegisterKindLLDB];
+ value.GetScalar() =
+ (uint64_t)thread.GetRegisterContext()->ReadRegisterAsUnsigned(rax_id,
+ 0);
+ value.SetValueType(Value::eValueTypeScalar);
+ return_valobj_sp = ValueObjectConstResult::Create(
+ thread.GetStackFrameAtIndex(0).get(), value, ConstString(""));
+ } else if (type_flags & eTypeIsVector) {
+ const size_t byte_size = return_compiler_type.GetByteSize(nullptr);
+ if (byte_size > 0) {
+ const RegisterInfo *altivec_reg =
+ reg_ctx->GetRegisterInfoByName("xmm0", 0);
+ if (altivec_reg == nullptr)
+ altivec_reg = reg_ctx->GetRegisterInfoByName("mm0", 0);
+
+ if (altivec_reg) {
+ if (byte_size <= altivec_reg->byte_size) {
+ ProcessSP process_sp(thread.GetProcess());
+ if (process_sp) {
+ std::unique_ptr<DataBufferHeap> heap_data_ap(
+ new DataBufferHeap(byte_size, 0));
+ const ByteOrder byte_order = process_sp->GetByteOrder();
+ RegisterValue reg_value;
+ if (reg_ctx->ReadRegister(altivec_reg, reg_value)) {
+ Error error;
+ if (reg_value.GetAsMemoryData(
+ altivec_reg, heap_data_ap->GetBytes(),
+ heap_data_ap->GetByteSize(), byte_order, error)) {
+ DataExtractor data(DataBufferSP(heap_data_ap.release()),
+ byte_order, process_sp->GetTarget()
+ .GetArchitecture()
+ .GetAddressByteSize());
+ return_valobj_sp = ValueObjectConstResult::Create(
+ &thread, return_compiler_type, ConstString(""), data);
+ }
+ }
+ }
+ } else if (byte_size <= altivec_reg->byte_size * 2) {
+ const RegisterInfo *altivec_reg2 =
+ reg_ctx->GetRegisterInfoByName("xmm1", 0);
+ if (altivec_reg2) {
+ ProcessSP process_sp(thread.GetProcess());
+ if (process_sp) {
+ std::unique_ptr<DataBufferHeap> heap_data_ap(
+ new DataBufferHeap(byte_size, 0));
+ const ByteOrder byte_order = process_sp->GetByteOrder();
+ RegisterValue reg_value;
+ RegisterValue reg_value2;
+ if (reg_ctx->ReadRegister(altivec_reg, reg_value) &&
+ reg_ctx->ReadRegister(altivec_reg2, reg_value2)) {
+
+ Error error;
+ if (reg_value.GetAsMemoryData(
+ altivec_reg, heap_data_ap->GetBytes(),
+ altivec_reg->byte_size, byte_order, error) &&
+ reg_value2.GetAsMemoryData(
+ altivec_reg2,
+ heap_data_ap->GetBytes() + altivec_reg->byte_size,
+ heap_data_ap->GetByteSize() - altivec_reg->byte_size,
+ byte_order, error)) {
+ DataExtractor data(DataBufferSP(heap_data_ap.release()),
+ byte_order, process_sp->GetTarget()
+ .GetArchitecture()
+ .GetAddressByteSize());
+ return_valobj_sp = ValueObjectConstResult::Create(
+ &thread, return_compiler_type, ConstString(""), data);
}
+ }
}
+ }
}
+ }
}
-
- return return_valobj_sp;
+ }
+
+ return return_valobj_sp;
}
-ValueObjectSP
-ABISysV_x86_64::GetReturnValueObjectImpl (Thread &thread, CompilerType &return_compiler_type) const
-{
- ValueObjectSP return_valobj_sp;
-
- if (!return_compiler_type)
- return return_valobj_sp;
-
- ExecutionContext exe_ctx (thread.shared_from_this());
- return_valobj_sp = GetReturnValueObjectSimple(thread, return_compiler_type);
- if (return_valobj_sp)
- return return_valobj_sp;
-
- RegisterContextSP reg_ctx_sp = thread.GetRegisterContext();
- if (!reg_ctx_sp)
- return return_valobj_sp;
-
- const size_t bit_width = return_compiler_type.GetBitSize(&thread);
- if (return_compiler_type.IsAggregateType())
- {
- Target *target = exe_ctx.GetTargetPtr();
- bool is_memory = true;
- if (bit_width <= 128)
- {
- ByteOrder target_byte_order = target->GetArchitecture().GetByteOrder();
- DataBufferSP data_sp (new DataBufferHeap(16, 0));
- DataExtractor return_ext (data_sp,
- target_byte_order,
- target->GetArchitecture().GetAddressByteSize());
-
- const RegisterInfo *rax_info = reg_ctx_sp->GetRegisterInfoByName("rax", 0);
- const RegisterInfo *rdx_info = reg_ctx_sp->GetRegisterInfoByName("rdx", 0);
- const RegisterInfo *xmm0_info = reg_ctx_sp->GetRegisterInfoByName("xmm0", 0);
- const RegisterInfo *xmm1_info = reg_ctx_sp->GetRegisterInfoByName("xmm1", 0);
-
- RegisterValue rax_value, rdx_value, xmm0_value, xmm1_value;
- reg_ctx_sp->ReadRegister (rax_info, rax_value);
- reg_ctx_sp->ReadRegister (rdx_info, rdx_value);
- reg_ctx_sp->ReadRegister (xmm0_info, xmm0_value);
- reg_ctx_sp->ReadRegister (xmm1_info, xmm1_value);
+ValueObjectSP ABISysV_x86_64::GetReturnValueObjectImpl(
+ Thread &thread, CompilerType &return_compiler_type) const {
+ ValueObjectSP return_valobj_sp;
- DataExtractor rax_data, rdx_data, xmm0_data, xmm1_data;
-
- rax_value.GetData(rax_data);
- rdx_value.GetData(rdx_data);
- xmm0_value.GetData(xmm0_data);
- xmm1_value.GetData(xmm1_data);
-
- uint32_t fp_bytes = 0; // Tracks how much of the xmm registers we've consumed so far
- uint32_t integer_bytes = 0; // Tracks how much of the rax/rds registers we've consumed so far
-
- const uint32_t num_children = return_compiler_type.GetNumFields ();
-
- // Since we are in the small struct regime, assume we are not in memory.
- is_memory = false;
-
- for (uint32_t idx = 0; idx < num_children; idx++)
- {
- std::string name;
- uint64_t field_bit_offset = 0;
- bool is_signed;
- bool is_complex;
- uint32_t count;
-
- CompilerType field_compiler_type = return_compiler_type.GetFieldAtIndex(idx, name, &field_bit_offset, nullptr, nullptr);
- const size_t field_bit_width = field_compiler_type.GetBitSize(&thread);
-
- // if we don't know the size of the field (e.g. invalid type), just bail out
- if (field_bit_width == 0)
- break;
-
- // If there are any unaligned fields, this is stored in memory.
- if (field_bit_offset % field_bit_width != 0)
- {
- is_memory = true;
- break;
- }
-
- uint32_t field_byte_width = field_bit_width/8;
- uint32_t field_byte_offset = field_bit_offset/8;
-
- DataExtractor *copy_from_extractor = nullptr;
- uint32_t copy_from_offset = 0;
-
- if (field_compiler_type.IsIntegerOrEnumerationType (is_signed) || field_compiler_type.IsPointerType ())
- {
- if (integer_bytes < 8)
- {
- if (integer_bytes + field_byte_width <= 8)
- {
- // This is in RAX, copy from register to our result structure:
- copy_from_extractor = &rax_data;
- copy_from_offset = integer_bytes;
- integer_bytes += field_byte_width;
- }
- else
- {
- // The next field wouldn't fit in the remaining space, so we pushed it to rdx.
- copy_from_extractor = &rdx_data;
- copy_from_offset = 0;
- integer_bytes = 8 + field_byte_width;
- }
- }
- else if (integer_bytes + field_byte_width <= 16)
- {
- copy_from_extractor = &rdx_data;
- copy_from_offset = integer_bytes - 8;
- integer_bytes += field_byte_width;
- }
- else
- {
- // The last field didn't fit. I can't see how that would happen w/o the overall size being
- // greater than 16 bytes. For now, return a nullptr return value object.
- return return_valobj_sp;
- }
+ if (!return_compiler_type)
+ return return_valobj_sp;
+
+ ExecutionContext exe_ctx(thread.shared_from_this());
+ return_valobj_sp = GetReturnValueObjectSimple(thread, return_compiler_type);
+ if (return_valobj_sp)
+ return return_valobj_sp;
+
+ RegisterContextSP reg_ctx_sp = thread.GetRegisterContext();
+ if (!reg_ctx_sp)
+ return return_valobj_sp;
+
+ const size_t bit_width = return_compiler_type.GetBitSize(&thread);
+ if (return_compiler_type.IsAggregateType()) {
+ Target *target = exe_ctx.GetTargetPtr();
+ bool is_memory = true;
+ if (bit_width <= 128) {
+ ByteOrder target_byte_order = target->GetArchitecture().GetByteOrder();
+ DataBufferSP data_sp(new DataBufferHeap(16, 0));
+ DataExtractor return_ext(data_sp, target_byte_order,
+ target->GetArchitecture().GetAddressByteSize());
+
+ const RegisterInfo *rax_info =
+ reg_ctx_sp->GetRegisterInfoByName("rax", 0);
+ const RegisterInfo *rdx_info =
+ reg_ctx_sp->GetRegisterInfoByName("rdx", 0);
+ const RegisterInfo *xmm0_info =
+ reg_ctx_sp->GetRegisterInfoByName("xmm0", 0);
+ const RegisterInfo *xmm1_info =
+ reg_ctx_sp->GetRegisterInfoByName("xmm1", 0);
+
+ RegisterValue rax_value, rdx_value, xmm0_value, xmm1_value;
+ reg_ctx_sp->ReadRegister(rax_info, rax_value);
+ reg_ctx_sp->ReadRegister(rdx_info, rdx_value);
+ reg_ctx_sp->ReadRegister(xmm0_info, xmm0_value);
+ reg_ctx_sp->ReadRegister(xmm1_info, xmm1_value);
+
+ DataExtractor rax_data, rdx_data, xmm0_data, xmm1_data;
+
+ rax_value.GetData(rax_data);
+ rdx_value.GetData(rdx_data);
+ xmm0_value.GetData(xmm0_data);
+ xmm1_value.GetData(xmm1_data);
+
+ uint32_t fp_bytes =
+ 0; // Tracks how much of the xmm registers we've consumed so far
+ uint32_t integer_bytes =
+ 0; // Tracks how much of the rax/rds registers we've consumed so far
+
+ const uint32_t num_children = return_compiler_type.GetNumFields();
+
+ // Since we are in the small struct regime, assume we are not in memory.
+ is_memory = false;
+
+ for (uint32_t idx = 0; idx < num_children; idx++) {
+ std::string name;
+ uint64_t field_bit_offset = 0;
+ bool is_signed;
+ bool is_complex;
+ uint32_t count;
+
+ CompilerType field_compiler_type = return_compiler_type.GetFieldAtIndex(
+ idx, name, &field_bit_offset, nullptr, nullptr);
+ const size_t field_bit_width = field_compiler_type.GetBitSize(&thread);
+
+ // if we don't know the size of the field (e.g. invalid type), just bail
+ // out
+ if (field_bit_width == 0)
+ break;
+
+ // If there are any unaligned fields, this is stored in memory.
+ if (field_bit_offset % field_bit_width != 0) {
+ is_memory = true;
+ break;
+ }
+
+ uint32_t field_byte_width = field_bit_width / 8;
+ uint32_t field_byte_offset = field_bit_offset / 8;
+
+ DataExtractor *copy_from_extractor = nullptr;
+ uint32_t copy_from_offset = 0;
+
+ if (field_compiler_type.IsIntegerOrEnumerationType(is_signed) ||
+ field_compiler_type.IsPointerType()) {
+ if (integer_bytes < 8) {
+ if (integer_bytes + field_byte_width <= 8) {
+ // This is in RAX, copy from register to our result structure:
+ copy_from_extractor = &rax_data;
+ copy_from_offset = integer_bytes;
+ integer_bytes += field_byte_width;
+ } else {
+ // The next field wouldn't fit in the remaining space, so we
+ // pushed it to rdx.
+ copy_from_extractor = &rdx_data;
+ copy_from_offset = 0;
+ integer_bytes = 8 + field_byte_width;
+ }
+ } else if (integer_bytes + field_byte_width <= 16) {
+ copy_from_extractor = &rdx_data;
+ copy_from_offset = integer_bytes - 8;
+ integer_bytes += field_byte_width;
+ } else {
+ // The last field didn't fit. I can't see how that would happen w/o
+ // the overall size being
+ // greater than 16 bytes. For now, return a nullptr return value
+ // object.
+ return return_valobj_sp;
+ }
+ } else if (field_compiler_type.IsFloatingPointType(count, is_complex)) {
+ // Structs with long doubles are always passed in memory.
+ if (field_bit_width == 128) {
+ is_memory = true;
+ break;
+ } else if (field_bit_width == 64) {
+ // These have to be in a single xmm register.
+ if (fp_bytes == 0)
+ copy_from_extractor = &xmm0_data;
+ else
+ copy_from_extractor = &xmm1_data;
+
+ copy_from_offset = 0;
+ fp_bytes += field_byte_width;
+ } else if (field_bit_width == 32) {
+ // This one is kind of complicated. If we are in an "eightbyte"
+ // with another float, we'll
+ // be stuffed into an xmm register with it. If we are in an
+ // "eightbyte" with one or more ints,
+ // then we will be stuffed into the appropriate GPR with them.
+ bool in_gpr;
+ if (field_byte_offset % 8 == 0) {
+ // We are at the beginning of one of the eightbytes, so check the
+ // next element (if any)
+ if (idx == num_children - 1)
+ in_gpr = false;
+ else {
+ uint64_t next_field_bit_offset = 0;
+ CompilerType next_field_compiler_type =
+ return_compiler_type.GetFieldAtIndex(idx + 1, name,
+ &next_field_bit_offset,
+ nullptr, nullptr);
+ if (next_field_compiler_type.IsIntegerOrEnumerationType(
+ is_signed))
+ in_gpr = true;
+ else {
+ copy_from_offset = 0;
+ in_gpr = false;
}
- else if (field_compiler_type.IsFloatingPointType (count, is_complex))
- {
- // Structs with long doubles are always passed in memory.
- if (field_bit_width == 128)
- {
- is_memory = true;
- break;
- }
- else if (field_bit_width == 64)
- {
- // These have to be in a single xmm register.
- if (fp_bytes == 0)
- copy_from_extractor = &xmm0_data;
- else
- copy_from_extractor = &xmm1_data;
-
- copy_from_offset = 0;
- fp_bytes += field_byte_width;
- }
- else if (field_bit_width == 32)
- {
- // This one is kind of complicated. If we are in an "eightbyte" with another float, we'll
- // be stuffed into an xmm register with it. If we are in an "eightbyte" with one or more ints,
- // then we will be stuffed into the appropriate GPR with them.
- bool in_gpr;
- if (field_byte_offset % 8 == 0)
- {
- // We are at the beginning of one of the eightbytes, so check the next element (if any)
- if (idx == num_children - 1)
- in_gpr = false;
- else
- {
- uint64_t next_field_bit_offset = 0;
- CompilerType next_field_compiler_type = return_compiler_type.GetFieldAtIndex (idx + 1,
- name,
- &next_field_bit_offset,
- nullptr,
- nullptr);
- if (next_field_compiler_type.IsIntegerOrEnumerationType (is_signed))
- in_gpr = true;
- else
- {
- copy_from_offset = 0;
- in_gpr = false;
- }
- }
- }
- else if (field_byte_offset % 4 == 0)
- {
- // We are inside of an eightbyte, so see if the field before us is floating point:
- // This could happen if somebody put padding in the structure.
- if (idx == 0)
- in_gpr = false;
- else
- {
- uint64_t prev_field_bit_offset = 0;
- CompilerType prev_field_compiler_type = return_compiler_type.GetFieldAtIndex (idx - 1,
- name,
- &prev_field_bit_offset,
- nullptr,
- nullptr);
- if (prev_field_compiler_type.IsIntegerOrEnumerationType (is_signed))
- in_gpr = true;
- else
- {
- copy_from_offset = 4;
- in_gpr = false;
- }
- }
- }
- else
- {
- is_memory = true;
- continue;
- }
-
- // Okay, we've figured out whether we are in GPR or XMM, now figure out which one.
- if (in_gpr)
- {
- if (integer_bytes < 8)
- {
- // This is in RAX, copy from register to our result structure:
- copy_from_extractor = &rax_data;
- copy_from_offset = integer_bytes;
- integer_bytes += field_byte_width;
- }
- else
- {
- copy_from_extractor = &rdx_data;
- copy_from_offset = integer_bytes - 8;
- integer_bytes += field_byte_width;
- }
- }
- else
- {
- if (fp_bytes < 8)
- copy_from_extractor = &xmm0_data;
- else
- copy_from_extractor = &xmm1_data;
-
- fp_bytes += field_byte_width;
- }
- }
+ }
+ } else if (field_byte_offset % 4 == 0) {
+ // We are inside of an eightbyte, so see if the field before us is
+ // floating point:
+ // This could happen if somebody put padding in the structure.
+ if (idx == 0)
+ in_gpr = false;
+ else {
+ uint64_t prev_field_bit_offset = 0;
+ CompilerType prev_field_compiler_type =
+ return_compiler_type.GetFieldAtIndex(idx - 1, name,
+ &prev_field_bit_offset,
+ nullptr, nullptr);
+ if (prev_field_compiler_type.IsIntegerOrEnumerationType(
+ is_signed))
+ in_gpr = true;
+ else {
+ copy_from_offset = 4;
+ in_gpr = false;
}
-
- // These two tests are just sanity checks. If I somehow get the
- // type calculation wrong above it is better to just return nothing
- // than to assert or crash.
- if (!copy_from_extractor)
- return return_valobj_sp;
- if (copy_from_offset + field_byte_width > copy_from_extractor->GetByteSize())
- return return_valobj_sp;
-
- copy_from_extractor->CopyByteOrderedData (copy_from_offset,
- field_byte_width,
- data_sp->GetBytes() + field_byte_offset,
- field_byte_width,
- target_byte_order);
+ }
+ } else {
+ is_memory = true;
+ continue;
}
-
- if (!is_memory)
- {
- // The result is in our data buffer. Let's make a variable object out of it:
- return_valobj_sp = ValueObjectConstResult::Create (&thread,
- return_compiler_type,
- ConstString(""),
- return_ext);
+
+ // Okay, we've figured out whether we are in GPR or XMM, now figure
+ // out which one.
+ if (in_gpr) {
+ if (integer_bytes < 8) {
+ // This is in RAX, copy from register to our result structure:
+ copy_from_extractor = &rax_data;
+ copy_from_offset = integer_bytes;
+ integer_bytes += field_byte_width;
+ } else {
+ copy_from_extractor = &rdx_data;
+ copy_from_offset = integer_bytes - 8;
+ integer_bytes += field_byte_width;
+ }
+ } else {
+ if (fp_bytes < 8)
+ copy_from_extractor = &xmm0_data;
+ else
+ copy_from_extractor = &xmm1_data;
+
+ fp_bytes += field_byte_width;
}
+ }
}
- // FIXME: This is just taking a guess, rax may very well no longer hold the return storage location.
- // If we are going to do this right, when we make a new frame we should check to see if it uses a memory
- // return, and if we are at the first instruction and if so stash away the return location. Then we would
- // only return the memory return value if we know it is valid.
-
- if (is_memory)
- {
- unsigned rax_id = reg_ctx_sp->GetRegisterInfoByName("rax", 0)->kinds[eRegisterKindLLDB];
- lldb::addr_t storage_addr = (uint64_t)thread.GetRegisterContext()->ReadRegisterAsUnsigned(rax_id, 0);
- return_valobj_sp = ValueObjectMemory::Create(&thread,
- "",
- Address(storage_addr, nullptr),
- return_compiler_type);
- }
+ // These two tests are just sanity checks. If I somehow get the
+ // type calculation wrong above it is better to just return nothing
+ // than to assert or crash.
+ if (!copy_from_extractor)
+ return return_valobj_sp;
+ if (copy_from_offset + field_byte_width >
+ copy_from_extractor->GetByteSize())
+ return return_valobj_sp;
+
+ copy_from_extractor->CopyByteOrderedData(
+ copy_from_offset, field_byte_width,
+ data_sp->GetBytes() + field_byte_offset, field_byte_width,
+ target_byte_order);
+ }
+
+ if (!is_memory) {
+ // The result is in our data buffer. Let's make a variable object out
+ // of it:
+ return_valobj_sp = ValueObjectConstResult::Create(
+ &thread, return_compiler_type, ConstString(""), return_ext);
+ }
}
-
- return return_valobj_sp;
+
+ // FIXME: This is just taking a guess, rax may very well no longer hold the
+ // return storage location.
+ // If we are going to do this right, when we make a new frame we should
+ // check to see if it uses a memory
+ // return, and if we are at the first instruction and if so stash away the
+ // return location. Then we would
+ // only return the memory return value if we know it is valid.
+
+ if (is_memory) {
+ unsigned rax_id =
+ reg_ctx_sp->GetRegisterInfoByName("rax", 0)->kinds[eRegisterKindLLDB];
+ lldb::addr_t storage_addr =
+ (uint64_t)thread.GetRegisterContext()->ReadRegisterAsUnsigned(rax_id,
+ 0);
+ return_valobj_sp = ValueObjectMemory::Create(
+ &thread, "", Address(storage_addr, nullptr), return_compiler_type);
+ }
+ }
+
+ return return_valobj_sp;
}
// This defines the CFA as rsp+8
// the saved pc is at CFA-8 (i.e. rsp+0)
// The saved rsp is CFA+0
-bool
-ABISysV_x86_64::CreateFunctionEntryUnwindPlan (UnwindPlan &unwind_plan)
-{
- unwind_plan.Clear();
- unwind_plan.SetRegisterKind (eRegisterKindDWARF);
-
- uint32_t sp_reg_num = dwarf_rsp;
- uint32_t pc_reg_num = dwarf_rip;
-
- UnwindPlan::RowSP row(new UnwindPlan::Row);
- row->GetCFAValue().SetIsRegisterPlusOffset(sp_reg_num, 8);
- row->SetRegisterLocationToAtCFAPlusOffset(pc_reg_num, -8, false);
- row->SetRegisterLocationToIsCFAPlusOffset(sp_reg_num, 0, true);
- unwind_plan.AppendRow (row);
- unwind_plan.SetSourceName ("x86_64 at-func-entry default");
- unwind_plan.SetSourcedFromCompiler (eLazyBoolNo);
- return true;
+bool ABISysV_x86_64::CreateFunctionEntryUnwindPlan(UnwindPlan &unwind_plan) {
+ unwind_plan.Clear();
+ unwind_plan.SetRegisterKind(eRegisterKindDWARF);
+
+ uint32_t sp_reg_num = dwarf_rsp;
+ uint32_t pc_reg_num = dwarf_rip;
+
+ UnwindPlan::RowSP row(new UnwindPlan::Row);
+ row->GetCFAValue().SetIsRegisterPlusOffset(sp_reg_num, 8);
+ row->SetRegisterLocationToAtCFAPlusOffset(pc_reg_num, -8, false);
+ row->SetRegisterLocationToIsCFAPlusOffset(sp_reg_num, 0, true);
+ unwind_plan.AppendRow(row);
+ unwind_plan.SetSourceName("x86_64 at-func-entry default");
+ unwind_plan.SetSourcedFromCompiler(eLazyBoolNo);
+ return true;
}
// This defines the CFA as rbp+16
@@ -1060,137 +1792,114 @@ ABISysV_x86_64::CreateFunctionEntryUnwin
// The saved rbp is at CFA-16 (i.e. rbp+0)
// The saved rsp is CFA+0
-bool
-ABISysV_x86_64::CreateDefaultUnwindPlan (UnwindPlan &unwind_plan)
-{
- unwind_plan.Clear();
- unwind_plan.SetRegisterKind (eRegisterKindDWARF);
-
- uint32_t fp_reg_num = dwarf_rbp;
- uint32_t sp_reg_num = dwarf_rsp;
- uint32_t pc_reg_num = dwarf_rip;
-
- UnwindPlan::RowSP row(new UnwindPlan::Row);
-
- const int32_t ptr_size = 8;
- row->GetCFAValue().SetIsRegisterPlusOffset(dwarf_rbp, 2 * ptr_size);
- row->SetOffset (0);
-
- row->SetRegisterLocationToAtCFAPlusOffset(fp_reg_num, ptr_size * -2, true);
- row->SetRegisterLocationToAtCFAPlusOffset(pc_reg_num, ptr_size * -1, true);
- row->SetRegisterLocationToIsCFAPlusOffset(sp_reg_num, 0, true);
-
- unwind_plan.AppendRow (row);
- unwind_plan.SetSourceName ("x86_64 default unwind plan");
- unwind_plan.SetSourcedFromCompiler (eLazyBoolNo);
- unwind_plan.SetUnwindPlanValidAtAllInstructions (eLazyBoolNo);
- return true;
+bool ABISysV_x86_64::CreateDefaultUnwindPlan(UnwindPlan &unwind_plan) {
+ unwind_plan.Clear();
+ unwind_plan.SetRegisterKind(eRegisterKindDWARF);
+
+ uint32_t fp_reg_num = dwarf_rbp;
+ uint32_t sp_reg_num = dwarf_rsp;
+ uint32_t pc_reg_num = dwarf_rip;
+
+ UnwindPlan::RowSP row(new UnwindPlan::Row);
+
+ const int32_t ptr_size = 8;
+ row->GetCFAValue().SetIsRegisterPlusOffset(dwarf_rbp, 2 * ptr_size);
+ row->SetOffset(0);
+
+ row->SetRegisterLocationToAtCFAPlusOffset(fp_reg_num, ptr_size * -2, true);
+ row->SetRegisterLocationToAtCFAPlusOffset(pc_reg_num, ptr_size * -1, true);
+ row->SetRegisterLocationToIsCFAPlusOffset(sp_reg_num, 0, true);
+
+ unwind_plan.AppendRow(row);
+ unwind_plan.SetSourceName("x86_64 default unwind plan");
+ unwind_plan.SetSourcedFromCompiler(eLazyBoolNo);
+ unwind_plan.SetUnwindPlanValidAtAllInstructions(eLazyBoolNo);
+ return true;
}
-bool
-ABISysV_x86_64::RegisterIsVolatile (const RegisterInfo *reg_info)
-{
- return !RegisterIsCalleeSaved (reg_info);
+bool ABISysV_x86_64::RegisterIsVolatile(const RegisterInfo *reg_info) {
+ return !RegisterIsCalleeSaved(reg_info);
}
-// See "Register Usage" in the
+// See "Register Usage" in the
// "System V Application Binary Interface"
-// "AMD64 Architecture Processor Supplement"
+// "AMD64 Architecture Processor Supplement"
// (or "x86-64(tm) Architecture Processor Supplement" in earlier revisions)
// (this doc is also commonly referred to as the x86-64/AMD64 psABI)
// Edited by Michael Matz, Jan Hubicka, Andreas Jaeger, and Mark Mitchell
-// current version is 0.99.6 released 2012-07-02 at http://refspecs.linuxfoundation.org/elf/x86-64-abi-0.99.pdf
+// current version is 0.99.6 released 2012-07-02 at
+// http://refspecs.linuxfoundation.org/elf/x86-64-abi-0.99.pdf
// It's being revised & updated at https://github.com/hjl-tools/x86-psABI/
-bool
-ABISysV_x86_64::RegisterIsCalleeSaved (const RegisterInfo *reg_info)
-{
- if (reg_info)
- {
- // Preserved registers are :
- // rbx, rsp, rbp, r12, r13, r14, r15
- // mxcsr (partially preserved)
- // x87 control word
-
- const char *name = reg_info->name;
- if (name[0] == 'r')
- {
- switch (name[1])
- {
- case '1': // r12, r13, r14, r15
- if (name[2] >= '2' && name[2] <= '5')
- return name[3] == '\0';
- break;
-
- default:
- break;
- }
- }
+bool ABISysV_x86_64::RegisterIsCalleeSaved(const RegisterInfo *reg_info) {
+ if (reg_info) {
+ // Preserved registers are :
+ // rbx, rsp, rbp, r12, r13, r14, r15
+ // mxcsr (partially preserved)
+ // x87 control word
+
+ const char *name = reg_info->name;
+ if (name[0] == 'r') {
+ switch (name[1]) {
+ case '1': // r12, r13, r14, r15
+ if (name[2] >= '2' && name[2] <= '5')
+ return name[3] == '\0';
+ break;
+
+ default:
+ break;
+ }
+ }
- // Accept shorter-variant versions, rbx/ebx, rip/ eip, etc.
- if (name[0] == 'r' || name[0] == 'e')
- {
- switch (name[1])
- {
- case 'b': // rbp, rbx
- if (name[2] == 'p' || name[2] == 'x')
- return name[3] == '\0';
- break;
-
- case 'i': // rip
- if (name[2] == 'p')
- return name[3] == '\0';
- break;
-
- case 's': // rsp
- if (name[2] == 'p')
- return name[3] == '\0';
- break;
- }
- }
- if (name[0] == 's' && name[1] == 'p' && name[2] == '\0') // sp
- return true;
- if (name[0] == 'f' && name[1] == 'p' && name[2] == '\0') // fp
- return true;
- if (name[0] == 'p' && name[1] == 'c' && name[2] == '\0') // pc
- return true;
+ // Accept shorter-variant versions, rbx/ebx, rip/ eip, etc.
+ if (name[0] == 'r' || name[0] == 'e') {
+ switch (name[1]) {
+ case 'b': // rbp, rbx
+ if (name[2] == 'p' || name[2] == 'x')
+ return name[3] == '\0';
+ break;
+
+ case 'i': // rip
+ if (name[2] == 'p')
+ return name[3] == '\0';
+ break;
+
+ case 's': // rsp
+ if (name[2] == 'p')
+ return name[3] == '\0';
+ break;
+ }
}
- return false;
+ if (name[0] == 's' && name[1] == 'p' && name[2] == '\0') // sp
+ return true;
+ if (name[0] == 'f' && name[1] == 'p' && name[2] == '\0') // fp
+ return true;
+ if (name[0] == 'p' && name[1] == 'c' && name[2] == '\0') // pc
+ return true;
+ }
+ return false;
}
-void
-ABISysV_x86_64::Initialize()
-{
- PluginManager::RegisterPlugin (GetPluginNameStatic(),
- "System V ABI for x86_64 targets",
- CreateInstance);
+void ABISysV_x86_64::Initialize() {
+ PluginManager::RegisterPlugin(
+ GetPluginNameStatic(), "System V ABI for x86_64 targets", CreateInstance);
}
-void
-ABISysV_x86_64::Terminate()
-{
- PluginManager::UnregisterPlugin (CreateInstance);
+void ABISysV_x86_64::Terminate() {
+ PluginManager::UnregisterPlugin(CreateInstance);
}
-lldb_private::ConstString
-ABISysV_x86_64::GetPluginNameStatic()
-{
- static ConstString g_name("sysv-x86_64");
- return g_name;
+lldb_private::ConstString ABISysV_x86_64::GetPluginNameStatic() {
+ static ConstString g_name("sysv-x86_64");
+ return g_name;
}
//------------------------------------------------------------------
// PluginInterface protocol
//------------------------------------------------------------------
-lldb_private::ConstString
-ABISysV_x86_64::GetPluginName()
-{
- return GetPluginNameStatic();
+lldb_private::ConstString ABISysV_x86_64::GetPluginName() {
+ return GetPluginNameStatic();
}
-uint32_t
-ABISysV_x86_64::GetPluginVersion()
-{
- return 1;
-}
+uint32_t ABISysV_x86_64::GetPluginVersion() { return 1; }
Modified: lldb/trunk/source/Plugins/ABI/SysV-x86_64/ABISysV_x86_64.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ABI/SysV-x86_64/ABISysV_x86_64.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ABI/SysV-x86_64/ABISysV_x86_64.h (original)
+++ lldb/trunk/source/Plugins/ABI/SysV-x86_64/ABISysV_x86_64.h Tue Sep 6 15:57:50 2016
@@ -14,123 +14,102 @@
// C++ Includes
// Other libraries and framework includes
// Project includes
-#include "lldb/lldb-private.h"
#include "lldb/Target/ABI.h"
+#include "lldb/lldb-private.h"
-class ABISysV_x86_64 :
- public lldb_private::ABI
-{
+class ABISysV_x86_64 : public lldb_private::ABI {
public:
- ~ABISysV_x86_64() override = default;
+ ~ABISysV_x86_64() override = default;
+
+ size_t GetRedZoneSize() const override;
+
+ bool PrepareTrivialCall(lldb_private::Thread &thread, lldb::addr_t sp,
+ lldb::addr_t functionAddress,
+ lldb::addr_t returnAddress,
+ llvm::ArrayRef<lldb::addr_t> args) const override;
+
+ bool GetArgumentValues(lldb_private::Thread &thread,
+ lldb_private::ValueList &values) const override;
+
+ lldb_private::Error
+ SetReturnValueObject(lldb::StackFrameSP &frame_sp,
+ lldb::ValueObjectSP &new_value) override;
+
+ lldb::ValueObjectSP
+ GetReturnValueObjectImpl(lldb_private::Thread &thread,
+ lldb_private::CompilerType &type) const override;
+
+ bool
+ CreateFunctionEntryUnwindPlan(lldb_private::UnwindPlan &unwind_plan) override;
+
+ bool CreateDefaultUnwindPlan(lldb_private::UnwindPlan &unwind_plan) override;
+
+ bool RegisterIsVolatile(const lldb_private::RegisterInfo *reg_info) override;
+
+ // The SysV x86_64 ABI requires that stack frames be 16 byte aligned.
+ // When there is a trap handler on the stack, e.g. _sigtramp in userland
+ // code, we've seen that the stack pointer is often not aligned properly
+ // before the handler is invoked. This means that lldb will stop the unwind
+ // early -- before the function which caused the trap.
+ //
+ // To work around this, we relax that alignment to be just word-size
+ // (8-bytes).
+ // Whitelisting the trap handlers for user space would be easy (_sigtramp) but
+ // in other environments there can be a large number of different functions
+ // involved in async traps.
+ bool CallFrameAddressIsValid(lldb::addr_t cfa) override {
+ // Make sure the stack call frame addresses are 8 byte aligned
+ if (cfa & (8ull - 1ull))
+ return false; // Not 8 byte aligned
+ if (cfa == 0)
+ return false; // Zero is not a valid stack address
+ return true;
+ }
+
+ bool CodeAddressIsValid(lldb::addr_t pc) override {
+ // We have a 64 bit address space, so anything is valid as opcodes
+ // aren't fixed width...
+ return true;
+ }
+
+ const lldb_private::RegisterInfo *
+ GetRegisterInfoArray(uint32_t &count) override;
+
+ bool GetPointerReturnRegister(const char *&name) override;
+
+ //------------------------------------------------------------------
+ // Static Functions
+ //------------------------------------------------------------------
+
+ static void Initialize();
+
+ static void Terminate();
+
+ static lldb::ABISP CreateInstance(const lldb_private::ArchSpec &arch);
- size_t
- GetRedZoneSize() const override;
+ static lldb_private::ConstString GetPluginNameStatic();
- bool
- PrepareTrivialCall(lldb_private::Thread &thread,
- lldb::addr_t sp,
- lldb::addr_t functionAddress,
- lldb::addr_t returnAddress,
- llvm::ArrayRef<lldb::addr_t> args) const override;
-
- bool
- GetArgumentValues(lldb_private::Thread &thread,
- lldb_private::ValueList &values) const override;
-
- lldb_private::Error
- SetReturnValueObject(lldb::StackFrameSP &frame_sp, lldb::ValueObjectSP &new_value) override;
-
- lldb::ValueObjectSP
- GetReturnValueObjectImpl(lldb_private::Thread &thread,
- lldb_private::CompilerType &type) const override;
-
- bool
- CreateFunctionEntryUnwindPlan(lldb_private::UnwindPlan &unwind_plan) override;
-
- bool
- CreateDefaultUnwindPlan(lldb_private::UnwindPlan &unwind_plan) override;
-
- bool
- RegisterIsVolatile(const lldb_private::RegisterInfo *reg_info) override;
-
- // The SysV x86_64 ABI requires that stack frames be 16 byte aligned.
- // When there is a trap handler on the stack, e.g. _sigtramp in userland
- // code, we've seen that the stack pointer is often not aligned properly
- // before the handler is invoked. This means that lldb will stop the unwind
- // early -- before the function which caused the trap.
- //
- // To work around this, we relax that alignment to be just word-size (8-bytes).
- // Whitelisting the trap handlers for user space would be easy (_sigtramp) but
- // in other environments there can be a large number of different functions
- // involved in async traps.
- bool
- CallFrameAddressIsValid(lldb::addr_t cfa) override
- {
- // Make sure the stack call frame addresses are 8 byte aligned
- if (cfa & (8ull - 1ull))
- return false; // Not 8 byte aligned
- if (cfa == 0)
- return false; // Zero is not a valid stack address
- return true;
- }
-
- bool
- CodeAddressIsValid(lldb::addr_t pc) override
- {
- // We have a 64 bit address space, so anything is valid as opcodes
- // aren't fixed width...
- return true;
- }
-
- const lldb_private::RegisterInfo *
- GetRegisterInfoArray(uint32_t &count) override;
-
- bool
- GetPointerReturnRegister (const char *&name) override;
-
- //------------------------------------------------------------------
- // Static Functions
- //------------------------------------------------------------------
-
- static void
- Initialize();
-
- static void
- Terminate();
-
- static lldb::ABISP
- CreateInstance (const lldb_private::ArchSpec &arch);
-
- static lldb_private::ConstString
- GetPluginNameStatic();
-
- //------------------------------------------------------------------
- // PluginInterface protocol
- //------------------------------------------------------------------
+ //------------------------------------------------------------------
+ // PluginInterface protocol
+ //------------------------------------------------------------------
- lldb_private::ConstString
- GetPluginName() override;
+ lldb_private::ConstString GetPluginName() override;
- uint32_t
- GetPluginVersion() override;
+ uint32_t GetPluginVersion() override;
protected:
- void
- CreateRegisterMapIfNeeded ();
+ void CreateRegisterMapIfNeeded();
- lldb::ValueObjectSP
- GetReturnValueObjectSimple(lldb_private::Thread &thread,
- lldb_private::CompilerType &ast_type) const;
+ lldb::ValueObjectSP
+ GetReturnValueObjectSimple(lldb_private::Thread &thread,
+ lldb_private::CompilerType &ast_type) const;
- bool
- RegisterIsCalleeSaved (const lldb_private::RegisterInfo *reg_info);
+ bool RegisterIsCalleeSaved(const lldb_private::RegisterInfo *reg_info);
private:
- ABISysV_x86_64() :
- lldb_private::ABI()
- {
- // Call CreateInstance instead.
- }
+ ABISysV_x86_64() : lldb_private::ABI() {
+ // Call CreateInstance instead.
+ }
};
#endif // liblldb_ABISysV_x86_64_h_
Modified: lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp (original)
+++ lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp Tue Sep 6 15:57:50 2016
@@ -23,9 +23,9 @@
#include "llvm/MC/MCRegisterInfo.h"
#include "llvm/MC/MCSubtargetInfo.h"
#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/ScopedPrinter.h"
#include "llvm/Support/TargetRegistry.h"
#include "llvm/Support/TargetSelect.h"
-#include "llvm/Support/ScopedPrinter.h"
// Other libraries and framework includes
#include "DisassemblerLLVMC.h"
@@ -40,1551 +40,1336 @@
#include "lldb/Target/Process.h"
#include "lldb/Target/RegisterContext.h"
#include "lldb/Target/SectionLoadList.h"
-#include "lldb/Target/Target.h"
#include "lldb/Target/StackFrame.h"
+#include "lldb/Target/Target.h"
#include "lldb/Core/RegularExpression.h"
using namespace lldb;
using namespace lldb_private;
-class InstructionLLVMC : public lldb_private::Instruction
-{
+class InstructionLLVMC : public lldb_private::Instruction {
public:
- InstructionLLVMC (DisassemblerLLVMC &disasm,
- const lldb_private::Address &address,
- AddressClass addr_class) :
- Instruction (address, addr_class),
- m_disasm_wp (std::static_pointer_cast<DisassemblerLLVMC>(disasm.shared_from_this())),
- m_does_branch (eLazyBoolCalculate),
- m_has_delay_slot (eLazyBoolCalculate),
- m_is_call (eLazyBoolCalculate),
- m_is_valid (false),
- m_using_file_addr (false)
- {
- }
-
- ~InstructionLLVMC() override = default;
-
- bool
- DoesBranch() override
- {
- if (m_does_branch == eLazyBoolCalculate)
- {
- std::shared_ptr<DisassemblerLLVMC> disasm_sp(GetDisassembler());
- if (disasm_sp)
- {
- disasm_sp->Lock(this, NULL);
- DataExtractor data;
- if (m_opcode.GetData(data))
- {
- bool is_alternate_isa;
- lldb::addr_t pc = m_address.GetFileAddress();
-
- DisassemblerLLVMC::LLVMCDisassembler *mc_disasm_ptr = GetDisasmToUse (is_alternate_isa);
- const uint8_t *opcode_data = data.GetDataStart();
- const size_t opcode_data_len = data.GetByteSize();
- llvm::MCInst inst;
- const size_t inst_size = mc_disasm_ptr->GetMCInst (opcode_data,
- opcode_data_len,
- pc,
- inst);
- // Be conservative, if we didn't understand the instruction, say it might branch...
- if (inst_size == 0)
- m_does_branch = eLazyBoolYes;
- else
- {
- const bool can_branch = mc_disasm_ptr->CanBranch(inst);
- if (can_branch)
- m_does_branch = eLazyBoolYes;
- else
- m_does_branch = eLazyBoolNo;
- }
- }
- disasm_sp->Unlock();
- }
+ InstructionLLVMC(DisassemblerLLVMC &disasm,
+ const lldb_private::Address &address,
+ AddressClass addr_class)
+ : Instruction(address, addr_class),
+ m_disasm_wp(std::static_pointer_cast<DisassemblerLLVMC>(
+ disasm.shared_from_this())),
+ m_does_branch(eLazyBoolCalculate), m_has_delay_slot(eLazyBoolCalculate),
+ m_is_call(eLazyBoolCalculate), m_is_valid(false),
+ m_using_file_addr(false) {}
+
+ ~InstructionLLVMC() override = default;
+
+ bool DoesBranch() override {
+ if (m_does_branch == eLazyBoolCalculate) {
+ std::shared_ptr<DisassemblerLLVMC> disasm_sp(GetDisassembler());
+ if (disasm_sp) {
+ disasm_sp->Lock(this, NULL);
+ DataExtractor data;
+ if (m_opcode.GetData(data)) {
+ bool is_alternate_isa;
+ lldb::addr_t pc = m_address.GetFileAddress();
+
+ DisassemblerLLVMC::LLVMCDisassembler *mc_disasm_ptr =
+ GetDisasmToUse(is_alternate_isa);
+ const uint8_t *opcode_data = data.GetDataStart();
+ const size_t opcode_data_len = data.GetByteSize();
+ llvm::MCInst inst;
+ const size_t inst_size =
+ mc_disasm_ptr->GetMCInst(opcode_data, opcode_data_len, pc, inst);
+ // Be conservative, if we didn't understand the instruction, say it
+ // might branch...
+ if (inst_size == 0)
+ m_does_branch = eLazyBoolYes;
+ else {
+ const bool can_branch = mc_disasm_ptr->CanBranch(inst);
+ if (can_branch)
+ m_does_branch = eLazyBoolYes;
+ else
+ m_does_branch = eLazyBoolNo;
+ }
}
- return m_does_branch == eLazyBoolYes;
+ disasm_sp->Unlock();
+ }
}
+ return m_does_branch == eLazyBoolYes;
+ }
- bool
- HasDelaySlot() override
- {
- if (m_has_delay_slot == eLazyBoolCalculate)
- {
- std::shared_ptr<DisassemblerLLVMC> disasm_sp(GetDisassembler());
- if (disasm_sp)
- {
- disasm_sp->Lock(this, NULL);
- DataExtractor data;
- if (m_opcode.GetData(data))
- {
- bool is_alternate_isa;
- lldb::addr_t pc = m_address.GetFileAddress();
-
- DisassemblerLLVMC::LLVMCDisassembler *mc_disasm_ptr = GetDisasmToUse (is_alternate_isa);
- const uint8_t *opcode_data = data.GetDataStart();
- const size_t opcode_data_len = data.GetByteSize();
- llvm::MCInst inst;
- const size_t inst_size = mc_disasm_ptr->GetMCInst (opcode_data,
- opcode_data_len,
- pc,
- inst);
- // if we didn't understand the instruction, say it doesn't have a delay slot...
- if (inst_size == 0)
- m_has_delay_slot = eLazyBoolNo;
- else
- {
- const bool has_delay_slot = mc_disasm_ptr->HasDelaySlot(inst);
- if (has_delay_slot)
- m_has_delay_slot = eLazyBoolYes;
- else
- m_has_delay_slot = eLazyBoolNo;
- }
- }
- disasm_sp->Unlock();
- }
+ bool HasDelaySlot() override {
+ if (m_has_delay_slot == eLazyBoolCalculate) {
+ std::shared_ptr<DisassemblerLLVMC> disasm_sp(GetDisassembler());
+ if (disasm_sp) {
+ disasm_sp->Lock(this, NULL);
+ DataExtractor data;
+ if (m_opcode.GetData(data)) {
+ bool is_alternate_isa;
+ lldb::addr_t pc = m_address.GetFileAddress();
+
+ DisassemblerLLVMC::LLVMCDisassembler *mc_disasm_ptr =
+ GetDisasmToUse(is_alternate_isa);
+ const uint8_t *opcode_data = data.GetDataStart();
+ const size_t opcode_data_len = data.GetByteSize();
+ llvm::MCInst inst;
+ const size_t inst_size =
+ mc_disasm_ptr->GetMCInst(opcode_data, opcode_data_len, pc, inst);
+ // if we didn't understand the instruction, say it doesn't have a
+ // delay slot...
+ if (inst_size == 0)
+ m_has_delay_slot = eLazyBoolNo;
+ else {
+ const bool has_delay_slot = mc_disasm_ptr->HasDelaySlot(inst);
+ if (has_delay_slot)
+ m_has_delay_slot = eLazyBoolYes;
+ else
+ m_has_delay_slot = eLazyBoolNo;
+ }
}
- return m_has_delay_slot == eLazyBoolYes;
+ disasm_sp->Unlock();
+ }
}
+ return m_has_delay_slot == eLazyBoolYes;
+ }
- DisassemblerLLVMC::LLVMCDisassembler *
- GetDisasmToUse (bool &is_alternate_isa)
- {
- is_alternate_isa = false;
- std::shared_ptr<DisassemblerLLVMC> disasm_sp(GetDisassembler());
- if (disasm_sp)
- {
- if (disasm_sp->m_alternate_disasm_ap.get() != NULL)
- {
- const AddressClass address_class = GetAddressClass ();
-
- if (address_class == eAddressClassCodeAlternateISA)
- {
- is_alternate_isa = true;
- return disasm_sp->m_alternate_disasm_ap.get();
- }
- }
- return disasm_sp->m_disasm_ap.get();
- }
- return nullptr;
- }
+ DisassemblerLLVMC::LLVMCDisassembler *GetDisasmToUse(bool &is_alternate_isa) {
+ is_alternate_isa = false;
+ std::shared_ptr<DisassemblerLLVMC> disasm_sp(GetDisassembler());
+ if (disasm_sp) {
+ if (disasm_sp->m_alternate_disasm_ap.get() != NULL) {
+ const AddressClass address_class = GetAddressClass();
+
+ if (address_class == eAddressClassCodeAlternateISA) {
+ is_alternate_isa = true;
+ return disasm_sp->m_alternate_disasm_ap.get();
+ }
+ }
+ return disasm_sp->m_disasm_ap.get();
+ }
+ return nullptr;
+ }
+
+ size_t Decode(const lldb_private::Disassembler &disassembler,
+ const lldb_private::DataExtractor &data,
+ lldb::offset_t data_offset) override {
+ // All we have to do is read the opcode which can be easy for some
+ // architectures
+ bool got_op = false;
+ std::shared_ptr<DisassemblerLLVMC> disasm_sp(GetDisassembler());
+ if (disasm_sp) {
+ const ArchSpec &arch = disasm_sp->GetArchitecture();
+ const lldb::ByteOrder byte_order = data.GetByteOrder();
+
+ const uint32_t min_op_byte_size = arch.GetMinimumOpcodeByteSize();
+ const uint32_t max_op_byte_size = arch.GetMaximumOpcodeByteSize();
+ if (min_op_byte_size == max_op_byte_size) {
+ // Fixed size instructions, just read that amount of data.
+ if (!data.ValidOffsetForDataOfSize(data_offset, min_op_byte_size))
+ return false;
+
+ switch (min_op_byte_size) {
+ case 1:
+ m_opcode.SetOpcode8(data.GetU8(&data_offset), byte_order);
+ got_op = true;
+ break;
+
+ case 2:
+ m_opcode.SetOpcode16(data.GetU16(&data_offset), byte_order);
+ got_op = true;
+ break;
+
+ case 4:
+ m_opcode.SetOpcode32(data.GetU32(&data_offset), byte_order);
+ got_op = true;
+ break;
+
+ case 8:
+ m_opcode.SetOpcode64(data.GetU64(&data_offset), byte_order);
+ got_op = true;
+ break;
- size_t
- Decode(const lldb_private::Disassembler &disassembler,
- const lldb_private::DataExtractor &data,
- lldb::offset_t data_offset) override
- {
- // All we have to do is read the opcode which can be easy for some
- // architectures
- bool got_op = false;
- std::shared_ptr<DisassemblerLLVMC> disasm_sp(GetDisassembler());
- if (disasm_sp)
- {
- const ArchSpec &arch = disasm_sp->GetArchitecture();
- const lldb::ByteOrder byte_order = data.GetByteOrder();
-
- const uint32_t min_op_byte_size = arch.GetMinimumOpcodeByteSize();
- const uint32_t max_op_byte_size = arch.GetMaximumOpcodeByteSize();
- if (min_op_byte_size == max_op_byte_size)
- {
- // Fixed size instructions, just read that amount of data.
- if (!data.ValidOffsetForDataOfSize(data_offset, min_op_byte_size))
- return false;
-
- switch (min_op_byte_size)
- {
- case 1:
- m_opcode.SetOpcode8 (data.GetU8 (&data_offset), byte_order);
- got_op = true;
- break;
-
- case 2:
- m_opcode.SetOpcode16 (data.GetU16 (&data_offset), byte_order);
- got_op = true;
- break;
-
- case 4:
- m_opcode.SetOpcode32 (data.GetU32 (&data_offset), byte_order);
- got_op = true;
- break;
-
- case 8:
- m_opcode.SetOpcode64 (data.GetU64 (&data_offset), byte_order);
- got_op = true;
- break;
-
- default:
- m_opcode.SetOpcodeBytes(data.PeekData(data_offset, min_op_byte_size), min_op_byte_size);
- got_op = true;
- break;
- }
- }
- if (!got_op)
- {
- bool is_alternate_isa = false;
- DisassemblerLLVMC::LLVMCDisassembler *mc_disasm_ptr = GetDisasmToUse (is_alternate_isa);
-
- const llvm::Triple::ArchType machine = arch.GetMachine();
- if (machine == llvm::Triple::arm || machine == llvm::Triple::thumb)
- {
- if (machine == llvm::Triple::thumb || is_alternate_isa)
- {
- uint32_t thumb_opcode = data.GetU16(&data_offset);
- if ((thumb_opcode & 0xe000) != 0xe000 || ((thumb_opcode & 0x1800u) == 0))
- {
- m_opcode.SetOpcode16 (thumb_opcode, byte_order);
- m_is_valid = true;
- }
- else
- {
- thumb_opcode <<= 16;
- thumb_opcode |= data.GetU16(&data_offset);
- m_opcode.SetOpcode16_2 (thumb_opcode, byte_order);
- m_is_valid = true;
- }
- }
- else
- {
- m_opcode.SetOpcode32 (data.GetU32(&data_offset), byte_order);
- m_is_valid = true;
- }
- }
- else
- {
- // The opcode isn't evenly sized, so we need to actually use the llvm
- // disassembler to parse it and get the size.
- uint8_t *opcode_data = const_cast<uint8_t *>(data.PeekData (data_offset, 1));
- const size_t opcode_data_len = data.BytesLeft(data_offset);
- const addr_t pc = m_address.GetFileAddress();
- llvm::MCInst inst;
-
- disasm_sp->Lock(this, NULL);
- const size_t inst_size = mc_disasm_ptr->GetMCInst(opcode_data,
- opcode_data_len,
- pc,
- inst);
- disasm_sp->Unlock();
- if (inst_size == 0)
- m_opcode.Clear();
- else
- {
- m_opcode.SetOpcodeBytes(opcode_data, inst_size);
- m_is_valid = true;
- }
- }
- }
- return m_opcode.GetByteSize();
+ default:
+ m_opcode.SetOpcodeBytes(data.PeekData(data_offset, min_op_byte_size),
+ min_op_byte_size);
+ got_op = true;
+ break;
+ }
+ }
+ if (!got_op) {
+ bool is_alternate_isa = false;
+ DisassemblerLLVMC::LLVMCDisassembler *mc_disasm_ptr =
+ GetDisasmToUse(is_alternate_isa);
+
+ const llvm::Triple::ArchType machine = arch.GetMachine();
+ if (machine == llvm::Triple::arm || machine == llvm::Triple::thumb) {
+ if (machine == llvm::Triple::thumb || is_alternate_isa) {
+ uint32_t thumb_opcode = data.GetU16(&data_offset);
+ if ((thumb_opcode & 0xe000) != 0xe000 ||
+ ((thumb_opcode & 0x1800u) == 0)) {
+ m_opcode.SetOpcode16(thumb_opcode, byte_order);
+ m_is_valid = true;
+ } else {
+ thumb_opcode <<= 16;
+ thumb_opcode |= data.GetU16(&data_offset);
+ m_opcode.SetOpcode16_2(thumb_opcode, byte_order);
+ m_is_valid = true;
+ }
+ } else {
+ m_opcode.SetOpcode32(data.GetU32(&data_offset), byte_order);
+ m_is_valid = true;
+ }
+ } else {
+ // The opcode isn't evenly sized, so we need to actually use the llvm
+ // disassembler to parse it and get the size.
+ uint8_t *opcode_data =
+ const_cast<uint8_t *>(data.PeekData(data_offset, 1));
+ const size_t opcode_data_len = data.BytesLeft(data_offset);
+ const addr_t pc = m_address.GetFileAddress();
+ llvm::MCInst inst;
+
+ disasm_sp->Lock(this, NULL);
+ const size_t inst_size =
+ mc_disasm_ptr->GetMCInst(opcode_data, opcode_data_len, pc, inst);
+ disasm_sp->Unlock();
+ if (inst_size == 0)
+ m_opcode.Clear();
+ else {
+ m_opcode.SetOpcodeBytes(opcode_data, inst_size);
+ m_is_valid = true;
+ }
}
- return 0;
+ }
+ return m_opcode.GetByteSize();
}
+ return 0;
+ }
+
+ void AppendComment(std::string &description) {
+ if (m_comment.empty())
+ m_comment.swap(description);
+ else {
+ m_comment.append(", ");
+ m_comment.append(description);
+ }
+ }
+
+ void CalculateMnemonicOperandsAndComment(
+ const lldb_private::ExecutionContext *exe_ctx) override {
+ DataExtractor data;
+ const AddressClass address_class = GetAddressClass();
+
+ if (m_opcode.GetData(data)) {
+ std::string out_string;
+ std::string comment_string;
+
+ std::shared_ptr<DisassemblerLLVMC> disasm_sp(GetDisassembler());
+ if (disasm_sp) {
+ DisassemblerLLVMC::LLVMCDisassembler *mc_disasm_ptr;
- void
- AppendComment (std::string &description)
- {
- if (m_comment.empty())
- m_comment.swap (description);
+ if (address_class == eAddressClassCodeAlternateISA)
+ mc_disasm_ptr = disasm_sp->m_alternate_disasm_ap.get();
else
- {
- m_comment.append(", ");
- m_comment.append(description);
- }
- }
+ mc_disasm_ptr = disasm_sp->m_disasm_ap.get();
- void
- CalculateMnemonicOperandsAndComment(const lldb_private::ExecutionContext *exe_ctx) override
- {
- DataExtractor data;
- const AddressClass address_class = GetAddressClass ();
+ lldb::addr_t pc = m_address.GetFileAddress();
+ m_using_file_addr = true;
- if (m_opcode.GetData(data))
- {
- std::string out_string;
- std::string comment_string;
-
- std::shared_ptr<DisassemblerLLVMC> disasm_sp(GetDisassembler());
- if (disasm_sp)
- {
- DisassemblerLLVMC::LLVMCDisassembler *mc_disasm_ptr;
-
- if (address_class == eAddressClassCodeAlternateISA)
- mc_disasm_ptr = disasm_sp->m_alternate_disasm_ap.get();
- else
- mc_disasm_ptr = disasm_sp->m_disasm_ap.get();
-
- lldb::addr_t pc = m_address.GetFileAddress();
- m_using_file_addr = true;
-
- const bool data_from_file = disasm_sp->m_data_from_file;
- bool use_hex_immediates = true;
- Disassembler::HexImmediateStyle hex_style = Disassembler::eHexStyleC;
-
- if (exe_ctx)
- {
- Target *target = exe_ctx->GetTargetPtr();
- if (target)
- {
- use_hex_immediates = target->GetUseHexImmediates();
- hex_style = target->GetHexImmediateStyle();
-
- if (!data_from_file)
- {
- const lldb::addr_t load_addr = m_address.GetLoadAddress(target);
- if (load_addr != LLDB_INVALID_ADDRESS)
- {
- pc = load_addr;
- m_using_file_addr = false;
- }
- }
- }
- }
-
- disasm_sp->Lock(this, exe_ctx);
-
- const uint8_t *opcode_data = data.GetDataStart();
- const size_t opcode_data_len = data.GetByteSize();
- llvm::MCInst inst;
- size_t inst_size = mc_disasm_ptr->GetMCInst (opcode_data,
- opcode_data_len,
- pc,
- inst);
-
- if (inst_size > 0)
- {
- mc_disasm_ptr->SetStyle(use_hex_immediates, hex_style);
- mc_disasm_ptr->PrintMCInst(inst, out_string, comment_string);
-
- if (!comment_string.empty())
- {
- AppendComment(comment_string);
- }
- }
-
- disasm_sp->Unlock();
-
- if (inst_size == 0)
- {
- m_comment.assign ("unknown opcode");
- inst_size = m_opcode.GetByteSize();
- StreamString mnemonic_strm;
- lldb::offset_t offset = 0;
- lldb::ByteOrder byte_order = data.GetByteOrder();
- switch (inst_size)
- {
- case 1:
- {
- const uint8_t uval8 = data.GetU8 (&offset);
- m_opcode.SetOpcode8 (uval8, byte_order);
- m_opcode_name.assign (".byte");
- mnemonic_strm.Printf("0x%2.2x", uval8);
- }
- break;
- case 2:
- {
- const uint16_t uval16 = data.GetU16(&offset);
- m_opcode.SetOpcode16(uval16, byte_order);
- m_opcode_name.assign (".short");
- mnemonic_strm.Printf("0x%4.4x", uval16);
- }
- break;
- case 4:
- {
- const uint32_t uval32 = data.GetU32(&offset);
- m_opcode.SetOpcode32(uval32, byte_order);
- m_opcode_name.assign (".long");
- mnemonic_strm.Printf("0x%8.8x", uval32);
- }
- break;
- case 8:
- {
- const uint64_t uval64 = data.GetU64(&offset);
- m_opcode.SetOpcode64(uval64, byte_order);
- m_opcode_name.assign (".quad");
- mnemonic_strm.Printf("0x%16.16" PRIx64, uval64);
- }
- break;
- default:
- if (inst_size == 0)
- return;
- else
- {
- const uint8_t *bytes = data.PeekData(offset, inst_size);
- if (bytes == NULL)
- return;
- m_opcode_name.assign (".byte");
- m_opcode.SetOpcodeBytes(bytes, inst_size);
- mnemonic_strm.Printf("0x%2.2x", bytes[0]);
- for (uint32_t i=1; i<inst_size; ++i)
- mnemonic_strm.Printf(" 0x%2.2x", bytes[i]);
- }
- break;
- }
- m_mnemonics.swap(mnemonic_strm.GetString());
- return;
- }
- else
- {
- if (m_does_branch == eLazyBoolCalculate)
- {
- const bool can_branch = mc_disasm_ptr->CanBranch(inst);
- if (can_branch)
- m_does_branch = eLazyBoolYes;
- else
- m_does_branch = eLazyBoolNo;
-
- }
- }
-
- static RegularExpression s_regex("[ \t]*([^ ^\t]+)[ \t]*([^ ^\t].*)?");
-
- RegularExpression::Match matches(3);
-
- if (s_regex.Execute(out_string.c_str(), &matches))
- {
- matches.GetMatchAtIndex(out_string.c_str(), 1, m_opcode_name);
- matches.GetMatchAtIndex(out_string.c_str(), 2, m_mnemonics);
- }
- }
- }
- }
-
- bool
- IsValid () const
- {
- return m_is_valid;
- }
-
- bool
- UsingFileAddress() const
- {
- return m_using_file_addr;
- }
- size_t
- GetByteSize () const
- {
- return m_opcode.GetByteSize();
- }
-
- std::shared_ptr<DisassemblerLLVMC>
- GetDisassembler ()
- {
- return m_disasm_wp.lock();
- }
-
- static llvm::StringRef::const_iterator
- ConsumeWhitespace(llvm::StringRef::const_iterator osi, llvm::StringRef::const_iterator ose)
- {
- while (osi != ose)
- {
- switch (*osi) {
- default:
- return osi;
- case ' ': case '\t':
- break;
- }
- ++osi;
- }
-
- return osi;
- }
-
- static std::pair<bool, llvm::StringRef::const_iterator>
- ConsumeChar(llvm::StringRef::const_iterator osi, const char c, llvm::StringRef::const_iterator ose)
- {
- bool found = false;
-
- osi = ConsumeWhitespace(osi, ose);
- if (osi != ose && *osi == c)
- {
- found = true;
- ++osi;
- }
-
- return std::make_pair(found, osi);
- }
-
- static std::pair<Operand, llvm::StringRef::const_iterator>
- ParseRegisterName(llvm::StringRef::const_iterator osi, llvm::StringRef::const_iterator ose)
- {
- Operand ret;
- ret.m_type = Operand::Type::Register;
- std::string str;
-
- osi = ConsumeWhitespace(osi, ose);
-
- while (osi != ose)
- {
- if (*osi >= '0' && *osi <= '9')
- {
- if (str.empty())
- {
- return std::make_pair(Operand(), osi);
- }
- else
- {
- str.push_back(*osi);
- }
- }
- else if (*osi >= 'a' && *osi <= 'z')
- {
- str.push_back(*osi);
+ const bool data_from_file = disasm_sp->m_data_from_file;
+ bool use_hex_immediates = true;
+ Disassembler::HexImmediateStyle hex_style = Disassembler::eHexStyleC;
+
+ if (exe_ctx) {
+ Target *target = exe_ctx->GetTargetPtr();
+ if (target) {
+ use_hex_immediates = target->GetUseHexImmediates();
+ hex_style = target->GetHexImmediateStyle();
+
+ if (!data_from_file) {
+ const lldb::addr_t load_addr = m_address.GetLoadAddress(target);
+ if (load_addr != LLDB_INVALID_ADDRESS) {
+ pc = load_addr;
+ m_using_file_addr = false;
+ }
+ }
+ }
+ }
+
+ disasm_sp->Lock(this, exe_ctx);
+
+ const uint8_t *opcode_data = data.GetDataStart();
+ const size_t opcode_data_len = data.GetByteSize();
+ llvm::MCInst inst;
+ size_t inst_size =
+ mc_disasm_ptr->GetMCInst(opcode_data, opcode_data_len, pc, inst);
+
+ if (inst_size > 0) {
+ mc_disasm_ptr->SetStyle(use_hex_immediates, hex_style);
+ mc_disasm_ptr->PrintMCInst(inst, out_string, comment_string);
+
+ if (!comment_string.empty()) {
+ AppendComment(comment_string);
+ }
+ }
+
+ disasm_sp->Unlock();
+
+ if (inst_size == 0) {
+ m_comment.assign("unknown opcode");
+ inst_size = m_opcode.GetByteSize();
+ StreamString mnemonic_strm;
+ lldb::offset_t offset = 0;
+ lldb::ByteOrder byte_order = data.GetByteOrder();
+ switch (inst_size) {
+ case 1: {
+ const uint8_t uval8 = data.GetU8(&offset);
+ m_opcode.SetOpcode8(uval8, byte_order);
+ m_opcode_name.assign(".byte");
+ mnemonic_strm.Printf("0x%2.2x", uval8);
+ } break;
+ case 2: {
+ const uint16_t uval16 = data.GetU16(&offset);
+ m_opcode.SetOpcode16(uval16, byte_order);
+ m_opcode_name.assign(".short");
+ mnemonic_strm.Printf("0x%4.4x", uval16);
+ } break;
+ case 4: {
+ const uint32_t uval32 = data.GetU32(&offset);
+ m_opcode.SetOpcode32(uval32, byte_order);
+ m_opcode_name.assign(".long");
+ mnemonic_strm.Printf("0x%8.8x", uval32);
+ } break;
+ case 8: {
+ const uint64_t uval64 = data.GetU64(&offset);
+ m_opcode.SetOpcode64(uval64, byte_order);
+ m_opcode_name.assign(".quad");
+ mnemonic_strm.Printf("0x%16.16" PRIx64, uval64);
+ } break;
+ default:
+ if (inst_size == 0)
+ return;
+ else {
+ const uint8_t *bytes = data.PeekData(offset, inst_size);
+ if (bytes == NULL)
+ return;
+ m_opcode_name.assign(".byte");
+ m_opcode.SetOpcodeBytes(bytes, inst_size);
+ mnemonic_strm.Printf("0x%2.2x", bytes[0]);
+ for (uint32_t i = 1; i < inst_size; ++i)
+ mnemonic_strm.Printf(" 0x%2.2x", bytes[i]);
}
+ break;
+ }
+ m_mnemonics.swap(mnemonic_strm.GetString());
+ return;
+ } else {
+ if (m_does_branch == eLazyBoolCalculate) {
+ const bool can_branch = mc_disasm_ptr->CanBranch(inst);
+ if (can_branch)
+ m_does_branch = eLazyBoolYes;
else
- {
- switch (*osi)
- {
- default:
- if (str.empty())
- {
- return std::make_pair(Operand(), osi);
- }
- else
- {
- ret.m_register = ConstString(str);
- return std::make_pair(ret, osi);
- }
- case '%':
- if (!str.empty())
- {
- return std::make_pair(Operand(), osi);
- }
- break;
- }
- }
- ++osi;
+ m_does_branch = eLazyBoolNo;
+ }
}
-
- ret.m_register = ConstString(str);
- return std::make_pair(ret, osi);
- }
-
- static std::pair<Operand, llvm::StringRef::const_iterator>
- ParseImmediate(llvm::StringRef::const_iterator osi, llvm::StringRef::const_iterator ose)
- {
- Operand ret;
- ret.m_type = Operand::Type::Immediate;
- std::string str;
- bool is_hex = false;
-
- osi = ConsumeWhitespace(osi, ose);
-
- while (osi != ose)
- {
- if (*osi >= '0' && *osi <= '9')
- {
- str.push_back(*osi);
- }
- else if (*osi >= 'a' && *osi <= 'f')
- {
- if (is_hex)
- {
- str.push_back(*osi);
- }
- else
- {
- return std::make_pair(Operand(), osi);
- }
- }
- else
- {
- switch (*osi)
- {
- default:
- if (str.empty())
- {
- return std::make_pair(Operand(), osi);
- }
- else
- {
- ret.m_immediate = strtoull(str.c_str(), nullptr, 0);
- return std::make_pair(ret, osi);
- }
- case 'x':
- if (!str.compare("0"))
- {
- is_hex = true;
- str.push_back(*osi);
- }
- else
- {
- return std::make_pair(Operand(), osi);
- }
- break;
- case '#': case '$':
- if (!str.empty())
- {
- return std::make_pair(Operand(), osi);
- }
- break;
- case '-':
- if (str.empty())
- {
- ret.m_negative = true;
- }
- else
- {
- return std::make_pair(Operand(), osi);
- }
- }
- }
- ++osi;
+
+ static RegularExpression s_regex("[ \t]*([^ ^\t]+)[ \t]*([^ ^\t].*)?");
+
+ RegularExpression::Match matches(3);
+
+ if (s_regex.Execute(out_string.c_str(), &matches)) {
+ matches.GetMatchAtIndex(out_string.c_str(), 1, m_opcode_name);
+ matches.GetMatchAtIndex(out_string.c_str(), 2, m_mnemonics);
}
-
- ret.m_immediate = strtoull(str.c_str(), nullptr, 0);
- return std::make_pair(ret, osi);
+ }
}
+ }
- // -0x5(%rax,%rax,2)
- static std::pair<Operand, llvm::StringRef::const_iterator>
- ParseIntelIndexedAccess (llvm::StringRef::const_iterator osi, llvm::StringRef::const_iterator ose)
- {
- std::pair<Operand, llvm::StringRef::const_iterator> offset_and_iterator = ParseImmediate(osi, ose);
- if (offset_and_iterator.first.IsValid())
- {
- osi = offset_and_iterator.second;
- }
-
- bool found = false;
- std::tie(found, osi) = ConsumeChar(osi, '(', ose);
- if (!found)
- {
- return std::make_pair(Operand(), osi);
- }
-
- std::pair<Operand, llvm::StringRef::const_iterator> base_and_iterator = ParseRegisterName(osi, ose);
- if (base_and_iterator.first.IsValid())
- {
- osi = base_and_iterator.second;
- }
- else
- {
- return std::make_pair(Operand(), osi);
- }
-
- std::tie(found, osi) = ConsumeChar(osi, ',', ose);
- if (!found)
- {
- return std::make_pair(Operand(), osi);
- }
-
- std::pair<Operand, llvm::StringRef::const_iterator> index_and_iterator = ParseRegisterName(osi, ose);
- if (index_and_iterator.first.IsValid())
- {
- osi = index_and_iterator.second;
- }
- else
- {
- return std::make_pair(Operand(), osi);
- }
-
- std::tie(found, osi) = ConsumeChar(osi, ',', ose);
- if (!found)
- {
- return std::make_pair(Operand(), osi);
- }
+ bool IsValid() const { return m_is_valid; }
- std::pair<Operand, llvm::StringRef::const_iterator> multiplier_and_iterator = ParseImmediate(osi, ose);
- if (index_and_iterator.first.IsValid())
- {
- osi = index_and_iterator.second;
- }
- else
- {
- return std::make_pair(Operand(), osi);
- }
-
- std::tie(found, osi) = ConsumeChar(osi, ')', ose);
- if (!found)
- {
- return std::make_pair(Operand(), osi);
- }
-
- Operand product;
- product.m_type = Operand::Type::Product;
- product.m_children.push_back(index_and_iterator.first);
- product.m_children.push_back(multiplier_and_iterator.first);
-
- Operand index;
- index.m_type = Operand::Type::Sum;
- index.m_children.push_back(base_and_iterator.first);
- index.m_children.push_back(product);
-
- if (offset_and_iterator.first.IsValid())
- {
- Operand offset;
- offset.m_type = Operand::Type::Sum;
- offset.m_children.push_back(offset_and_iterator.first);
- offset.m_children.push_back(index);
-
- Operand deref;
- deref.m_type = Operand::Type::Dereference;
- deref.m_children.push_back(offset);
- return std::make_pair(deref, osi);
- }
- else
- {
- Operand deref;
- deref.m_type = Operand::Type::Dereference;
- deref.m_children.push_back(index);
- return std::make_pair(deref, osi);
- }
+ bool UsingFileAddress() const { return m_using_file_addr; }
+ size_t GetByteSize() const { return m_opcode.GetByteSize(); }
+
+ std::shared_ptr<DisassemblerLLVMC> GetDisassembler() {
+ return m_disasm_wp.lock();
+ }
+
+ static llvm::StringRef::const_iterator
+ ConsumeWhitespace(llvm::StringRef::const_iterator osi,
+ llvm::StringRef::const_iterator ose) {
+ while (osi != ose) {
+ switch (*osi) {
+ default:
+ return osi;
+ case ' ':
+ case '\t':
+ break;
+ }
+ ++osi;
}
-
- // -0x10(%rbp)
- static std::pair<Operand, llvm::StringRef::const_iterator>
- ParseIntelDerefAccess (llvm::StringRef::const_iterator osi, llvm::StringRef::const_iterator ose)
- {
- std::pair<Operand, llvm::StringRef::const_iterator> offset_and_iterator = ParseImmediate(osi, ose);
- if (offset_and_iterator.first.IsValid())
- {
- osi = offset_and_iterator.second;
- }
-
- bool found = false;
- std::tie(found, osi) = ConsumeChar(osi, '(', ose);
- if (!found)
- {
- return std::make_pair(Operand(), osi);
- }
-
- std::pair<Operand, llvm::StringRef::const_iterator> base_and_iterator = ParseRegisterName(osi, ose);
- if (base_and_iterator.first.IsValid())
- {
- osi = base_and_iterator.second;
- }
- else
- {
+
+ return osi;
+ }
+
+ static std::pair<bool, llvm::StringRef::const_iterator>
+ ConsumeChar(llvm::StringRef::const_iterator osi, const char c,
+ llvm::StringRef::const_iterator ose) {
+ bool found = false;
+
+ osi = ConsumeWhitespace(osi, ose);
+ if (osi != ose && *osi == c) {
+ found = true;
+ ++osi;
+ }
+
+ return std::make_pair(found, osi);
+ }
+
+ static std::pair<Operand, llvm::StringRef::const_iterator>
+ ParseRegisterName(llvm::StringRef::const_iterator osi,
+ llvm::StringRef::const_iterator ose) {
+ Operand ret;
+ ret.m_type = Operand::Type::Register;
+ std::string str;
+
+ osi = ConsumeWhitespace(osi, ose);
+
+ while (osi != ose) {
+ if (*osi >= '0' && *osi <= '9') {
+ if (str.empty()) {
+ return std::make_pair(Operand(), osi);
+ } else {
+ str.push_back(*osi);
+ }
+ } else if (*osi >= 'a' && *osi <= 'z') {
+ str.push_back(*osi);
+ } else {
+ switch (*osi) {
+ default:
+ if (str.empty()) {
return std::make_pair(Operand(), osi);
- }
-
- std::tie(found, osi) = ConsumeChar(osi, ')', ose);
- if (!found)
- {
+ } else {
+ ret.m_register = ConstString(str);
+ return std::make_pair(ret, osi);
+ }
+ case '%':
+ if (!str.empty()) {
return std::make_pair(Operand(), osi);
+ }
+ break;
}
-
- if (offset_and_iterator.first.IsValid())
- {
- Operand offset;
- offset.m_type = Operand::Type::Sum;
- offset.m_children.push_back(offset_and_iterator.first);
- offset.m_children.push_back(base_and_iterator.first);
-
- Operand deref;
- deref.m_type = Operand::Type::Dereference;
- deref.m_children.push_back(offset);
- return std::make_pair(deref, osi);
- }
- else
- {
- Operand deref;
- deref.m_type = Operand::Type::Dereference;
- deref.m_children.push_back(base_and_iterator.first);
- return std::make_pair(deref, osi);
- }
+ }
+ ++osi;
}
-
- // [sp, #8]!
- static std::pair<Operand, llvm::StringRef::const_iterator>
- ParseARMOffsetAccess (llvm::StringRef::const_iterator osi, llvm::StringRef::const_iterator ose)
- {
- bool found = false;
- std::tie(found, osi) = ConsumeChar(osi, '[', ose);
- if (!found)
- {
- return std::make_pair(Operand(), osi);
- }
-
- std::pair<Operand, llvm::StringRef::const_iterator> base_and_iterator = ParseRegisterName(osi, ose);
- if (base_and_iterator.first.IsValid())
- {
- osi = base_and_iterator.second;
+
+ ret.m_register = ConstString(str);
+ return std::make_pair(ret, osi);
+ }
+
+ static std::pair<Operand, llvm::StringRef::const_iterator>
+ ParseImmediate(llvm::StringRef::const_iterator osi,
+ llvm::StringRef::const_iterator ose) {
+ Operand ret;
+ ret.m_type = Operand::Type::Immediate;
+ std::string str;
+ bool is_hex = false;
+
+ osi = ConsumeWhitespace(osi, ose);
+
+ while (osi != ose) {
+ if (*osi >= '0' && *osi <= '9') {
+ str.push_back(*osi);
+ } else if (*osi >= 'a' && *osi <= 'f') {
+ if (is_hex) {
+ str.push_back(*osi);
+ } else {
+ return std::make_pair(Operand(), osi);
}
- else
- {
+ } else {
+ switch (*osi) {
+ default:
+ if (str.empty()) {
return std::make_pair(Operand(), osi);
- }
-
- std::tie(found, osi) = ConsumeChar(osi, ',', ose);
- if (!found)
- {
+ } else {
+ ret.m_immediate = strtoull(str.c_str(), nullptr, 0);
+ return std::make_pair(ret, osi);
+ }
+ case 'x':
+ if (!str.compare("0")) {
+ is_hex = true;
+ str.push_back(*osi);
+ } else {
return std::make_pair(Operand(), osi);
- }
-
- std::pair<Operand, llvm::StringRef::const_iterator> offset_and_iterator = ParseImmediate(osi, ose);
- if (offset_and_iterator.first.IsValid())
- {
- osi = offset_and_iterator.second;
- }
-
- std::tie(found, osi) = ConsumeChar(osi, ']', ose);
- if (!found)
- {
+ }
+ break;
+ case '#':
+ case '$':
+ if (!str.empty()) {
return std::make_pair(Operand(), osi);
- }
-
- Operand offset;
- offset.m_type = Operand::Type::Sum;
- offset.m_children.push_back(offset_and_iterator.first);
- offset.m_children.push_back(base_and_iterator.first);
-
- Operand deref;
- deref.m_type = Operand::Type::Dereference;
- deref.m_children.push_back(offset);
- return std::make_pair(deref, osi);
- }
-
- // [sp]
- static std::pair<Operand, llvm::StringRef::const_iterator>
- ParseARMDerefAccess (llvm::StringRef::const_iterator osi, llvm::StringRef::const_iterator ose)
- {
- bool found = false;
- std::tie(found, osi) = ConsumeChar(osi, '[', ose);
- if (!found)
- {
- return std::make_pair(Operand(), osi);
- }
-
- std::pair<Operand, llvm::StringRef::const_iterator> base_and_iterator = ParseRegisterName(osi, ose);
- if (base_and_iterator.first.IsValid())
- {
- osi = base_and_iterator.second;
- }
- else
- {
+ }
+ break;
+ case '-':
+ if (str.empty()) {
+ ret.m_negative = true;
+ } else {
return std::make_pair(Operand(), osi);
+ }
}
-
- std::tie(found, osi) = ConsumeChar(osi, ']', ose);
- if (!found)
- {
- return std::make_pair(Operand(), osi);
- }
-
- Operand deref;
- deref.m_type = Operand::Type::Dereference;
- deref.m_children.push_back(base_and_iterator.first);
- return std::make_pair(deref, osi);
- }
-
- static void
- DumpOperand(const Operand &op, Stream &s)
- {
- switch (op.m_type)
- {
- case Operand::Type::Dereference:
- s.PutCString("*");
- DumpOperand(op.m_children[0], s);
- break;
- case Operand::Type::Immediate:
- if (op.m_negative)
- {
- s.PutCString("-");
- }
- s.PutCString(llvm::to_string(op.m_immediate).c_str());
- break;
- case Operand::Type::Invalid:
- s.PutCString("Invalid");
- break;
- case Operand::Type::Product:
- s.PutCString("(");
- DumpOperand(op.m_children[0], s);
- s.PutCString("*");
- DumpOperand(op.m_children[1], s);
- s.PutCString(")");
- break;
- case Operand::Type::Register:
- s.PutCString(op.m_register.AsCString());
- break;
- case Operand::Type::Sum:
- s.PutCString("(");
- DumpOperand(op.m_children[0], s);
- s.PutCString("+");
- DumpOperand(op.m_children[1], s);
- s.PutCString(")");
- break;
- }
+ }
+ ++osi;
}
-
- bool
- ParseOperands (llvm::SmallVectorImpl<Instruction::Operand> &operands) override
- {
- const char *operands_string = GetOperands(nullptr);
-
- if (!operands_string)
- {
- return false;
- }
-
- llvm::StringRef operands_ref(operands_string);
-
- llvm::StringRef::const_iterator osi = operands_ref.begin();
- llvm::StringRef::const_iterator ose = operands_ref.end();
-
- while (osi != ose)
- {
- Operand operand;
- llvm::StringRef::const_iterator iter;
-
- if ((std::tie(operand, iter) = ParseIntelIndexedAccess(osi, ose), operand.IsValid()) ||
- (std::tie(operand, iter) = ParseIntelDerefAccess(osi, ose), operand.IsValid()) ||
- (std::tie(operand, iter) = ParseARMOffsetAccess(osi, ose), operand.IsValid()) ||
- (std::tie(operand, iter) = ParseARMDerefAccess(osi, ose), operand.IsValid()) ||
- (std::tie(operand, iter) = ParseRegisterName(osi, ose), operand.IsValid()) ||
- (std::tie(operand, iter) = ParseImmediate(osi, ose), operand.IsValid()))
- {
- osi = iter;
- operands.push_back(operand);
- }
- else
- {
- return false;
- }
-
- std::pair<bool, llvm::StringRef::const_iterator> found_and_iter = ConsumeChar(osi, ',', ose);
- if (found_and_iter.first)
- {
- osi = found_and_iter.second;
- }
-
- osi = ConsumeWhitespace(osi, ose);
- }
-
- DisassemblerSP disasm_sp = m_disasm_wp.lock();
-
- if (disasm_sp && operands.size() > 1)
- {
- // TODO tie this into the MC Disassembler's notion of clobbers.
- switch (disasm_sp->GetArchitecture().GetMachine())
- {
- default:
- break;
- case llvm::Triple::x86:
- case llvm::Triple::x86_64:
- operands[operands.size() - 1].m_clobbered = true;
- break;
- case llvm::Triple::arm:
- operands[0].m_clobbered = true;
- break;
- }
- }
-
- if (Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS))
- {
- StreamString ss;
-
- ss.Printf("[%s] expands to %zu operands:\n", operands_string, operands.size());
- for (const Operand &operand : operands) {
- ss.PutCString(" ");
- DumpOperand(operand, ss);
- ss.PutCString("\n");
- }
-
- log->PutCString(ss.GetData());
- }
-
- return true;
+
+ ret.m_immediate = strtoull(str.c_str(), nullptr, 0);
+ return std::make_pair(ret, osi);
+ }
+
+ // -0x5(%rax,%rax,2)
+ static std::pair<Operand, llvm::StringRef::const_iterator>
+ ParseIntelIndexedAccess(llvm::StringRef::const_iterator osi,
+ llvm::StringRef::const_iterator ose) {
+ std::pair<Operand, llvm::StringRef::const_iterator> offset_and_iterator =
+ ParseImmediate(osi, ose);
+ if (offset_and_iterator.first.IsValid()) {
+ osi = offset_and_iterator.second;
+ }
+
+ bool found = false;
+ std::tie(found, osi) = ConsumeChar(osi, '(', ose);
+ if (!found) {
+ return std::make_pair(Operand(), osi);
+ }
+
+ std::pair<Operand, llvm::StringRef::const_iterator> base_and_iterator =
+ ParseRegisterName(osi, ose);
+ if (base_and_iterator.first.IsValid()) {
+ osi = base_and_iterator.second;
+ } else {
+ return std::make_pair(Operand(), osi);
+ }
+
+ std::tie(found, osi) = ConsumeChar(osi, ',', ose);
+ if (!found) {
+ return std::make_pair(Operand(), osi);
+ }
+
+ std::pair<Operand, llvm::StringRef::const_iterator> index_and_iterator =
+ ParseRegisterName(osi, ose);
+ if (index_and_iterator.first.IsValid()) {
+ osi = index_and_iterator.second;
+ } else {
+ return std::make_pair(Operand(), osi);
+ }
+
+ std::tie(found, osi) = ConsumeChar(osi, ',', ose);
+ if (!found) {
+ return std::make_pair(Operand(), osi);
+ }
+
+ std::pair<Operand, llvm::StringRef::const_iterator>
+ multiplier_and_iterator = ParseImmediate(osi, ose);
+ if (index_and_iterator.first.IsValid()) {
+ osi = index_and_iterator.second;
+ } else {
+ return std::make_pair(Operand(), osi);
+ }
+
+ std::tie(found, osi) = ConsumeChar(osi, ')', ose);
+ if (!found) {
+ return std::make_pair(Operand(), osi);
+ }
+
+ Operand product;
+ product.m_type = Operand::Type::Product;
+ product.m_children.push_back(index_and_iterator.first);
+ product.m_children.push_back(multiplier_and_iterator.first);
+
+ Operand index;
+ index.m_type = Operand::Type::Sum;
+ index.m_children.push_back(base_and_iterator.first);
+ index.m_children.push_back(product);
+
+ if (offset_and_iterator.first.IsValid()) {
+ Operand offset;
+ offset.m_type = Operand::Type::Sum;
+ offset.m_children.push_back(offset_and_iterator.first);
+ offset.m_children.push_back(index);
+
+ Operand deref;
+ deref.m_type = Operand::Type::Dereference;
+ deref.m_children.push_back(offset);
+ return std::make_pair(deref, osi);
+ } else {
+ Operand deref;
+ deref.m_type = Operand::Type::Dereference;
+ deref.m_children.push_back(index);
+ return std::make_pair(deref, osi);
+ }
+ }
+
+ // -0x10(%rbp)
+ static std::pair<Operand, llvm::StringRef::const_iterator>
+ ParseIntelDerefAccess(llvm::StringRef::const_iterator osi,
+ llvm::StringRef::const_iterator ose) {
+ std::pair<Operand, llvm::StringRef::const_iterator> offset_and_iterator =
+ ParseImmediate(osi, ose);
+ if (offset_and_iterator.first.IsValid()) {
+ osi = offset_and_iterator.second;
+ }
+
+ bool found = false;
+ std::tie(found, osi) = ConsumeChar(osi, '(', ose);
+ if (!found) {
+ return std::make_pair(Operand(), osi);
+ }
+
+ std::pair<Operand, llvm::StringRef::const_iterator> base_and_iterator =
+ ParseRegisterName(osi, ose);
+ if (base_and_iterator.first.IsValid()) {
+ osi = base_and_iterator.second;
+ } else {
+ return std::make_pair(Operand(), osi);
+ }
+
+ std::tie(found, osi) = ConsumeChar(osi, ')', ose);
+ if (!found) {
+ return std::make_pair(Operand(), osi);
+ }
+
+ if (offset_and_iterator.first.IsValid()) {
+ Operand offset;
+ offset.m_type = Operand::Type::Sum;
+ offset.m_children.push_back(offset_and_iterator.first);
+ offset.m_children.push_back(base_and_iterator.first);
+
+ Operand deref;
+ deref.m_type = Operand::Type::Dereference;
+ deref.m_children.push_back(offset);
+ return std::make_pair(deref, osi);
+ } else {
+ Operand deref;
+ deref.m_type = Operand::Type::Dereference;
+ deref.m_children.push_back(base_and_iterator.first);
+ return std::make_pair(deref, osi);
+ }
+ }
+
+ // [sp, #8]!
+ static std::pair<Operand, llvm::StringRef::const_iterator>
+ ParseARMOffsetAccess(llvm::StringRef::const_iterator osi,
+ llvm::StringRef::const_iterator ose) {
+ bool found = false;
+ std::tie(found, osi) = ConsumeChar(osi, '[', ose);
+ if (!found) {
+ return std::make_pair(Operand(), osi);
+ }
+
+ std::pair<Operand, llvm::StringRef::const_iterator> base_and_iterator =
+ ParseRegisterName(osi, ose);
+ if (base_and_iterator.first.IsValid()) {
+ osi = base_and_iterator.second;
+ } else {
+ return std::make_pair(Operand(), osi);
+ }
+
+ std::tie(found, osi) = ConsumeChar(osi, ',', ose);
+ if (!found) {
+ return std::make_pair(Operand(), osi);
+ }
+
+ std::pair<Operand, llvm::StringRef::const_iterator> offset_and_iterator =
+ ParseImmediate(osi, ose);
+ if (offset_and_iterator.first.IsValid()) {
+ osi = offset_and_iterator.second;
+ }
+
+ std::tie(found, osi) = ConsumeChar(osi, ']', ose);
+ if (!found) {
+ return std::make_pair(Operand(), osi);
+ }
+
+ Operand offset;
+ offset.m_type = Operand::Type::Sum;
+ offset.m_children.push_back(offset_and_iterator.first);
+ offset.m_children.push_back(base_and_iterator.first);
+
+ Operand deref;
+ deref.m_type = Operand::Type::Dereference;
+ deref.m_children.push_back(offset);
+ return std::make_pair(deref, osi);
+ }
+
+ // [sp]
+ static std::pair<Operand, llvm::StringRef::const_iterator>
+ ParseARMDerefAccess(llvm::StringRef::const_iterator osi,
+ llvm::StringRef::const_iterator ose) {
+ bool found = false;
+ std::tie(found, osi) = ConsumeChar(osi, '[', ose);
+ if (!found) {
+ return std::make_pair(Operand(), osi);
+ }
+
+ std::pair<Operand, llvm::StringRef::const_iterator> base_and_iterator =
+ ParseRegisterName(osi, ose);
+ if (base_and_iterator.first.IsValid()) {
+ osi = base_and_iterator.second;
+ } else {
+ return std::make_pair(Operand(), osi);
+ }
+
+ std::tie(found, osi) = ConsumeChar(osi, ']', ose);
+ if (!found) {
+ return std::make_pair(Operand(), osi);
+ }
+
+ Operand deref;
+ deref.m_type = Operand::Type::Dereference;
+ deref.m_children.push_back(base_and_iterator.first);
+ return std::make_pair(deref, osi);
+ }
+
+ static void DumpOperand(const Operand &op, Stream &s) {
+ switch (op.m_type) {
+ case Operand::Type::Dereference:
+ s.PutCString("*");
+ DumpOperand(op.m_children[0], s);
+ break;
+ case Operand::Type::Immediate:
+ if (op.m_negative) {
+ s.PutCString("-");
+ }
+ s.PutCString(llvm::to_string(op.m_immediate).c_str());
+ break;
+ case Operand::Type::Invalid:
+ s.PutCString("Invalid");
+ break;
+ case Operand::Type::Product:
+ s.PutCString("(");
+ DumpOperand(op.m_children[0], s);
+ s.PutCString("*");
+ DumpOperand(op.m_children[1], s);
+ s.PutCString(")");
+ break;
+ case Operand::Type::Register:
+ s.PutCString(op.m_register.AsCString());
+ break;
+ case Operand::Type::Sum:
+ s.PutCString("(");
+ DumpOperand(op.m_children[0], s);
+ s.PutCString("+");
+ DumpOperand(op.m_children[1], s);
+ s.PutCString(")");
+ break;
+ }
+ }
+
+ bool ParseOperands(
+ llvm::SmallVectorImpl<Instruction::Operand> &operands) override {
+ const char *operands_string = GetOperands(nullptr);
+
+ if (!operands_string) {
+ return false;
+ }
+
+ llvm::StringRef operands_ref(operands_string);
+
+ llvm::StringRef::const_iterator osi = operands_ref.begin();
+ llvm::StringRef::const_iterator ose = operands_ref.end();
+
+ while (osi != ose) {
+ Operand operand;
+ llvm::StringRef::const_iterator iter;
+
+ if ((std::tie(operand, iter) = ParseIntelIndexedAccess(osi, ose),
+ operand.IsValid()) ||
+ (std::tie(operand, iter) = ParseIntelDerefAccess(osi, ose),
+ operand.IsValid()) ||
+ (std::tie(operand, iter) = ParseARMOffsetAccess(osi, ose),
+ operand.IsValid()) ||
+ (std::tie(operand, iter) = ParseARMDerefAccess(osi, ose),
+ operand.IsValid()) ||
+ (std::tie(operand, iter) = ParseRegisterName(osi, ose),
+ operand.IsValid()) ||
+ (std::tie(operand, iter) = ParseImmediate(osi, ose),
+ operand.IsValid())) {
+ osi = iter;
+ operands.push_back(operand);
+ } else {
+ return false;
+ }
+
+ std::pair<bool, llvm::StringRef::const_iterator> found_and_iter =
+ ConsumeChar(osi, ',', ose);
+ if (found_and_iter.first) {
+ osi = found_and_iter.second;
+ }
+
+ osi = ConsumeWhitespace(osi, ose);
}
-
- bool
- IsCall () override
- {
- if (m_is_call == eLazyBoolCalculate)
- {
- std::shared_ptr<DisassemblerLLVMC> disasm_sp(GetDisassembler());
- if (disasm_sp)
- {
- disasm_sp->Lock(this, NULL);
- DataExtractor data;
- if (m_opcode.GetData(data))
- {
- bool is_alternate_isa;
- lldb::addr_t pc = m_address.GetFileAddress();
-
- DisassemblerLLVMC::LLVMCDisassembler *mc_disasm_ptr = GetDisasmToUse (is_alternate_isa);
- const uint8_t *opcode_data = data.GetDataStart();
- const size_t opcode_data_len = data.GetByteSize();
- llvm::MCInst inst;
- const size_t inst_size = mc_disasm_ptr->GetMCInst (opcode_data,
- opcode_data_len,
- pc,
- inst);
- if (inst_size == 0)
- {
- m_is_call = eLazyBoolNo;
- }
- else
- {
- if (mc_disasm_ptr->IsCall(inst))
- m_is_call = eLazyBoolYes;
- else
- m_is_call = eLazyBoolNo;
- }
- }
- disasm_sp->Unlock();
- }
- }
- return m_is_call == eLazyBoolYes;
+
+ DisassemblerSP disasm_sp = m_disasm_wp.lock();
+
+ if (disasm_sp && operands.size() > 1) {
+ // TODO tie this into the MC Disassembler's notion of clobbers.
+ switch (disasm_sp->GetArchitecture().GetMachine()) {
+ default:
+ break;
+ case llvm::Triple::x86:
+ case llvm::Triple::x86_64:
+ operands[operands.size() - 1].m_clobbered = true;
+ break;
+ case llvm::Triple::arm:
+ operands[0].m_clobbered = true;
+ break;
+ }
}
-
-protected:
- std::weak_ptr<DisassemblerLLVMC> m_disasm_wp;
- LazyBool m_does_branch;
- LazyBool m_has_delay_slot;
- LazyBool m_is_call;
- bool m_is_valid;
- bool m_using_file_addr;
-};
+ if (Log *log =
+ lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS)) {
+ StreamString ss;
-DisassemblerLLVMC::LLVMCDisassembler::LLVMCDisassembler (const char *triple, const char *cpu, const char *features_str, unsigned flavor, DisassemblerLLVMC &owner):
- m_is_valid(true)
-{
- std::string Error;
- const llvm::Target *curr_target = llvm::TargetRegistry::lookupTarget(triple, Error);
- if (!curr_target)
- {
- m_is_valid = false;
- return;
- }
-
- m_instr_info_ap.reset(curr_target->createMCInstrInfo());
- m_reg_info_ap.reset (curr_target->createMCRegInfo(triple));
-
- m_subtarget_info_ap.reset(curr_target->createMCSubtargetInfo(triple, cpu,
- features_str));
-
- std::unique_ptr<llvm::MCRegisterInfo> reg_info(curr_target->createMCRegInfo(triple));
- m_asm_info_ap.reset(curr_target->createMCAsmInfo(*reg_info, triple));
-
- if (m_instr_info_ap.get() == NULL || m_reg_info_ap.get() == NULL || m_subtarget_info_ap.get() == NULL || m_asm_info_ap.get() == NULL)
- {
- m_is_valid = false;
- return;
- }
-
- m_context_ap.reset(new llvm::MCContext(m_asm_info_ap.get(), m_reg_info_ap.get(), 0));
-
- m_disasm_ap.reset(curr_target->createMCDisassembler(*m_subtarget_info_ap.get(), *m_context_ap.get()));
- if (m_disasm_ap.get() && m_context_ap.get())
- {
- std::unique_ptr<llvm::MCRelocationInfo> RelInfo(curr_target->createMCRelocationInfo(triple, *m_context_ap.get()));
- if (!RelInfo)
- {
- m_is_valid = false;
- return;
- }
- std::unique_ptr<llvm::MCSymbolizer> symbolizer_up(curr_target->createMCSymbolizer(triple, NULL,
- DisassemblerLLVMC::SymbolLookupCallback,
- (void *) &owner,
- m_context_ap.get(), std::move(RelInfo)));
- m_disasm_ap->setSymbolizer(std::move(symbolizer_up));
+ ss.Printf("[%s] expands to %zu operands:\n", operands_string,
+ operands.size());
+ for (const Operand &operand : operands) {
+ ss.PutCString(" ");
+ DumpOperand(operand, ss);
+ ss.PutCString("\n");
+ }
+ log->PutCString(ss.GetData());
+ }
- unsigned asm_printer_variant;
- if (flavor == ~0U)
- asm_printer_variant = m_asm_info_ap->getAssemblerDialect();
- else
- {
- asm_printer_variant = flavor;
- }
+ return true;
+ }
- m_instr_printer_ap.reset(curr_target->createMCInstPrinter(llvm::Triple{triple},
- asm_printer_variant,
- *m_asm_info_ap.get(),
- *m_instr_info_ap.get(),
- *m_reg_info_ap.get()));
- if (m_instr_printer_ap.get() == NULL)
- {
- m_disasm_ap.reset();
- m_is_valid = false;
+ bool IsCall() override {
+ if (m_is_call == eLazyBoolCalculate) {
+ std::shared_ptr<DisassemblerLLVMC> disasm_sp(GetDisassembler());
+ if (disasm_sp) {
+ disasm_sp->Lock(this, NULL);
+ DataExtractor data;
+ if (m_opcode.GetData(data)) {
+ bool is_alternate_isa;
+ lldb::addr_t pc = m_address.GetFileAddress();
+
+ DisassemblerLLVMC::LLVMCDisassembler *mc_disasm_ptr =
+ GetDisasmToUse(is_alternate_isa);
+ const uint8_t *opcode_data = data.GetDataStart();
+ const size_t opcode_data_len = data.GetByteSize();
+ llvm::MCInst inst;
+ const size_t inst_size =
+ mc_disasm_ptr->GetMCInst(opcode_data, opcode_data_len, pc, inst);
+ if (inst_size == 0) {
+ m_is_call = eLazyBoolNo;
+ } else {
+ if (mc_disasm_ptr->IsCall(inst))
+ m_is_call = eLazyBoolYes;
+ else
+ m_is_call = eLazyBoolNo;
+ }
}
+ disasm_sp->Unlock();
+ }
}
- else
- m_is_valid = false;
+ return m_is_call == eLazyBoolYes;
+ }
+
+protected:
+ std::weak_ptr<DisassemblerLLVMC> m_disasm_wp;
+ LazyBool m_does_branch;
+ LazyBool m_has_delay_slot;
+ LazyBool m_is_call;
+ bool m_is_valid;
+ bool m_using_file_addr;
+};
+
+DisassemblerLLVMC::LLVMCDisassembler::LLVMCDisassembler(
+ const char *triple, const char *cpu, const char *features_str,
+ unsigned flavor, DisassemblerLLVMC &owner)
+ : m_is_valid(true) {
+ std::string Error;
+ const llvm::Target *curr_target =
+ llvm::TargetRegistry::lookupTarget(triple, Error);
+ if (!curr_target) {
+ m_is_valid = false;
+ return;
+ }
+
+ m_instr_info_ap.reset(curr_target->createMCInstrInfo());
+ m_reg_info_ap.reset(curr_target->createMCRegInfo(triple));
+
+ m_subtarget_info_ap.reset(
+ curr_target->createMCSubtargetInfo(triple, cpu, features_str));
+
+ std::unique_ptr<llvm::MCRegisterInfo> reg_info(
+ curr_target->createMCRegInfo(triple));
+ m_asm_info_ap.reset(curr_target->createMCAsmInfo(*reg_info, triple));
+
+ if (m_instr_info_ap.get() == NULL || m_reg_info_ap.get() == NULL ||
+ m_subtarget_info_ap.get() == NULL || m_asm_info_ap.get() == NULL) {
+ m_is_valid = false;
+ return;
+ }
+
+ m_context_ap.reset(
+ new llvm::MCContext(m_asm_info_ap.get(), m_reg_info_ap.get(), 0));
+
+ m_disasm_ap.reset(curr_target->createMCDisassembler(
+ *m_subtarget_info_ap.get(), *m_context_ap.get()));
+ if (m_disasm_ap.get() && m_context_ap.get()) {
+ std::unique_ptr<llvm::MCRelocationInfo> RelInfo(
+ curr_target->createMCRelocationInfo(triple, *m_context_ap.get()));
+ if (!RelInfo) {
+ m_is_valid = false;
+ return;
+ }
+ std::unique_ptr<llvm::MCSymbolizer> symbolizer_up(
+ curr_target->createMCSymbolizer(
+ triple, NULL, DisassemblerLLVMC::SymbolLookupCallback,
+ (void *)&owner, m_context_ap.get(), std::move(RelInfo)));
+ m_disasm_ap->setSymbolizer(std::move(symbolizer_up));
+
+ unsigned asm_printer_variant;
+ if (flavor == ~0U)
+ asm_printer_variant = m_asm_info_ap->getAssemblerDialect();
+ else {
+ asm_printer_variant = flavor;
+ }
+
+ m_instr_printer_ap.reset(curr_target->createMCInstPrinter(
+ llvm::Triple{triple}, asm_printer_variant, *m_asm_info_ap.get(),
+ *m_instr_info_ap.get(), *m_reg_info_ap.get()));
+ if (m_instr_printer_ap.get() == NULL) {
+ m_disasm_ap.reset();
+ m_is_valid = false;
+ }
+ } else
+ m_is_valid = false;
}
DisassemblerLLVMC::LLVMCDisassembler::~LLVMCDisassembler() = default;
-uint64_t
-DisassemblerLLVMC::LLVMCDisassembler::GetMCInst (const uint8_t *opcode_data,
- size_t opcode_data_len,
- lldb::addr_t pc,
- llvm::MCInst &mc_inst)
-{
- llvm::ArrayRef<uint8_t> data(opcode_data, opcode_data_len);
- llvm::MCDisassembler::DecodeStatus status;
-
- uint64_t new_inst_size;
- status = m_disasm_ap->getInstruction(mc_inst,
- new_inst_size,
- data,
- pc,
- llvm::nulls(),
- llvm::nulls());
- if (status == llvm::MCDisassembler::Success)
- return new_inst_size;
- else
- return 0;
+uint64_t DisassemblerLLVMC::LLVMCDisassembler::GetMCInst(
+ const uint8_t *opcode_data, size_t opcode_data_len, lldb::addr_t pc,
+ llvm::MCInst &mc_inst) {
+ llvm::ArrayRef<uint8_t> data(opcode_data, opcode_data_len);
+ llvm::MCDisassembler::DecodeStatus status;
+
+ uint64_t new_inst_size;
+ status = m_disasm_ap->getInstruction(mc_inst, new_inst_size, data, pc,
+ llvm::nulls(), llvm::nulls());
+ if (status == llvm::MCDisassembler::Success)
+ return new_inst_size;
+ else
+ return 0;
}
-void
-DisassemblerLLVMC::LLVMCDisassembler::PrintMCInst (llvm::MCInst &mc_inst,
- std::string &inst_string,
- std::string &comments_string)
-{
- llvm::raw_string_ostream inst_stream(inst_string);
- llvm::raw_string_ostream comments_stream(comments_string);
-
- m_instr_printer_ap->setCommentStream(comments_stream);
- m_instr_printer_ap->printInst (&mc_inst, inst_stream, llvm::StringRef(), *m_subtarget_info_ap);
- m_instr_printer_ap->setCommentStream(llvm::nulls());
- comments_stream.flush();
-
- static std::string g_newlines("\r\n");
-
- for (size_t newline_pos = 0; (newline_pos = comments_string.find_first_of(g_newlines, newline_pos)) != comments_string.npos; /**/)
- {
- comments_string.replace(comments_string.begin() + newline_pos, comments_string.begin() + newline_pos + 1, 1, ' ');
- }
+void DisassemblerLLVMC::LLVMCDisassembler::PrintMCInst(
+ llvm::MCInst &mc_inst, std::string &inst_string,
+ std::string &comments_string) {
+ llvm::raw_string_ostream inst_stream(inst_string);
+ llvm::raw_string_ostream comments_stream(comments_string);
+
+ m_instr_printer_ap->setCommentStream(comments_stream);
+ m_instr_printer_ap->printInst(&mc_inst, inst_stream, llvm::StringRef(),
+ *m_subtarget_info_ap);
+ m_instr_printer_ap->setCommentStream(llvm::nulls());
+ comments_stream.flush();
+
+ static std::string g_newlines("\r\n");
+
+ for (size_t newline_pos = 0;
+ (newline_pos = comments_string.find_first_of(g_newlines, newline_pos)) !=
+ comments_string.npos;
+ /**/) {
+ comments_string.replace(comments_string.begin() + newline_pos,
+ comments_string.begin() + newline_pos + 1, 1, ' ');
+ }
}
-void
-DisassemblerLLVMC::LLVMCDisassembler::SetStyle (bool use_hex_immed, HexImmediateStyle hex_style)
-{
- m_instr_printer_ap->setPrintImmHex(use_hex_immed);
- switch(hex_style)
- {
- case eHexStyleC: m_instr_printer_ap->setPrintHexStyle(llvm::HexStyle::C); break;
- case eHexStyleAsm: m_instr_printer_ap->setPrintHexStyle(llvm::HexStyle::Asm); break;
- }
+void DisassemblerLLVMC::LLVMCDisassembler::SetStyle(
+ bool use_hex_immed, HexImmediateStyle hex_style) {
+ m_instr_printer_ap->setPrintImmHex(use_hex_immed);
+ switch (hex_style) {
+ case eHexStyleC:
+ m_instr_printer_ap->setPrintHexStyle(llvm::HexStyle::C);
+ break;
+ case eHexStyleAsm:
+ m_instr_printer_ap->setPrintHexStyle(llvm::HexStyle::Asm);
+ break;
+ }
}
-bool
-DisassemblerLLVMC::LLVMCDisassembler::CanBranch (llvm::MCInst &mc_inst)
-{
- return m_instr_info_ap->get(mc_inst.getOpcode()).mayAffectControlFlow(mc_inst, *m_reg_info_ap.get());
+bool DisassemblerLLVMC::LLVMCDisassembler::CanBranch(llvm::MCInst &mc_inst) {
+ return m_instr_info_ap->get(mc_inst.getOpcode())
+ .mayAffectControlFlow(mc_inst, *m_reg_info_ap.get());
}
-bool
-DisassemblerLLVMC::LLVMCDisassembler::HasDelaySlot (llvm::MCInst &mc_inst)
-{
- return m_instr_info_ap->get(mc_inst.getOpcode()).hasDelaySlot();
+bool DisassemblerLLVMC::LLVMCDisassembler::HasDelaySlot(llvm::MCInst &mc_inst) {
+ return m_instr_info_ap->get(mc_inst.getOpcode()).hasDelaySlot();
}
-bool
-DisassemblerLLVMC::LLVMCDisassembler::IsCall (llvm::MCInst &mc_inst)
-{
- return m_instr_info_ap->get(mc_inst.getOpcode()).isCall();
+bool DisassemblerLLVMC::LLVMCDisassembler::IsCall(llvm::MCInst &mc_inst) {
+ return m_instr_info_ap->get(mc_inst.getOpcode()).isCall();
}
-DisassemblerLLVMC::DisassemblerLLVMC (const ArchSpec &arch, const char *flavor_string) :
- Disassembler(arch, flavor_string),
- m_exe_ctx (NULL),
- m_inst (NULL),
- m_data_from_file (false)
-{
- if (!FlavorValidForArchSpec (arch, m_flavor.c_str()))
- {
- m_flavor.assign("default");
- }
-
- unsigned flavor = ~0U;
- llvm::Triple triple = arch.GetTriple();
-
- // So far the only supported flavor is "intel" on x86. The base class will set this
- // correctly coming in.
- if (triple.getArch() == llvm::Triple::x86 || triple.getArch() == llvm::Triple::x86_64)
- {
- if (m_flavor == "intel")
- {
- flavor = 1;
- }
- else if (m_flavor == "att")
- {
- flavor = 0;
- }
- }
-
- ArchSpec thumb_arch(arch);
- if (triple.getArch() == llvm::Triple::arm)
- {
- std::string thumb_arch_name (thumb_arch.GetTriple().getArchName().str());
- // Replace "arm" with "thumb" so we get all thumb variants correct
- if (thumb_arch_name.size() > 3)
- {
- thumb_arch_name.erase(0,3);
- thumb_arch_name.insert(0, "thumb");
- }
- else
- {
- thumb_arch_name = "thumbv8.2a";
- }
- thumb_arch.GetTriple().setArchName(llvm::StringRef(thumb_arch_name.c_str()));
+DisassemblerLLVMC::DisassemblerLLVMC(const ArchSpec &arch,
+ const char *flavor_string)
+ : Disassembler(arch, flavor_string), m_exe_ctx(NULL), m_inst(NULL),
+ m_data_from_file(false) {
+ if (!FlavorValidForArchSpec(arch, m_flavor.c_str())) {
+ m_flavor.assign("default");
+ }
+
+ unsigned flavor = ~0U;
+ llvm::Triple triple = arch.GetTriple();
+
+ // So far the only supported flavor is "intel" on x86. The base class will
+ // set this
+ // correctly coming in.
+ if (triple.getArch() == llvm::Triple::x86 ||
+ triple.getArch() == llvm::Triple::x86_64) {
+ if (m_flavor == "intel") {
+ flavor = 1;
+ } else if (m_flavor == "att") {
+ flavor = 0;
+ }
+ }
+
+ ArchSpec thumb_arch(arch);
+ if (triple.getArch() == llvm::Triple::arm) {
+ std::string thumb_arch_name(thumb_arch.GetTriple().getArchName().str());
+ // Replace "arm" with "thumb" so we get all thumb variants correct
+ if (thumb_arch_name.size() > 3) {
+ thumb_arch_name.erase(0, 3);
+ thumb_arch_name.insert(0, "thumb");
+ } else {
+ thumb_arch_name = "thumbv8.2a";
+ }
+ thumb_arch.GetTriple().setArchName(
+ llvm::StringRef(thumb_arch_name.c_str()));
+ }
+
+ // If no sub architecture specified then use the most recent arm architecture
+ // so the
+ // disassembler will return all instruction. Without it we will see a lot of
+ // unknow opcode
+ // in case the code uses instructions which are not available in the oldest
+ // arm version
+ // (used when no sub architecture is specified)
+ if (triple.getArch() == llvm::Triple::arm &&
+ triple.getSubArch() == llvm::Triple::NoSubArch)
+ triple.setArchName("armv8.2a");
+
+ const char *triple_str = triple.getTriple().c_str();
+
+ // ARM Cortex M0-M7 devices only execute thumb instructions
+ if (arch.IsAlwaysThumbInstructions()) {
+ triple_str = thumb_arch.GetTriple().getTriple().c_str();
+ }
+
+ const char *cpu = "";
+
+ switch (arch.GetCore()) {
+ case ArchSpec::eCore_mips32:
+ case ArchSpec::eCore_mips32el:
+ cpu = "mips32";
+ break;
+ case ArchSpec::eCore_mips32r2:
+ case ArchSpec::eCore_mips32r2el:
+ cpu = "mips32r2";
+ break;
+ case ArchSpec::eCore_mips32r3:
+ case ArchSpec::eCore_mips32r3el:
+ cpu = "mips32r3";
+ break;
+ case ArchSpec::eCore_mips32r5:
+ case ArchSpec::eCore_mips32r5el:
+ cpu = "mips32r5";
+ break;
+ case ArchSpec::eCore_mips32r6:
+ case ArchSpec::eCore_mips32r6el:
+ cpu = "mips32r6";
+ break;
+ case ArchSpec::eCore_mips64:
+ case ArchSpec::eCore_mips64el:
+ cpu = "mips64";
+ break;
+ case ArchSpec::eCore_mips64r2:
+ case ArchSpec::eCore_mips64r2el:
+ cpu = "mips64r2";
+ break;
+ case ArchSpec::eCore_mips64r3:
+ case ArchSpec::eCore_mips64r3el:
+ cpu = "mips64r3";
+ break;
+ case ArchSpec::eCore_mips64r5:
+ case ArchSpec::eCore_mips64r5el:
+ cpu = "mips64r5";
+ break;
+ case ArchSpec::eCore_mips64r6:
+ case ArchSpec::eCore_mips64r6el:
+ cpu = "mips64r6";
+ break;
+ default:
+ cpu = "";
+ break;
+ }
+
+ std::string features_str = "";
+ if (triple.getArch() == llvm::Triple::mips ||
+ triple.getArch() == llvm::Triple::mipsel ||
+ triple.getArch() == llvm::Triple::mips64 ||
+ triple.getArch() == llvm::Triple::mips64el) {
+ uint32_t arch_flags = arch.GetFlags();
+ if (arch_flags & ArchSpec::eMIPSAse_msa)
+ features_str += "+msa,";
+ if (arch_flags & ArchSpec::eMIPSAse_dsp)
+ features_str += "+dsp,";
+ if (arch_flags & ArchSpec::eMIPSAse_dspr2)
+ features_str += "+dspr2,";
+ }
+
+ m_disasm_ap.reset(new LLVMCDisassembler(triple_str, cpu, features_str.c_str(),
+ flavor, *this));
+ if (!m_disasm_ap->IsValid()) {
+ // We use m_disasm_ap.get() to tell whether we are valid or not, so if this
+ // isn't good for some reason,
+ // we reset it, and then we won't be valid and FindPlugin will fail and we
+ // won't get used.
+ m_disasm_ap.reset();
+ }
+
+ llvm::Triple::ArchType llvm_arch = triple.getArch();
+
+ // For arm CPUs that can execute arm or thumb instructions, also create a
+ // thumb instruction disassembler.
+ if (llvm_arch == llvm::Triple::arm) {
+ std::string thumb_triple(thumb_arch.GetTriple().getTriple());
+ m_alternate_disasm_ap.reset(
+ new LLVMCDisassembler(thumb_triple.c_str(), "", "", flavor, *this));
+ if (!m_alternate_disasm_ap->IsValid()) {
+ m_disasm_ap.reset();
+ m_alternate_disasm_ap.reset();
+ }
+ } else if (llvm_arch == llvm::Triple::mips ||
+ llvm_arch == llvm::Triple::mipsel ||
+ llvm_arch == llvm::Triple::mips64 ||
+ llvm_arch == llvm::Triple::mips64el) {
+ /* Create alternate disassembler for MIPS16 and microMIPS */
+ uint32_t arch_flags = arch.GetFlags();
+ if (arch_flags & ArchSpec::eMIPSAse_mips16)
+ features_str += "+mips16,";
+ else if (arch_flags & ArchSpec::eMIPSAse_micromips)
+ features_str += "+micromips,";
+
+ m_alternate_disasm_ap.reset(new LLVMCDisassembler(
+ triple_str, cpu, features_str.c_str(), flavor, *this));
+ if (!m_alternate_disasm_ap->IsValid()) {
+ m_disasm_ap.reset();
+ m_alternate_disasm_ap.reset();
}
+ }
+}
- // If no sub architecture specified then use the most recent arm architecture so the
- // disassembler will return all instruction. Without it we will see a lot of unknow opcode
- // in case the code uses instructions which are not available in the oldest arm version
- // (used when no sub architecture is specified)
- if (triple.getArch() == llvm::Triple::arm && triple.getSubArch() == llvm::Triple::NoSubArch)
- triple.setArchName("armv8.2a");
-
- const char *triple_str = triple.getTriple().c_str();
-
- // ARM Cortex M0-M7 devices only execute thumb instructions
- if (arch.IsAlwaysThumbInstructions ())
- {
- triple_str = thumb_arch.GetTriple().getTriple().c_str();
- }
-
- const char *cpu = "";
-
- switch (arch.GetCore())
- {
- case ArchSpec::eCore_mips32:
- case ArchSpec::eCore_mips32el:
- cpu = "mips32"; break;
- case ArchSpec::eCore_mips32r2:
- case ArchSpec::eCore_mips32r2el:
- cpu = "mips32r2"; break;
- case ArchSpec::eCore_mips32r3:
- case ArchSpec::eCore_mips32r3el:
- cpu = "mips32r3"; break;
- case ArchSpec::eCore_mips32r5:
- case ArchSpec::eCore_mips32r5el:
- cpu = "mips32r5"; break;
- case ArchSpec::eCore_mips32r6:
- case ArchSpec::eCore_mips32r6el:
- cpu = "mips32r6"; break;
- case ArchSpec::eCore_mips64:
- case ArchSpec::eCore_mips64el:
- cpu = "mips64"; break;
- case ArchSpec::eCore_mips64r2:
- case ArchSpec::eCore_mips64r2el:
- cpu = "mips64r2"; break;
- case ArchSpec::eCore_mips64r3:
- case ArchSpec::eCore_mips64r3el:
- cpu = "mips64r3"; break;
- case ArchSpec::eCore_mips64r5:
- case ArchSpec::eCore_mips64r5el:
- cpu = "mips64r5"; break;
- case ArchSpec::eCore_mips64r6:
- case ArchSpec::eCore_mips64r6el:
- cpu = "mips64r6"; break;
- default:
- cpu = ""; break;
- }
+DisassemblerLLVMC::~DisassemblerLLVMC() = default;
- std::string features_str = "";
- if (triple.getArch() == llvm::Triple::mips || triple.getArch() == llvm::Triple::mipsel
- || triple.getArch() == llvm::Triple::mips64 || triple.getArch() == llvm::Triple::mips64el)
- {
- uint32_t arch_flags = arch.GetFlags ();
- if (arch_flags & ArchSpec::eMIPSAse_msa)
- features_str += "+msa,";
- if (arch_flags & ArchSpec::eMIPSAse_dsp)
- features_str += "+dsp,";
- if (arch_flags & ArchSpec::eMIPSAse_dspr2)
- features_str += "+dspr2,";
- }
-
- m_disasm_ap.reset (new LLVMCDisassembler(triple_str, cpu, features_str.c_str(), flavor, *this));
- if (!m_disasm_ap->IsValid())
- {
- // We use m_disasm_ap.get() to tell whether we are valid or not, so if this isn't good for some reason,
- // we reset it, and then we won't be valid and FindPlugin will fail and we won't get used.
- m_disasm_ap.reset();
- }
-
- llvm::Triple::ArchType llvm_arch = triple.getArch();
-
- // For arm CPUs that can execute arm or thumb instructions, also create a thumb instruction disassembler.
- if (llvm_arch == llvm::Triple::arm)
- {
- std::string thumb_triple(thumb_arch.GetTriple().getTriple());
- m_alternate_disasm_ap.reset(new LLVMCDisassembler(thumb_triple.c_str(), "", "", flavor, *this));
- if (!m_alternate_disasm_ap->IsValid())
- {
- m_disasm_ap.reset();
- m_alternate_disasm_ap.reset();
- }
- }
- else if (llvm_arch == llvm::Triple::mips
- || llvm_arch == llvm::Triple::mipsel
- || llvm_arch == llvm::Triple::mips64
- || llvm_arch == llvm::Triple::mips64el)
- {
- /* Create alternate disassembler for MIPS16 and microMIPS */
- uint32_t arch_flags = arch.GetFlags ();
- if (arch_flags & ArchSpec::eMIPSAse_mips16)
- features_str += "+mips16,";
- else if (arch_flags & ArchSpec::eMIPSAse_micromips)
- features_str += "+micromips,";
-
- m_alternate_disasm_ap.reset(new LLVMCDisassembler (triple_str, cpu, features_str.c_str(), flavor, *this));
- if (!m_alternate_disasm_ap->IsValid())
- {
- m_disasm_ap.reset();
- m_alternate_disasm_ap.reset();
- }
- }
+Disassembler *DisassemblerLLVMC::CreateInstance(const ArchSpec &arch,
+ const char *flavor) {
+ if (arch.GetTriple().getArch() != llvm::Triple::UnknownArch) {
+ std::unique_ptr<DisassemblerLLVMC> disasm_ap(
+ new DisassemblerLLVMC(arch, flavor));
+
+ if (disasm_ap.get() && disasm_ap->IsValid())
+ return disasm_ap.release();
+ }
+ return NULL;
}
-DisassemblerLLVMC::~DisassemblerLLVMC() = default;
+size_t DisassemblerLLVMC::DecodeInstructions(const Address &base_addr,
+ const DataExtractor &data,
+ lldb::offset_t data_offset,
+ size_t num_instructions,
+ bool append, bool data_from_file) {
+ if (!append)
+ m_instruction_list.Clear();
-Disassembler *
-DisassemblerLLVMC::CreateInstance (const ArchSpec &arch, const char *flavor)
-{
- if (arch.GetTriple().getArch() != llvm::Triple::UnknownArch)
- {
- std::unique_ptr<DisassemblerLLVMC> disasm_ap (new DisassemblerLLVMC(arch, flavor));
+ if (!IsValid())
+ return 0;
- if (disasm_ap.get() && disasm_ap->IsValid())
- return disasm_ap.release();
- }
- return NULL;
-}
+ m_data_from_file = data_from_file;
+ uint32_t data_cursor = data_offset;
+ const size_t data_byte_size = data.GetByteSize();
+ uint32_t instructions_parsed = 0;
+ Address inst_addr(base_addr);
-size_t
-DisassemblerLLVMC::DecodeInstructions (const Address &base_addr,
- const DataExtractor& data,
- lldb::offset_t data_offset,
- size_t num_instructions,
- bool append,
- bool data_from_file)
-{
- if (!append)
- m_instruction_list.Clear();
-
- if (!IsValid())
- return 0;
-
- m_data_from_file = data_from_file;
- uint32_t data_cursor = data_offset;
- const size_t data_byte_size = data.GetByteSize();
- uint32_t instructions_parsed = 0;
- Address inst_addr(base_addr);
-
- while (data_cursor < data_byte_size && instructions_parsed < num_instructions)
- {
-
- AddressClass address_class = eAddressClassCode;
-
- if (m_alternate_disasm_ap.get() != NULL)
- address_class = inst_addr.GetAddressClass ();
-
- InstructionSP inst_sp(new InstructionLLVMC(*this,
- inst_addr,
- address_class));
+ while (data_cursor < data_byte_size &&
+ instructions_parsed < num_instructions) {
- if (!inst_sp)
- break;
+ AddressClass address_class = eAddressClassCode;
- uint32_t inst_size = inst_sp->Decode(*this, data, data_cursor);
+ if (m_alternate_disasm_ap.get() != NULL)
+ address_class = inst_addr.GetAddressClass();
- if (inst_size == 0)
- break;
+ InstructionSP inst_sp(
+ new InstructionLLVMC(*this, inst_addr, address_class));
- m_instruction_list.Append(inst_sp);
- data_cursor += inst_size;
- inst_addr.Slide(inst_size);
- instructions_parsed++;
- }
+ if (!inst_sp)
+ break;
- return data_cursor - data_offset;
-}
+ uint32_t inst_size = inst_sp->Decode(*this, data, data_cursor);
+
+ if (inst_size == 0)
+ break;
-void
-DisassemblerLLVMC::Initialize()
-{
- PluginManager::RegisterPlugin (GetPluginNameStatic(),
- "Disassembler that uses LLVM MC to disassemble i386, x86_64, ARM, and ARM64.",
- CreateInstance);
-
- llvm::InitializeAllTargetInfos();
- llvm::InitializeAllTargetMCs();
- llvm::InitializeAllAsmParsers();
- llvm::InitializeAllDisassemblers();
+ m_instruction_list.Append(inst_sp);
+ data_cursor += inst_size;
+ inst_addr.Slide(inst_size);
+ instructions_parsed++;
+ }
+
+ return data_cursor - data_offset;
}
-void
-DisassemblerLLVMC::Terminate()
-{
- PluginManager::UnregisterPlugin (CreateInstance);
+void DisassemblerLLVMC::Initialize() {
+ PluginManager::RegisterPlugin(GetPluginNameStatic(),
+ "Disassembler that uses LLVM MC to disassemble "
+ "i386, x86_64, ARM, and ARM64.",
+ CreateInstance);
+
+ llvm::InitializeAllTargetInfos();
+ llvm::InitializeAllTargetMCs();
+ llvm::InitializeAllAsmParsers();
+ llvm::InitializeAllDisassemblers();
}
+void DisassemblerLLVMC::Terminate() {
+ PluginManager::UnregisterPlugin(CreateInstance);
+}
-ConstString
-DisassemblerLLVMC::GetPluginNameStatic()
-{
- static ConstString g_name("llvm-mc");
- return g_name;
+ConstString DisassemblerLLVMC::GetPluginNameStatic() {
+ static ConstString g_name("llvm-mc");
+ return g_name;
}
-int DisassemblerLLVMC::OpInfoCallback (void *disassembler,
- uint64_t pc,
- uint64_t offset,
- uint64_t size,
- int tag_type,
- void *tag_bug)
-{
- return static_cast<DisassemblerLLVMC*>(disassembler)->OpInfo (pc,
- offset,
- size,
- tag_type,
- tag_bug);
+int DisassemblerLLVMC::OpInfoCallback(void *disassembler, uint64_t pc,
+ uint64_t offset, uint64_t size,
+ int tag_type, void *tag_bug) {
+ return static_cast<DisassemblerLLVMC *>(disassembler)
+ ->OpInfo(pc, offset, size, tag_type, tag_bug);
}
-const char *DisassemblerLLVMC::SymbolLookupCallback (void *disassembler,
- uint64_t value,
- uint64_t *type,
- uint64_t pc,
- const char **name)
-{
- return static_cast<DisassemblerLLVMC*>(disassembler)->SymbolLookup(value,
- type,
- pc,
- name);
+const char *DisassemblerLLVMC::SymbolLookupCallback(void *disassembler,
+ uint64_t value,
+ uint64_t *type, uint64_t pc,
+ const char **name) {
+ return static_cast<DisassemblerLLVMC *>(disassembler)
+ ->SymbolLookup(value, type, pc, name);
}
-bool
-DisassemblerLLVMC::FlavorValidForArchSpec (const lldb_private::ArchSpec &arch, const char *flavor)
-{
- llvm::Triple triple = arch.GetTriple();
- if (flavor == NULL || strcmp (flavor, "default") == 0)
- return true;
-
- if (triple.getArch() == llvm::Triple::x86 || triple.getArch() == llvm::Triple::x86_64)
- {
- if (strcmp (flavor, "intel") == 0 || strcmp (flavor, "att") == 0)
- return true;
- else
- return false;
- }
+bool DisassemblerLLVMC::FlavorValidForArchSpec(
+ const lldb_private::ArchSpec &arch, const char *flavor) {
+ llvm::Triple triple = arch.GetTriple();
+ if (flavor == NULL || strcmp(flavor, "default") == 0)
+ return true;
+
+ if (triple.getArch() == llvm::Triple::x86 ||
+ triple.getArch() == llvm::Triple::x86_64) {
+ if (strcmp(flavor, "intel") == 0 || strcmp(flavor, "att") == 0)
+ return true;
else
- return false;
+ return false;
+ } else
+ return false;
}
-int DisassemblerLLVMC::OpInfo (uint64_t PC,
- uint64_t Offset,
- uint64_t Size,
- int tag_type,
- void *tag_bug)
-{
- switch (tag_type)
- {
- default:
- break;
- case 1:
- memset (tag_bug, 0, sizeof(::LLVMOpInfo1));
- break;
- }
- return 0;
+int DisassemblerLLVMC::OpInfo(uint64_t PC, uint64_t Offset, uint64_t Size,
+ int tag_type, void *tag_bug) {
+ switch (tag_type) {
+ default:
+ break;
+ case 1:
+ memset(tag_bug, 0, sizeof(::LLVMOpInfo1));
+ break;
+ }
+ return 0;
}
-const char *DisassemblerLLVMC::SymbolLookup (uint64_t value,
- uint64_t *type_ptr,
- uint64_t pc,
- const char **name)
-{
- if (*type_ptr)
- {
- if (m_exe_ctx && m_inst)
- {
- //std::string remove_this_prior_to_checkin;
- Target *target = m_exe_ctx ? m_exe_ctx->GetTargetPtr() : NULL;
- Address value_so_addr;
- Address pc_so_addr;
- if (m_inst->UsingFileAddress())
- {
- ModuleSP module_sp(m_inst->GetAddress().GetModule());
- if (module_sp)
- {
- module_sp->ResolveFileAddress(value, value_so_addr);
- module_sp->ResolveFileAddress(pc, pc_so_addr);
- }
- }
- else if (target && !target->GetSectionLoadList().IsEmpty())
- {
- target->GetSectionLoadList().ResolveLoadAddress(value, value_so_addr);
- target->GetSectionLoadList().ResolveLoadAddress(pc, pc_so_addr);
- }
-
- SymbolContext sym_ctx;
- const uint32_t resolve_scope = eSymbolContextFunction | eSymbolContextSymbol;
- if (pc_so_addr.IsValid() && pc_so_addr.GetModule())
- {
- pc_so_addr.GetModule()->ResolveSymbolContextForAddress (pc_so_addr, resolve_scope, sym_ctx);
- }
-
- if (value_so_addr.IsValid() && value_so_addr.GetSection())
- {
- StreamString ss;
-
- bool format_omitting_current_func_name = false;
- if (sym_ctx.symbol || sym_ctx.function)
- {
- AddressRange range;
- if (sym_ctx.GetAddressRange (resolve_scope, 0, false, range)
- && range.GetBaseAddress().IsValid()
- && range.ContainsLoadAddress (value_so_addr, target))
- {
- format_omitting_current_func_name = true;
- }
- }
-
- // If the "value" address (the target address we're symbolicating)
- // is inside the same SymbolContext as the current instruction pc
- // (pc_so_addr), don't print the full function name - just print it
- // with DumpStyleNoFunctionName style, e.g. "<+36>".
- if (format_omitting_current_func_name)
- {
- value_so_addr.Dump (&ss,
- target,
- Address::DumpStyleNoFunctionName,
- Address::DumpStyleSectionNameOffset);
- }
- else
- {
- value_so_addr.Dump (&ss,
- target,
- Address::DumpStyleResolvedDescriptionNoFunctionArguments,
- Address::DumpStyleSectionNameOffset);
- }
-
- if (!ss.GetString().empty())
- {
- // If Address::Dump returned a multi-line description, most commonly seen when we
- // have multiple levels of inlined functions at an address, only show the first line.
- std::string &str(ss.GetString());
- size_t first_eol_char = str.find_first_of ("\r\n");
- if (first_eol_char != std::string::npos)
- {
- str.erase (first_eol_char);
- }
- m_inst->AppendComment(ss.GetString());
- }
- }
- }
- }
-
- *type_ptr = LLVMDisassembler_ReferenceType_InOut_None;
- *name = NULL;
- return NULL;
+const char *DisassemblerLLVMC::SymbolLookup(uint64_t value, uint64_t *type_ptr,
+ uint64_t pc, const char **name) {
+ if (*type_ptr) {
+ if (m_exe_ctx && m_inst) {
+ // std::string remove_this_prior_to_checkin;
+ Target *target = m_exe_ctx ? m_exe_ctx->GetTargetPtr() : NULL;
+ Address value_so_addr;
+ Address pc_so_addr;
+ if (m_inst->UsingFileAddress()) {
+ ModuleSP module_sp(m_inst->GetAddress().GetModule());
+ if (module_sp) {
+ module_sp->ResolveFileAddress(value, value_so_addr);
+ module_sp->ResolveFileAddress(pc, pc_so_addr);
+ }
+ } else if (target && !target->GetSectionLoadList().IsEmpty()) {
+ target->GetSectionLoadList().ResolveLoadAddress(value, value_so_addr);
+ target->GetSectionLoadList().ResolveLoadAddress(pc, pc_so_addr);
+ }
+
+ SymbolContext sym_ctx;
+ const uint32_t resolve_scope =
+ eSymbolContextFunction | eSymbolContextSymbol;
+ if (pc_so_addr.IsValid() && pc_so_addr.GetModule()) {
+ pc_so_addr.GetModule()->ResolveSymbolContextForAddress(
+ pc_so_addr, resolve_scope, sym_ctx);
+ }
+
+ if (value_so_addr.IsValid() && value_so_addr.GetSection()) {
+ StreamString ss;
+
+ bool format_omitting_current_func_name = false;
+ if (sym_ctx.symbol || sym_ctx.function) {
+ AddressRange range;
+ if (sym_ctx.GetAddressRange(resolve_scope, 0, false, range) &&
+ range.GetBaseAddress().IsValid() &&
+ range.ContainsLoadAddress(value_so_addr, target)) {
+ format_omitting_current_func_name = true;
+ }
+ }
+
+ // If the "value" address (the target address we're symbolicating)
+ // is inside the same SymbolContext as the current instruction pc
+ // (pc_so_addr), don't print the full function name - just print it
+ // with DumpStyleNoFunctionName style, e.g. "<+36>".
+ if (format_omitting_current_func_name) {
+ value_so_addr.Dump(&ss, target, Address::DumpStyleNoFunctionName,
+ Address::DumpStyleSectionNameOffset);
+ } else {
+ value_so_addr.Dump(
+ &ss, target,
+ Address::DumpStyleResolvedDescriptionNoFunctionArguments,
+ Address::DumpStyleSectionNameOffset);
+ }
+
+ if (!ss.GetString().empty()) {
+ // If Address::Dump returned a multi-line description, most commonly
+ // seen when we
+ // have multiple levels of inlined functions at an address, only show
+ // the first line.
+ std::string &str(ss.GetString());
+ size_t first_eol_char = str.find_first_of("\r\n");
+ if (first_eol_char != std::string::npos) {
+ str.erase(first_eol_char);
+ }
+ m_inst->AppendComment(ss.GetString());
+ }
+ }
+ }
+ }
+
+ *type_ptr = LLVMDisassembler_ReferenceType_InOut_None;
+ *name = NULL;
+ return NULL;
}
//------------------------------------------------------------------
// PluginInterface protocol
//------------------------------------------------------------------
-ConstString
-DisassemblerLLVMC::GetPluginName()
-{
- return GetPluginNameStatic();
-}
+ConstString DisassemblerLLVMC::GetPluginName() { return GetPluginNameStatic(); }
-uint32_t
-DisassemblerLLVMC::GetPluginVersion()
-{
- return 1;
-}
+uint32_t DisassemblerLLVMC::GetPluginVersion() { return 1; }
Modified: lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.h (original)
+++ lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.h Tue Sep 6 15:57:50 2016
@@ -25,148 +25,128 @@
#include "lldb/Core/PluginManager.h"
// Opaque references to C++ Objects in LLVM's MC.
-namespace llvm
-{
- class MCContext;
- class MCInst;
- class MCInstrInfo;
- class MCRegisterInfo;
- class MCDisassembler;
- class MCInstPrinter;
- class MCAsmInfo;
- class MCSubtargetInfo;
+namespace llvm {
+class MCContext;
+class MCInst;
+class MCInstrInfo;
+class MCRegisterInfo;
+class MCDisassembler;
+class MCInstPrinter;
+class MCAsmInfo;
+class MCSubtargetInfo;
} // namespace llvm
class InstructionLLVMC;
-class DisassemblerLLVMC : public lldb_private::Disassembler
-{
- // Since we need to make two actual MC Disassemblers for ARM (ARM & THUMB), and there's a bit of goo to set up and own
- // in the MC disassembler world, I added this class to manage the actual disassemblers.
- class LLVMCDisassembler
- {
- public:
- LLVMCDisassembler (const char *triple, const char *cpu, const char *features_str, unsigned flavor, DisassemblerLLVMC &owner);
-
- ~LLVMCDisassembler();
-
- uint64_t GetMCInst (const uint8_t *opcode_data, size_t opcode_data_len, lldb::addr_t pc, llvm::MCInst &mc_inst);
- void PrintMCInst (llvm::MCInst &mc_inst, std::string &inst_string, std::string &comments_string);
- void SetStyle (bool use_hex_immed, HexImmediateStyle hex_style);
- bool CanBranch (llvm::MCInst &mc_inst);
- bool HasDelaySlot (llvm::MCInst &mc_inst);
- bool IsCall (llvm::MCInst &mc_inst);
- bool IsValid()
- {
- return m_is_valid;
- }
-
- private:
- bool m_is_valid;
- std::unique_ptr<llvm::MCContext> m_context_ap;
- std::unique_ptr<llvm::MCAsmInfo> m_asm_info_ap;
- std::unique_ptr<llvm::MCSubtargetInfo> m_subtarget_info_ap;
- std::unique_ptr<llvm::MCInstrInfo> m_instr_info_ap;
- std::unique_ptr<llvm::MCRegisterInfo> m_reg_info_ap;
- std::unique_ptr<llvm::MCInstPrinter> m_instr_printer_ap;
- std::unique_ptr<llvm::MCDisassembler> m_disasm_ap;
- };
+class DisassemblerLLVMC : public lldb_private::Disassembler {
+ // Since we need to make two actual MC Disassemblers for ARM (ARM & THUMB),
+ // and there's a bit of goo to set up and own
+ // in the MC disassembler world, I added this class to manage the actual
+ // disassemblers.
+ class LLVMCDisassembler {
+ public:
+ LLVMCDisassembler(const char *triple, const char *cpu,
+ const char *features_str, unsigned flavor,
+ DisassemblerLLVMC &owner);
+
+ ~LLVMCDisassembler();
+
+ uint64_t GetMCInst(const uint8_t *opcode_data, size_t opcode_data_len,
+ lldb::addr_t pc, llvm::MCInst &mc_inst);
+ void PrintMCInst(llvm::MCInst &mc_inst, std::string &inst_string,
+ std::string &comments_string);
+ void SetStyle(bool use_hex_immed, HexImmediateStyle hex_style);
+ bool CanBranch(llvm::MCInst &mc_inst);
+ bool HasDelaySlot(llvm::MCInst &mc_inst);
+ bool IsCall(llvm::MCInst &mc_inst);
+ bool IsValid() { return m_is_valid; }
+
+ private:
+ bool m_is_valid;
+ std::unique_ptr<llvm::MCContext> m_context_ap;
+ std::unique_ptr<llvm::MCAsmInfo> m_asm_info_ap;
+ std::unique_ptr<llvm::MCSubtargetInfo> m_subtarget_info_ap;
+ std::unique_ptr<llvm::MCInstrInfo> m_instr_info_ap;
+ std::unique_ptr<llvm::MCRegisterInfo> m_reg_info_ap;
+ std::unique_ptr<llvm::MCInstPrinter> m_instr_printer_ap;
+ std::unique_ptr<llvm::MCDisassembler> m_disasm_ap;
+ };
public:
- DisassemblerLLVMC(const lldb_private::ArchSpec &arch, const char *flavor /* = NULL */);
+ DisassemblerLLVMC(const lldb_private::ArchSpec &arch,
+ const char *flavor /* = NULL */);
- ~DisassemblerLLVMC() override;
+ ~DisassemblerLLVMC() override;
- //------------------------------------------------------------------
- // Static Functions
- //------------------------------------------------------------------
- static void
- Initialize();
-
- static void
- Terminate();
-
- static lldb_private::ConstString
- GetPluginNameStatic();
-
- static lldb_private::Disassembler *
- CreateInstance(const lldb_private::ArchSpec &arch, const char *flavor);
-
- size_t
- DecodeInstructions(const lldb_private::Address &base_addr,
- const lldb_private::DataExtractor& data,
- lldb::offset_t data_offset,
- size_t num_instructions,
- bool append,
- bool data_from_file) override;
-
- //------------------------------------------------------------------
- // PluginInterface protocol
- //------------------------------------------------------------------
- lldb_private::ConstString
- GetPluginName() override;
+ //------------------------------------------------------------------
+ // Static Functions
+ //------------------------------------------------------------------
+ static void Initialize();
- uint32_t
- GetPluginVersion() override;
+ static void Terminate();
+
+ static lldb_private::ConstString GetPluginNameStatic();
+
+ static lldb_private::Disassembler *
+ CreateInstance(const lldb_private::ArchSpec &arch, const char *flavor);
+
+ size_t DecodeInstructions(const lldb_private::Address &base_addr,
+ const lldb_private::DataExtractor &data,
+ lldb::offset_t data_offset, size_t num_instructions,
+ bool append, bool data_from_file) override;
+
+ //------------------------------------------------------------------
+ // PluginInterface protocol
+ //------------------------------------------------------------------
+ lldb_private::ConstString GetPluginName() override;
+
+ uint32_t GetPluginVersion() override;
protected:
- friend class InstructionLLVMC;
+ friend class InstructionLLVMC;
- bool
- FlavorValidForArchSpec(const lldb_private::ArchSpec &arch, const char *flavor) override;
+ bool FlavorValidForArchSpec(const lldb_private::ArchSpec &arch,
+ const char *flavor) override;
- bool
- IsValid()
- {
- return (m_disasm_ap.get() != NULL && m_disasm_ap->IsValid());
- }
-
- int OpInfo(uint64_t PC,
- uint64_t Offset,
- uint64_t Size,
- int TagType,
- void *TagBug);
-
- const char *SymbolLookup (uint64_t ReferenceValue,
- uint64_t *ReferenceType,
- uint64_t ReferencePC,
- const char **ReferenceName);
-
- static int OpInfoCallback (void *DisInfo,
- uint64_t PC,
- uint64_t Offset,
- uint64_t Size,
- int TagType,
- void *TagBug);
-
- static const char *SymbolLookupCallback(void *DisInfo,
- uint64_t ReferenceValue,
- uint64_t *ReferenceType,
- uint64_t ReferencePC,
- const char **ReferenceName);
-
- void Lock(InstructionLLVMC *inst,
- const lldb_private::ExecutionContext *exe_ctx)
- {
- m_mutex.lock();
- m_inst = inst;
- m_exe_ctx = exe_ctx;
- }
-
- void Unlock()
- {
- m_inst = NULL;
- m_exe_ctx = NULL;
- m_mutex.unlock();
- }
-
- const lldb_private::ExecutionContext *m_exe_ctx;
- InstructionLLVMC *m_inst;
- std::mutex m_mutex;
- bool m_data_from_file;
+ bool IsValid() {
+ return (m_disasm_ap.get() != NULL && m_disasm_ap->IsValid());
+ }
+
+ int OpInfo(uint64_t PC, uint64_t Offset, uint64_t Size, int TagType,
+ void *TagBug);
+
+ const char *SymbolLookup(uint64_t ReferenceValue, uint64_t *ReferenceType,
+ uint64_t ReferencePC, const char **ReferenceName);
+
+ static int OpInfoCallback(void *DisInfo, uint64_t PC, uint64_t Offset,
+ uint64_t Size, int TagType, void *TagBug);
+
+ static const char *SymbolLookupCallback(void *DisInfo,
+ uint64_t ReferenceValue,
+ uint64_t *ReferenceType,
+ uint64_t ReferencePC,
+ const char **ReferenceName);
+
+ void Lock(InstructionLLVMC *inst,
+ const lldb_private::ExecutionContext *exe_ctx) {
+ m_mutex.lock();
+ m_inst = inst;
+ m_exe_ctx = exe_ctx;
+ }
+
+ void Unlock() {
+ m_inst = NULL;
+ m_exe_ctx = NULL;
+ m_mutex.unlock();
+ }
+
+ const lldb_private::ExecutionContext *m_exe_ctx;
+ InstructionLLVMC *m_inst;
+ std::mutex m_mutex;
+ bool m_data_from_file;
- std::unique_ptr<LLVMCDisassembler> m_disasm_ap;
- std::unique_ptr<LLVMCDisassembler> m_alternate_disasm_ap;
+ std::unique_ptr<LLVMCDisassembler> m_disasm_ap;
+ std::unique_ptr<LLVMCDisassembler> m_alternate_disasm_ap;
};
#endif // liblldb_DisassemblerLLVM_h_
Modified: lldb/trunk/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp Tue Sep 6 15:57:50 2016
@@ -1,4 +1,5 @@
-//===-- DynamicLoaderDarwinKernel.cpp -----------------------------*- C++ -*-===//
+//===-- DynamicLoaderDarwinKernel.cpp -----------------------------*- C++
+//-*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -9,6 +10,7 @@
#include "lldb/Utility/SafeMachO.h"
+#include "Plugins/Platform/MacOSX/PlatformDarwinKernel.h"
#include "lldb/Breakpoint/StoppointCallbackContext.h"
#include "lldb/Core/DataBuffer.h"
#include "lldb/Core/DataBufferHeap.h"
@@ -28,14 +30,13 @@
#include "lldb/Target/Target.h"
#include "lldb/Target/Thread.h"
#include "lldb/Target/ThreadPlanRunToAddress.h"
-#include "Plugins/Platform/MacOSX/PlatformDarwinKernel.h"
#include "DynamicLoaderDarwinKernel.h"
//#define ENABLE_DEBUG_PRINTF // COMMENT THIS LINE OUT PRIOR TO CHECKIN
#ifdef ENABLE_DEBUG_PRINTF
#include <stdio.h>
-#define DEBUG_PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__)
+#define DEBUG_PRINTF(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#define DEBUG_PRINTF(fmt, ...)
#endif
@@ -44,89 +45,79 @@ using namespace lldb;
using namespace lldb_private;
// Progressively greater amounts of scanning we will allow
-// For some targets very early in startup, we can't do any random reads of memory or we can crash the device
+// For some targets very early in startup, we can't do any random reads of
+// memory or we can crash the device
// so a setting is needed that can completely disable the KASLR scans.
-enum KASLRScanType
-{
- eKASLRScanNone = 0, // No reading into the inferior at all
- eKASLRScanLowgloAddresses, // Check one word of memory for a possible kernel addr, then see if a kernel is there
- eKASLRScanNearPC, // Scan backwards from the current $pc looking for kernel; checking at 96 locations total
- eKASLRScanExhaustiveScan // Scan through the entire possible kernel address range looking for a kernel
-};
-
-OptionEnumValueElement
-g_kaslr_kernel_scan_enum_values[] =
-{
- { eKASLRScanNone, "none", "Do not read memory looking for a Darwin kernel when attaching." },
- { eKASLRScanLowgloAddresses, "basic", "Check for the Darwin kernel's load addr in the lowglo page (boot-args=debug) only." },
- { eKASLRScanNearPC, "fast-scan", "Scan near the pc value on attach to find the Darwin kernel's load address."},
- { eKASLRScanExhaustiveScan, "exhaustive-scan", "Scan through the entire potential address range of Darwin kernel (only on 32-bit targets)."},
- { 0, NULL, NULL }
+enum KASLRScanType {
+ eKASLRScanNone = 0, // No reading into the inferior at all
+ eKASLRScanLowgloAddresses, // Check one word of memory for a possible kernel
+ // addr, then see if a kernel is there
+ eKASLRScanNearPC, // Scan backwards from the current $pc looking for kernel;
+ // checking at 96 locations total
+ eKASLRScanExhaustiveScan // Scan through the entire possible kernel address
+ // range looking for a kernel
};
-static PropertyDefinition
-g_properties[] =
-{
- { "load-kexts" , OptionValue::eTypeBoolean, true, true, NULL, NULL, "Automatically loads kext images when attaching to a kernel." },
- { "scan-type", OptionValue::eTypeEnum, true, eKASLRScanNearPC, NULL, g_kaslr_kernel_scan_enum_values, "Control how many reads lldb will make while searching for a Darwin kernel on attach." },
- { NULL , OptionValue::eTypeInvalid, false, 0 , NULL, NULL, NULL }
-};
+OptionEnumValueElement g_kaslr_kernel_scan_enum_values[] = {
+ {eKASLRScanNone, "none",
+ "Do not read memory looking for a Darwin kernel when attaching."},
+ {eKASLRScanLowgloAddresses, "basic", "Check for the Darwin kernel's load "
+ "addr in the lowglo page "
+ "(boot-args=debug) only."},
+ {eKASLRScanNearPC, "fast-scan", "Scan near the pc value on attach to find "
+ "the Darwin kernel's load address."},
+ {eKASLRScanExhaustiveScan, "exhaustive-scan",
+ "Scan through the entire potential address range of Darwin kernel (only "
+ "on 32-bit targets)."},
+ {0, NULL, NULL}};
+
+static PropertyDefinition g_properties[] = {
+ {"load-kexts", OptionValue::eTypeBoolean, true, true, NULL, NULL,
+ "Automatically loads kext images when attaching to a kernel."},
+ {"scan-type", OptionValue::eTypeEnum, true, eKASLRScanNearPC, NULL,
+ g_kaslr_kernel_scan_enum_values, "Control how many reads lldb will make "
+ "while searching for a Darwin kernel on "
+ "attach."},
+ {NULL, OptionValue::eTypeInvalid, false, 0, NULL, NULL, NULL}};
-enum {
- ePropertyLoadKexts,
- ePropertyScanType
-};
+enum { ePropertyLoadKexts, ePropertyScanType };
-class DynamicLoaderDarwinKernelProperties : public Properties
-{
+class DynamicLoaderDarwinKernelProperties : public Properties {
public:
-
- static ConstString &
- GetSettingName ()
- {
- static ConstString g_setting_name("darwin-kernel");
- return g_setting_name;
- }
-
- DynamicLoaderDarwinKernelProperties() :
- Properties ()
- {
- m_collection_sp.reset (new OptionValueProperties(GetSettingName()));
- m_collection_sp->Initialize(g_properties);
- }
-
- virtual
- ~DynamicLoaderDarwinKernelProperties()
- {
- }
-
- bool
- GetLoadKexts() const
- {
- const uint32_t idx = ePropertyLoadKexts;
- return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
- }
-
- KASLRScanType
- GetScanType() const
- {
- const uint32_t idx = ePropertyScanType;
- return (KASLRScanType) m_collection_sp->GetPropertyAtIndexAsEnumeration (NULL, idx, g_properties[idx].default_uint_value);
- }
-
-
+ static ConstString &GetSettingName() {
+ static ConstString g_setting_name("darwin-kernel");
+ return g_setting_name;
+ }
+
+ DynamicLoaderDarwinKernelProperties() : Properties() {
+ m_collection_sp.reset(new OptionValueProperties(GetSettingName()));
+ m_collection_sp->Initialize(g_properties);
+ }
+
+ virtual ~DynamicLoaderDarwinKernelProperties() {}
+
+ bool GetLoadKexts() const {
+ const uint32_t idx = ePropertyLoadKexts;
+ return m_collection_sp->GetPropertyAtIndexAsBoolean(
+ NULL, idx, g_properties[idx].default_uint_value != 0);
+ }
+
+ KASLRScanType GetScanType() const {
+ const uint32_t idx = ePropertyScanType;
+ return (KASLRScanType)m_collection_sp->GetPropertyAtIndexAsEnumeration(
+ NULL, idx, g_properties[idx].default_uint_value);
+ }
};
-typedef std::shared_ptr<DynamicLoaderDarwinKernelProperties> DynamicLoaderDarwinKernelPropertiesSP;
+typedef std::shared_ptr<DynamicLoaderDarwinKernelProperties>
+ DynamicLoaderDarwinKernelPropertiesSP;
-static const DynamicLoaderDarwinKernelPropertiesSP &
-GetGlobalProperties()
-{
- static DynamicLoaderDarwinKernelPropertiesSP g_settings_sp;
- if (!g_settings_sp)
- g_settings_sp.reset (new DynamicLoaderDarwinKernelProperties ());
- return g_settings_sp;
+static const DynamicLoaderDarwinKernelPropertiesSP &GetGlobalProperties() {
+ static DynamicLoaderDarwinKernelPropertiesSP g_settings_sp;
+ if (!g_settings_sp)
+ g_settings_sp.reset(new DynamicLoaderDarwinKernelProperties());
+ return g_settings_sp;
}
//----------------------------------------------------------------------
@@ -134,360 +125,345 @@ GetGlobalProperties()
// the plugin info class that gets handed out by the plugin factory and
// allows the lldb to instantiate an instance of this class.
//----------------------------------------------------------------------
-DynamicLoader *
-DynamicLoaderDarwinKernel::CreateInstance (Process* process, bool force)
-{
- if (!force)
- {
- // If the user provided an executable binary and it is not a kernel,
- // this plugin should not create an instance.
- Module* exe_module = process->GetTarget().GetExecutableModulePointer();
- if (exe_module)
- {
- ObjectFile *object_file = exe_module->GetObjectFile();
- if (object_file)
- {
- if (object_file->GetStrata() != ObjectFile::eStrataKernel)
- {
- return NULL;
- }
- }
- }
-
- // If the target's architecture does not look like an Apple environment,
- // this plugin should not create an instance.
- const llvm::Triple &triple_ref = process->GetTarget().GetArchitecture().GetTriple();
- switch (triple_ref.getOS())
- {
- case llvm::Triple::Darwin:
- case llvm::Triple::MacOSX:
- case llvm::Triple::IOS:
- case llvm::Triple::TvOS:
- case llvm::Triple::WatchOS:
- if (triple_ref.getVendor() != llvm::Triple::Apple)
- {
- return NULL;
- }
- break;
- // If we have triple like armv7-unknown-unknown, we should try looking for a Darwin kernel.
- case llvm::Triple::UnknownOS:
- break;
- default:
- return NULL;
- break;
- }
- }
-
- // At this point if there is an ExecutableModule, it is a kernel and the Target is some variant of an Apple system.
- // If the Process hasn't provided the kernel load address, we need to look around in memory to find it.
-
- const addr_t kernel_load_address = SearchForDarwinKernel (process);
- if (CheckForKernelImageAtAddress (kernel_load_address, process).IsValid())
- {
- process->SetCanRunCode(false);
- return new DynamicLoaderDarwinKernel (process, kernel_load_address);
- }
- return NULL;
+DynamicLoader *DynamicLoaderDarwinKernel::CreateInstance(Process *process,
+ bool force) {
+ if (!force) {
+ // If the user provided an executable binary and it is not a kernel,
+ // this plugin should not create an instance.
+ Module *exe_module = process->GetTarget().GetExecutableModulePointer();
+ if (exe_module) {
+ ObjectFile *object_file = exe_module->GetObjectFile();
+ if (object_file) {
+ if (object_file->GetStrata() != ObjectFile::eStrataKernel) {
+ return NULL;
+ }
+ }
+ }
+
+ // If the target's architecture does not look like an Apple environment,
+ // this plugin should not create an instance.
+ const llvm::Triple &triple_ref =
+ process->GetTarget().GetArchitecture().GetTriple();
+ switch (triple_ref.getOS()) {
+ case llvm::Triple::Darwin:
+ case llvm::Triple::MacOSX:
+ case llvm::Triple::IOS:
+ case llvm::Triple::TvOS:
+ case llvm::Triple::WatchOS:
+ if (triple_ref.getVendor() != llvm::Triple::Apple) {
+ return NULL;
+ }
+ break;
+ // If we have triple like armv7-unknown-unknown, we should try looking for a
+ // Darwin kernel.
+ case llvm::Triple::UnknownOS:
+ break;
+ default:
+ return NULL;
+ break;
+ }
+ }
+
+ // At this point if there is an ExecutableModule, it is a kernel and the
+ // Target is some variant of an Apple system.
+ // If the Process hasn't provided the kernel load address, we need to look
+ // around in memory to find it.
+
+ const addr_t kernel_load_address = SearchForDarwinKernel(process);
+ if (CheckForKernelImageAtAddress(kernel_load_address, process).IsValid()) {
+ process->SetCanRunCode(false);
+ return new DynamicLoaderDarwinKernel(process, kernel_load_address);
+ }
+ return NULL;
}
lldb::addr_t
-DynamicLoaderDarwinKernel::SearchForDarwinKernel (Process *process)
-{
- addr_t kernel_load_address = process->GetImageInfoAddress();
- if (kernel_load_address == LLDB_INVALID_ADDRESS)
- {
- kernel_load_address = SearchForKernelAtSameLoadAddr (process);
- if (kernel_load_address == LLDB_INVALID_ADDRESS)
- {
- kernel_load_address = SearchForKernelWithDebugHints (process);
- if (kernel_load_address == LLDB_INVALID_ADDRESS)
- {
- kernel_load_address = SearchForKernelNearPC (process);
- if (kernel_load_address == LLDB_INVALID_ADDRESS)
- {
- kernel_load_address = SearchForKernelViaExhaustiveSearch (process);
- }
- }
+DynamicLoaderDarwinKernel::SearchForDarwinKernel(Process *process) {
+ addr_t kernel_load_address = process->GetImageInfoAddress();
+ if (kernel_load_address == LLDB_INVALID_ADDRESS) {
+ kernel_load_address = SearchForKernelAtSameLoadAddr(process);
+ if (kernel_load_address == LLDB_INVALID_ADDRESS) {
+ kernel_load_address = SearchForKernelWithDebugHints(process);
+ if (kernel_load_address == LLDB_INVALID_ADDRESS) {
+ kernel_load_address = SearchForKernelNearPC(process);
+ if (kernel_load_address == LLDB_INVALID_ADDRESS) {
+ kernel_load_address = SearchForKernelViaExhaustiveSearch(process);
}
+ }
}
- return kernel_load_address;
+ }
+ return kernel_load_address;
}
//----------------------------------------------------------------------
// Check if the kernel binary is loaded in memory without a slide.
// First verify that the ExecutableModule is a kernel before we proceed.
-// Returns the address of the kernel if one was found, else LLDB_INVALID_ADDRESS.
+// Returns the address of the kernel if one was found, else
+// LLDB_INVALID_ADDRESS.
//----------------------------------------------------------------------
lldb::addr_t
-DynamicLoaderDarwinKernel::SearchForKernelAtSameLoadAddr (Process *process)
-{
- Module *exe_module = process->GetTarget().GetExecutableModulePointer();
- if (exe_module == NULL)
- return LLDB_INVALID_ADDRESS;
+DynamicLoaderDarwinKernel::SearchForKernelAtSameLoadAddr(Process *process) {
+ Module *exe_module = process->GetTarget().GetExecutableModulePointer();
+ if (exe_module == NULL)
+ return LLDB_INVALID_ADDRESS;
- ObjectFile *exe_objfile = exe_module->GetObjectFile();
- if (exe_objfile == NULL)
- return LLDB_INVALID_ADDRESS;
+ ObjectFile *exe_objfile = exe_module->GetObjectFile();
+ if (exe_objfile == NULL)
+ return LLDB_INVALID_ADDRESS;
- if (exe_objfile->GetType() != ObjectFile::eTypeExecutable || exe_objfile->GetStrata() != ObjectFile::eStrataKernel)
- return LLDB_INVALID_ADDRESS;
+ if (exe_objfile->GetType() != ObjectFile::eTypeExecutable ||
+ exe_objfile->GetStrata() != ObjectFile::eStrataKernel)
+ return LLDB_INVALID_ADDRESS;
- if (!exe_objfile->GetHeaderAddress().IsValid())
- return LLDB_INVALID_ADDRESS;
+ if (!exe_objfile->GetHeaderAddress().IsValid())
+ return LLDB_INVALID_ADDRESS;
- if (CheckForKernelImageAtAddress (exe_objfile->GetHeaderAddress().GetFileAddress(), process) == exe_module->GetUUID())
- return exe_objfile->GetHeaderAddress().GetFileAddress();
+ if (CheckForKernelImageAtAddress(
+ exe_objfile->GetHeaderAddress().GetFileAddress(), process) ==
+ exe_module->GetUUID())
+ return exe_objfile->GetHeaderAddress().GetFileAddress();
- return LLDB_INVALID_ADDRESS;
+ return LLDB_INVALID_ADDRESS;
}
//----------------------------------------------------------------------
-// If the debug flag is included in the boot-args nvram setting, the kernel's load address
+// If the debug flag is included in the boot-args nvram setting, the kernel's
+// load address
// will be noted in the lowglo page at a fixed address
-// Returns the address of the kernel if one was found, else LLDB_INVALID_ADDRESS.
+// Returns the address of the kernel if one was found, else
+// LLDB_INVALID_ADDRESS.
//----------------------------------------------------------------------
lldb::addr_t
-DynamicLoaderDarwinKernel::SearchForKernelWithDebugHints (Process *process)
-{
- if (GetGlobalProperties()->GetScanType() == eKASLRScanNone)
- return LLDB_INVALID_ADDRESS;
-
- Error read_err;
- addr_t addr = LLDB_INVALID_ADDRESS;
- addr_t kernel_addresses_64[] = { 0xfffffff000004010ULL, // newest arm64 devices
- 0xffffff8000004010ULL, // 2014-2015-ish arm64 devices
- 0xffffff8000002010ULL, // oldest arm64 devices
- LLDB_INVALID_ADDRESS };
- addr_t kernel_addresses_32[] = { 0xffff0110,
- LLDB_INVALID_ADDRESS };
- for (size_t i = 0; kernel_addresses_64[i] != LLDB_INVALID_ADDRESS; i++)
- {
- addr = process->ReadUnsignedIntegerFromMemory (kernel_addresses_64[i], 8, LLDB_INVALID_ADDRESS, read_err);
- if (CheckForKernelImageAtAddress (addr, process).IsValid())
- {
- return addr;
- }
- }
+DynamicLoaderDarwinKernel::SearchForKernelWithDebugHints(Process *process) {
+ if (GetGlobalProperties()->GetScanType() == eKASLRScanNone)
+ return LLDB_INVALID_ADDRESS;
- for (size_t i = 0; kernel_addresses_32[i] != LLDB_INVALID_ADDRESS; i++)
- {
- addr = process->ReadUnsignedIntegerFromMemory (kernel_addresses_32[i], 4, LLDB_INVALID_ADDRESS, read_err);
- if (CheckForKernelImageAtAddress (addr, process).IsValid())
- {
- return addr;
- }
+ Error read_err;
+ addr_t addr = LLDB_INVALID_ADDRESS;
+ addr_t kernel_addresses_64[] = {
+ 0xfffffff000004010ULL, // newest arm64 devices
+ 0xffffff8000004010ULL, // 2014-2015-ish arm64 devices
+ 0xffffff8000002010ULL, // oldest arm64 devices
+ LLDB_INVALID_ADDRESS};
+ addr_t kernel_addresses_32[] = {0xffff0110, LLDB_INVALID_ADDRESS};
+ for (size_t i = 0; kernel_addresses_64[i] != LLDB_INVALID_ADDRESS; i++) {
+ addr = process->ReadUnsignedIntegerFromMemory(
+ kernel_addresses_64[i], 8, LLDB_INVALID_ADDRESS, read_err);
+ if (CheckForKernelImageAtAddress(addr, process).IsValid()) {
+ return addr;
+ }
+ }
+
+ for (size_t i = 0; kernel_addresses_32[i] != LLDB_INVALID_ADDRESS; i++) {
+ addr = process->ReadUnsignedIntegerFromMemory(
+ kernel_addresses_32[i], 4, LLDB_INVALID_ADDRESS, read_err);
+ if (CheckForKernelImageAtAddress(addr, process).IsValid()) {
+ return addr;
}
+ }
- return LLDB_INVALID_ADDRESS;
+ return LLDB_INVALID_ADDRESS;
}
//----------------------------------------------------------------------
// If the kernel is currently executing when lldb attaches, and we don't have
// a better way of finding the kernel's load address, try searching backwards
// from the current pc value looking for the kernel's Mach header in memory.
-// Returns the address of the kernel if one was found, else LLDB_INVALID_ADDRESS.
+// Returns the address of the kernel if one was found, else
+// LLDB_INVALID_ADDRESS.
//----------------------------------------------------------------------
lldb::addr_t
-DynamicLoaderDarwinKernel::SearchForKernelNearPC (Process *process)
-{
- if (GetGlobalProperties()->GetScanType() == eKASLRScanNone
- || GetGlobalProperties()->GetScanType() == eKASLRScanLowgloAddresses)
- {
- return LLDB_INVALID_ADDRESS;
- }
-
- ThreadSP thread = process->GetThreadList().GetSelectedThread ();
- if (thread.get() == NULL)
- return LLDB_INVALID_ADDRESS;
- addr_t pc = thread->GetRegisterContext ()->GetPC(LLDB_INVALID_ADDRESS);
-
- if (pc == LLDB_INVALID_ADDRESS)
- return LLDB_INVALID_ADDRESS;
-
- // The kernel will load at at one megabyte boundary (0x100000), or at that boundary plus
- // an offset of one page (0x1000) or two, or four (0x4000), depending on the device.
-
- // Round the current pc down to the nearest one megabyte boundary - the place where we will start searching.
- addr_t addr = pc & ~0xfffff;
-
- // Search backwards 32 megabytes, looking for the start of the kernel at each one-megabyte boundary.
- for (int i = 0; i < 32; i++, addr -= 0x100000)
- {
- if (CheckForKernelImageAtAddress (addr, process).IsValid())
- return addr;
- if (CheckForKernelImageAtAddress (addr + 0x1000, process).IsValid())
- return addr + 0x1000;
- if (CheckForKernelImageAtAddress (addr + 0x2000, process).IsValid())
- return addr + 0x2000;
- if (CheckForKernelImageAtAddress (addr + 0x4000, process).IsValid())
- return addr + 0x4000;
- }
+DynamicLoaderDarwinKernel::SearchForKernelNearPC(Process *process) {
+ if (GetGlobalProperties()->GetScanType() == eKASLRScanNone ||
+ GetGlobalProperties()->GetScanType() == eKASLRScanLowgloAddresses) {
+ return LLDB_INVALID_ADDRESS;
+ }
+
+ ThreadSP thread = process->GetThreadList().GetSelectedThread();
+ if (thread.get() == NULL)
+ return LLDB_INVALID_ADDRESS;
+ addr_t pc = thread->GetRegisterContext()->GetPC(LLDB_INVALID_ADDRESS);
+ if (pc == LLDB_INVALID_ADDRESS)
return LLDB_INVALID_ADDRESS;
+
+ // The kernel will load at at one megabyte boundary (0x100000), or at that
+ // boundary plus
+ // an offset of one page (0x1000) or two, or four (0x4000), depending on the
+ // device.
+
+ // Round the current pc down to the nearest one megabyte boundary - the place
+ // where we will start searching.
+ addr_t addr = pc & ~0xfffff;
+
+ // Search backwards 32 megabytes, looking for the start of the kernel at each
+ // one-megabyte boundary.
+ for (int i = 0; i < 32; i++, addr -= 0x100000) {
+ if (CheckForKernelImageAtAddress(addr, process).IsValid())
+ return addr;
+ if (CheckForKernelImageAtAddress(addr + 0x1000, process).IsValid())
+ return addr + 0x1000;
+ if (CheckForKernelImageAtAddress(addr + 0x2000, process).IsValid())
+ return addr + 0x2000;
+ if (CheckForKernelImageAtAddress(addr + 0x4000, process).IsValid())
+ return addr + 0x4000;
+ }
+
+ return LLDB_INVALID_ADDRESS;
}
//----------------------------------------------------------------------
// Scan through the valid address range for a kernel binary.
// This is uselessly slow in 64-bit environments so we don't even try it.
// This scan is not enabled by default even for 32-bit targets.
-// Returns the address of the kernel if one was found, else LLDB_INVALID_ADDRESS.
+// Returns the address of the kernel if one was found, else
+// LLDB_INVALID_ADDRESS.
//----------------------------------------------------------------------
-lldb::addr_t
-DynamicLoaderDarwinKernel::SearchForKernelViaExhaustiveSearch (Process *process)
-{
- if (GetGlobalProperties()->GetScanType() != eKASLRScanExhaustiveScan)
- {
- return LLDB_INVALID_ADDRESS;
- }
+lldb::addr_t DynamicLoaderDarwinKernel::SearchForKernelViaExhaustiveSearch(
+ Process *process) {
+ if (GetGlobalProperties()->GetScanType() != eKASLRScanExhaustiveScan) {
+ return LLDB_INVALID_ADDRESS;
+ }
- addr_t kernel_range_low, kernel_range_high;
- if (process->GetTarget().GetArchitecture().GetAddressByteSize() == 8)
- {
- kernel_range_low = 1ULL << 63;
- kernel_range_high = UINT64_MAX;
- }
- else
- {
- kernel_range_low = 1ULL << 31;
- kernel_range_high = UINT32_MAX;
- }
-
- // Stepping through memory at one-megabyte resolution looking for a kernel
- // rarely works (fast enough) with a 64-bit address space -- for now, let's
- // not even bother. We may be attaching to something which *isn't* a kernel
- // and we don't want to spin for minutes on-end looking for a kernel.
- if (process->GetTarget().GetArchitecture().GetAddressByteSize() == 8)
- return LLDB_INVALID_ADDRESS;
-
- addr_t addr = kernel_range_low;
-
- while (addr >= kernel_range_low && addr < kernel_range_high)
- {
- if (CheckForKernelImageAtAddress (addr, process).IsValid())
- return addr;
- if (CheckForKernelImageAtAddress (addr + 0x1000, process).IsValid())
- return addr + 0x1000;
- if (CheckForKernelImageAtAddress (addr + 0x2000, process).IsValid())
- return addr + 0x2000;
- if (CheckForKernelImageAtAddress (addr + 0x4000, process).IsValid())
- return addr + 0x4000;
- addr += 0x100000;
- }
+ addr_t kernel_range_low, kernel_range_high;
+ if (process->GetTarget().GetArchitecture().GetAddressByteSize() == 8) {
+ kernel_range_low = 1ULL << 63;
+ kernel_range_high = UINT64_MAX;
+ } else {
+ kernel_range_low = 1ULL << 31;
+ kernel_range_high = UINT32_MAX;
+ }
+
+ // Stepping through memory at one-megabyte resolution looking for a kernel
+ // rarely works (fast enough) with a 64-bit address space -- for now, let's
+ // not even bother. We may be attaching to something which *isn't* a kernel
+ // and we don't want to spin for minutes on-end looking for a kernel.
+ if (process->GetTarget().GetArchitecture().GetAddressByteSize() == 8)
return LLDB_INVALID_ADDRESS;
+
+ addr_t addr = kernel_range_low;
+
+ while (addr >= kernel_range_low && addr < kernel_range_high) {
+ if (CheckForKernelImageAtAddress(addr, process).IsValid())
+ return addr;
+ if (CheckForKernelImageAtAddress(addr + 0x1000, process).IsValid())
+ return addr + 0x1000;
+ if (CheckForKernelImageAtAddress(addr + 0x2000, process).IsValid())
+ return addr + 0x2000;
+ if (CheckForKernelImageAtAddress(addr + 0x4000, process).IsValid())
+ return addr + 0x4000;
+ addr += 0x100000;
+ }
+ return LLDB_INVALID_ADDRESS;
}
//----------------------------------------------------------------------
// Given an address in memory, look to see if there is a kernel image at that
-// address.
-// Returns a UUID; if a kernel was not found at that address, UUID.IsValid() will be false.
+// address.
+// Returns a UUID; if a kernel was not found at that address, UUID.IsValid()
+// will be false.
//----------------------------------------------------------------------
lldb_private::UUID
-DynamicLoaderDarwinKernel::CheckForKernelImageAtAddress (lldb::addr_t addr, Process *process)
-{
- Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_DYNAMIC_LOADER));
- if (addr == LLDB_INVALID_ADDRESS)
- return UUID();
+DynamicLoaderDarwinKernel::CheckForKernelImageAtAddress(lldb::addr_t addr,
+ Process *process) {
+ Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
+ if (addr == LLDB_INVALID_ADDRESS)
+ return UUID();
- if (log)
- log->Printf ("DynamicLoaderDarwinKernel::CheckForKernelImageAtAddress: looking for kernel binary at 0x%" PRIx64, addr);
+ if (log)
+ log->Printf("DynamicLoaderDarwinKernel::CheckForKernelImageAtAddress: "
+ "looking for kernel binary at 0x%" PRIx64,
+ addr);
+
+ // First try a quick test -- read the first 4 bytes and see if there is a
+ // valid Mach-O magic field there
+ // (the first field of the mach_header/mach_header_64 struct).
+
+ Error read_error;
+ uint64_t result = process->ReadUnsignedIntegerFromMemory(
+ addr, 4, LLDB_INVALID_ADDRESS, read_error);
+ if (result != llvm::MachO::MH_MAGIC_64 && result != llvm::MachO::MH_MAGIC &&
+ result != llvm::MachO::MH_CIGAM && result != llvm::MachO::MH_CIGAM_64) {
+ return UUID();
+ }
+
+ // Read the mach header and see whether it looks like a kernel
+ llvm::MachO::mach_header header;
+ if (process->DoReadMemory(addr, &header, sizeof(header), read_error) !=
+ sizeof(header))
+ return UUID();
- // First try a quick test -- read the first 4 bytes and see if there is a valid Mach-O magic field there
- // (the first field of the mach_header/mach_header_64 struct).
+ if (header.magic == llvm::MachO::MH_CIGAM ||
+ header.magic == llvm::MachO::MH_CIGAM_64) {
+ header.magic = llvm::ByteSwap_32(header.magic);
+ header.cputype = llvm::ByteSwap_32(header.cputype);
+ header.cpusubtype = llvm::ByteSwap_32(header.cpusubtype);
+ header.filetype = llvm::ByteSwap_32(header.filetype);
+ header.ncmds = llvm::ByteSwap_32(header.ncmds);
+ header.sizeofcmds = llvm::ByteSwap_32(header.sizeofcmds);
+ header.flags = llvm::ByteSwap_32(header.flags);
+ }
+
+ // A kernel is an executable which does not have the dynamic link object flag
+ // set.
+ if (header.filetype == llvm::MachO::MH_EXECUTE &&
+ (header.flags & llvm::MachO::MH_DYLDLINK) == 0) {
+ // Create a full module to get the UUID
+ ModuleSP memory_module_sp = process->ReadModuleFromMemory(
+ FileSpec("temp_mach_kernel", false), addr);
+ if (!memory_module_sp.get())
+ return UUID();
- Error read_error;
- uint64_t result = process->ReadUnsignedIntegerFromMemory (addr, 4, LLDB_INVALID_ADDRESS, read_error);
- if (result != llvm::MachO::MH_MAGIC_64
- && result != llvm::MachO::MH_MAGIC
- && result != llvm::MachO::MH_CIGAM
- && result != llvm::MachO::MH_CIGAM_64)
- {
- return UUID();
- }
-
- // Read the mach header and see whether it looks like a kernel
- llvm::MachO::mach_header header;
- if (process->DoReadMemory (addr, &header, sizeof (header), read_error) != sizeof (header))
- return UUID();
-
- if (header.magic == llvm::MachO::MH_CIGAM ||
- header.magic == llvm::MachO::MH_CIGAM_64)
- {
- header.magic = llvm::ByteSwap_32 (header.magic);
- header.cputype = llvm::ByteSwap_32 (header.cputype);
- header.cpusubtype = llvm::ByteSwap_32 (header.cpusubtype);
- header.filetype = llvm::ByteSwap_32 (header.filetype);
- header.ncmds = llvm::ByteSwap_32 (header.ncmds);
- header.sizeofcmds = llvm::ByteSwap_32 (header.sizeofcmds);
- header.flags = llvm::ByteSwap_32 (header.flags);
- }
-
- // A kernel is an executable which does not have the dynamic link object flag set.
- if (header.filetype == llvm::MachO::MH_EXECUTE
- && (header.flags & llvm::MachO::MH_DYLDLINK) == 0)
- {
- // Create a full module to get the UUID
- ModuleSP memory_module_sp = process->ReadModuleFromMemory (FileSpec ("temp_mach_kernel", false), addr);
- if (!memory_module_sp.get())
- return UUID();
-
- ObjectFile *exe_objfile = memory_module_sp->GetObjectFile();
- if (exe_objfile == NULL)
- return UUID();
-
- if (exe_objfile->GetType() == ObjectFile::eTypeExecutable && exe_objfile->GetStrata() == ObjectFile::eStrataKernel)
- {
- ArchSpec kernel_arch (eArchTypeMachO, header.cputype, header.cpusubtype);
- if (!process->GetTarget().GetArchitecture().IsCompatibleMatch(kernel_arch))
- {
- process->GetTarget().SetArchitecture (kernel_arch);
- }
- if (log)
- log->Printf ("DynamicLoaderDarwinKernel::CheckForKernelImageAtAddress: kernel binary image found at 0x%" PRIx64, addr);
- return memory_module_sp->GetUUID();
- }
+ ObjectFile *exe_objfile = memory_module_sp->GetObjectFile();
+ if (exe_objfile == NULL)
+ return UUID();
+
+ if (exe_objfile->GetType() == ObjectFile::eTypeExecutable &&
+ exe_objfile->GetStrata() == ObjectFile::eStrataKernel) {
+ ArchSpec kernel_arch(eArchTypeMachO, header.cputype, header.cpusubtype);
+ if (!process->GetTarget().GetArchitecture().IsCompatibleMatch(
+ kernel_arch)) {
+ process->GetTarget().SetArchitecture(kernel_arch);
+ }
+ if (log)
+ log->Printf("DynamicLoaderDarwinKernel::CheckForKernelImageAtAddress: "
+ "kernel binary image found at 0x%" PRIx64,
+ addr);
+ return memory_module_sp->GetUUID();
}
+ }
- return UUID();
+ return UUID();
}
//----------------------------------------------------------------------
// Constructor
//----------------------------------------------------------------------
-DynamicLoaderDarwinKernel::DynamicLoaderDarwinKernel(Process *process, lldb::addr_t kernel_addr)
- : DynamicLoader(process),
- m_kernel_load_address(kernel_addr),
- m_kernel(),
- m_kext_summary_header_ptr_addr(),
- m_kext_summary_header_addr(),
- m_kext_summary_header(),
- m_known_kexts(),
- m_mutex(),
- m_break_id(LLDB_INVALID_BREAK_ID)
-{
- Error error;
- PlatformSP platform_sp(Platform::Create(PlatformDarwinKernel::GetPluginNameStatic(), error));
- // Only select the darwin-kernel Platform if we've been asked to load kexts.
- // It can take some time to scan over all of the kext info.plists and that
- // shouldn't be done if kext loading is explicitly disabled.
- if (platform_sp.get() && GetGlobalProperties()->GetLoadKexts())
- {
- process->GetTarget().SetPlatform(platform_sp);
- }
+DynamicLoaderDarwinKernel::DynamicLoaderDarwinKernel(Process *process,
+ lldb::addr_t kernel_addr)
+ : DynamicLoader(process), m_kernel_load_address(kernel_addr), m_kernel(),
+ m_kext_summary_header_ptr_addr(), m_kext_summary_header_addr(),
+ m_kext_summary_header(), m_known_kexts(), m_mutex(),
+ m_break_id(LLDB_INVALID_BREAK_ID) {
+ Error error;
+ PlatformSP platform_sp(
+ Platform::Create(PlatformDarwinKernel::GetPluginNameStatic(), error));
+ // Only select the darwin-kernel Platform if we've been asked to load kexts.
+ // It can take some time to scan over all of the kext info.plists and that
+ // shouldn't be done if kext loading is explicitly disabled.
+ if (platform_sp.get() && GetGlobalProperties()->GetLoadKexts()) {
+ process->GetTarget().SetPlatform(platform_sp);
+ }
}
//----------------------------------------------------------------------
// Destructor
//----------------------------------------------------------------------
-DynamicLoaderDarwinKernel::~DynamicLoaderDarwinKernel()
-{
- Clear(true);
-}
+DynamicLoaderDarwinKernel::~DynamicLoaderDarwinKernel() { Clear(true); }
-void
-DynamicLoaderDarwinKernel::UpdateIfNeeded()
-{
- LoadKernelModuleIfNeeded();
- SetNotificationBreakpointIfNeeded ();
+void DynamicLoaderDarwinKernel::UpdateIfNeeded() {
+ LoadKernelModuleIfNeeded();
+ SetNotificationBreakpointIfNeeded();
}
//------------------------------------------------------------------
/// Called after attaching a process.
@@ -495,11 +471,9 @@ DynamicLoaderDarwinKernel::UpdateIfNeede
/// Allow DynamicLoader plug-ins to execute some code after
/// attaching to a process.
//------------------------------------------------------------------
-void
-DynamicLoaderDarwinKernel::DidAttach ()
-{
- PrivateInitialize(m_process);
- UpdateIfNeeded();
+void DynamicLoaderDarwinKernel::DidAttach() {
+ PrivateInitialize(m_process);
+ UpdateIfNeeded();
}
//------------------------------------------------------------------
@@ -508,595 +482,528 @@ DynamicLoaderDarwinKernel::DidAttach ()
/// Allow DynamicLoader plug-ins to execute some code after
/// attaching to a process.
//------------------------------------------------------------------
-void
-DynamicLoaderDarwinKernel::DidLaunch ()
-{
- PrivateInitialize(m_process);
- UpdateIfNeeded();
+void DynamicLoaderDarwinKernel::DidLaunch() {
+ PrivateInitialize(m_process);
+ UpdateIfNeeded();
}
-
//----------------------------------------------------------------------
// Clear out the state of this class.
//----------------------------------------------------------------------
-void
-DynamicLoaderDarwinKernel::Clear (bool clear_process)
-{
- std::lock_guard<std::recursive_mutex> guard(m_mutex);
-
- if (m_process->IsAlive() && LLDB_BREAK_ID_IS_VALID(m_break_id))
- m_process->ClearBreakpointSiteByID(m_break_id);
+void DynamicLoaderDarwinKernel::Clear(bool clear_process) {
+ std::lock_guard<std::recursive_mutex> guard(m_mutex);
- if (clear_process)
- m_process = NULL;
- m_kernel.Clear();
- m_known_kexts.clear();
- m_kext_summary_header_ptr_addr.Clear();
- m_kext_summary_header_addr.Clear();
- m_break_id = LLDB_INVALID_BREAK_ID;
-}
+ if (m_process->IsAlive() && LLDB_BREAK_ID_IS_VALID(m_break_id))
+ m_process->ClearBreakpointSiteByID(m_break_id);
+ if (clear_process)
+ m_process = NULL;
+ m_kernel.Clear();
+ m_known_kexts.clear();
+ m_kext_summary_header_ptr_addr.Clear();
+ m_kext_summary_header_addr.Clear();
+ m_break_id = LLDB_INVALID_BREAK_ID;
+}
+
+bool DynamicLoaderDarwinKernel::KextImageInfo::LoadImageAtFileAddress(
+ Process *process) {
+ if (IsLoaded())
+ return true;
-bool
-DynamicLoaderDarwinKernel::KextImageInfo::LoadImageAtFileAddress (Process *process)
-{
- if (IsLoaded())
- return true;
-
- if (m_module_sp)
- {
- bool changed = false;
- if (m_module_sp->SetLoadAddress (process->GetTarget(), 0, true, changed))
- m_load_process_stop_id = process->GetStopID();
- }
- return false;
+ if (m_module_sp) {
+ bool changed = false;
+ if (m_module_sp->SetLoadAddress(process->GetTarget(), 0, true, changed))
+ m_load_process_stop_id = process->GetStopID();
+ }
+ return false;
}
-void
-DynamicLoaderDarwinKernel::KextImageInfo::SetModule (ModuleSP module_sp)
-{
- m_module_sp = module_sp;
- if (module_sp.get() && module_sp->GetObjectFile())
- {
- if (module_sp->GetObjectFile()->GetType() == ObjectFile::eTypeExecutable
- && module_sp->GetObjectFile()->GetStrata() == ObjectFile::eStrataKernel)
- {
- m_kernel_image = true;
- }
- else
- {
- m_kernel_image = false;
- }
+void DynamicLoaderDarwinKernel::KextImageInfo::SetModule(ModuleSP module_sp) {
+ m_module_sp = module_sp;
+ if (module_sp.get() && module_sp->GetObjectFile()) {
+ if (module_sp->GetObjectFile()->GetType() == ObjectFile::eTypeExecutable &&
+ module_sp->GetObjectFile()->GetStrata() == ObjectFile::eStrataKernel) {
+ m_kernel_image = true;
+ } else {
+ m_kernel_image = false;
}
+ }
}
-ModuleSP
-DynamicLoaderDarwinKernel::KextImageInfo::GetModule ()
-{
- return m_module_sp;
+ModuleSP DynamicLoaderDarwinKernel::KextImageInfo::GetModule() {
+ return m_module_sp;
}
-void
-DynamicLoaderDarwinKernel::KextImageInfo::SetLoadAddress (addr_t load_addr)
-{
- m_load_address = load_addr;
+void DynamicLoaderDarwinKernel::KextImageInfo::SetLoadAddress(
+ addr_t load_addr) {
+ m_load_address = load_addr;
}
-addr_t
-DynamicLoaderDarwinKernel::KextImageInfo::GetLoadAddress () const
-{
- return m_load_address;
+addr_t DynamicLoaderDarwinKernel::KextImageInfo::GetLoadAddress() const {
+ return m_load_address;
}
-uint64_t
-DynamicLoaderDarwinKernel::KextImageInfo::GetSize () const
-{
- return m_size;
+uint64_t DynamicLoaderDarwinKernel::KextImageInfo::GetSize() const {
+ return m_size;
}
-void
-DynamicLoaderDarwinKernel::KextImageInfo::SetSize (uint64_t size)
-{
- m_size = size;
+void DynamicLoaderDarwinKernel::KextImageInfo::SetSize(uint64_t size) {
+ m_size = size;
}
-uint32_t
-DynamicLoaderDarwinKernel::KextImageInfo::GetProcessStopId () const
-{
- return m_load_process_stop_id;
+uint32_t DynamicLoaderDarwinKernel::KextImageInfo::GetProcessStopId() const {
+ return m_load_process_stop_id;
}
-void
-DynamicLoaderDarwinKernel::KextImageInfo::SetProcessStopId (uint32_t stop_id)
-{
- m_load_process_stop_id = stop_id;
+void DynamicLoaderDarwinKernel::KextImageInfo::SetProcessStopId(
+ uint32_t stop_id) {
+ m_load_process_stop_id = stop_id;
}
-bool
-DynamicLoaderDarwinKernel::KextImageInfo::operator== (const KextImageInfo &rhs)
-{
- if (m_uuid.IsValid() || rhs.GetUUID().IsValid())
- {
- if (m_uuid == rhs.GetUUID())
- {
- return true;
- }
- return false;
+bool DynamicLoaderDarwinKernel::KextImageInfo::
+operator==(const KextImageInfo &rhs) {
+ if (m_uuid.IsValid() || rhs.GetUUID().IsValid()) {
+ if (m_uuid == rhs.GetUUID()) {
+ return true;
}
+ return false;
+ }
- if (m_name == rhs.GetName() && m_load_address == rhs.GetLoadAddress())
- return true;
+ if (m_name == rhs.GetName() && m_load_address == rhs.GetLoadAddress())
+ return true;
- return false;
+ return false;
}
-void
-DynamicLoaderDarwinKernel::KextImageInfo::SetName (const char *name)
-{
- m_name = name;
+void DynamicLoaderDarwinKernel::KextImageInfo::SetName(const char *name) {
+ m_name = name;
}
-std::string
-DynamicLoaderDarwinKernel::KextImageInfo::GetName () const
-{
- return m_name;
+std::string DynamicLoaderDarwinKernel::KextImageInfo::GetName() const {
+ return m_name;
}
-void
-DynamicLoaderDarwinKernel::KextImageInfo::SetUUID (const UUID &uuid)
-{
- m_uuid = uuid;
+void DynamicLoaderDarwinKernel::KextImageInfo::SetUUID(const UUID &uuid) {
+ m_uuid = uuid;
}
-UUID
-DynamicLoaderDarwinKernel::KextImageInfo::GetUUID () const
-{
- return m_uuid;
+UUID DynamicLoaderDarwinKernel::KextImageInfo::GetUUID() const {
+ return m_uuid;
}
-// Given the m_load_address from the kext summaries, and a UUID, try to create an in-memory
-// Module at that address. Require that the MemoryModule have a matching UUID and detect
+// Given the m_load_address from the kext summaries, and a UUID, try to create
+// an in-memory
+// Module at that address. Require that the MemoryModule have a matching UUID
+// and detect
// if this MemoryModule is a kernel or a kext.
//
-// Returns true if m_memory_module_sp is now set to a valid Module.
-
-bool
-DynamicLoaderDarwinKernel::KextImageInfo::ReadMemoryModule (Process *process)
-{
- Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
- if (m_memory_module_sp.get() != NULL)
- return true;
- if (m_load_address == LLDB_INVALID_ADDRESS)
- return false;
-
- FileSpec file_spec;
- file_spec.SetFile (m_name.c_str(), false);
-
- ModuleSP memory_module_sp = process->ReadModuleFromMemory (file_spec, m_load_address);
-
- if (memory_module_sp.get() == NULL)
- return false;
-
- bool is_kernel = false;
- if (memory_module_sp->GetObjectFile())
- {
- if (memory_module_sp->GetObjectFile()->GetType() == ObjectFile::eTypeExecutable
- && memory_module_sp->GetObjectFile()->GetStrata() == ObjectFile::eStrataKernel)
- {
- is_kernel = true;
- }
- else if (memory_module_sp->GetObjectFile()->GetType() == ObjectFile::eTypeSharedLibrary)
- {
- is_kernel = false;
- }
- }
-
- // If this is a kext, and the kernel specified what UUID we should find at this
- // load address, require that the memory module have a matching UUID or something
- // has gone wrong and we should discard it.
- if (m_uuid.IsValid())
- {
- if (m_uuid != memory_module_sp->GetUUID())
- {
- if (log)
- {
- log->Printf ("KextImageInfo::ReadMemoryModule the kernel said to find uuid %s at 0x%" PRIx64 " but instead we found uuid %s, throwing it away", m_uuid.GetAsString().c_str(), m_load_address, memory_module_sp->GetUUID().GetAsString().c_str());
- }
- return false;
- }
- }
-
- // If the in-memory Module has a UUID, let's use that.
- if (!m_uuid.IsValid() && memory_module_sp->GetUUID().IsValid())
- {
- m_uuid = memory_module_sp->GetUUID();
- }
-
- m_memory_module_sp = memory_module_sp;
- m_kernel_image = is_kernel;
- if (is_kernel)
- {
- if (log)
- {
- // This is unusual and probably not intended
- log->Printf ("KextImageInfo::ReadMemoryModule read the kernel binary out of memory");
- }
- if (memory_module_sp->GetArchitecture().IsValid())
- {
- process->GetTarget().SetArchitecture(memory_module_sp->GetArchitecture());
- }
- if (m_uuid.IsValid())
- {
- ModuleSP exe_module_sp = process->GetTarget().GetExecutableModule();
- if (exe_module_sp.get() && exe_module_sp->GetUUID().IsValid())
- {
- if (m_uuid != exe_module_sp->GetUUID())
- {
- // The user specified a kernel binary that has a different UUID than
- // the kernel actually running in memory. This never ends well;
- // clear the user specified kernel binary from the Target.
-
- m_module_sp.reset();
-
- ModuleList user_specified_kernel_list;
- user_specified_kernel_list.Append (exe_module_sp);
- process->GetTarget().GetImages().Remove (user_specified_kernel_list);
- }
- }
- }
- }
+// Returns true if m_memory_module_sp is now set to a valid Module.
+bool DynamicLoaderDarwinKernel::KextImageInfo::ReadMemoryModule(
+ Process *process) {
+ Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
+ if (m_memory_module_sp.get() != NULL)
return true;
-}
-
-bool
-DynamicLoaderDarwinKernel::KextImageInfo::IsKernel () const
-{
- return m_kernel_image == true;
-}
-
-void
-DynamicLoaderDarwinKernel::KextImageInfo::SetIsKernel (bool is_kernel)
-{
- m_kernel_image = is_kernel;
-}
-
-bool
-DynamicLoaderDarwinKernel::KextImageInfo::LoadImageUsingMemoryModule (Process *process)
-{
- if (IsLoaded())
- return true;
-
-
- Target &target = process->GetTarget();
-
- // If we don't have / can't create a memory module for this kext, don't try to load it - we won't
- // have the correct segment load addresses.
- if (!ReadMemoryModule (process))
- {
- Log *log(GetLogIfAnyCategoriesSet (LIBLLDB_LOG_DYNAMIC_LOADER));
- if (log)
- log->Printf("Unable to read '%s' from memory at address 0x%" PRIx64 " to get the segment load addresses.", m_name.c_str(), m_load_address);
- return false;
- }
-
- bool uuid_is_valid = m_uuid.IsValid();
+ if (m_load_address == LLDB_INVALID_ADDRESS)
+ return false;
- if (IsKernel() && uuid_is_valid && m_memory_module_sp.get())
- {
- Stream *s = target.GetDebugger().GetOutputFile().get();
- if (s)
- {
- s->Printf ("Kernel UUID: %s\n", m_memory_module_sp->GetUUID().GetAsString().c_str());
- s->Printf ("Load Address: 0x%" PRIx64 "\n", m_load_address);
- }
- }
+ FileSpec file_spec;
+ file_spec.SetFile(m_name.c_str(), false);
- if (!m_module_sp)
- {
- // See if the kext has already been loaded into the target, probably by the user doing target modules add.
- const ModuleList &target_images = target.GetImages();
- m_module_sp = target_images.FindModule(m_uuid);
-
- // Search for the kext on the local filesystem via the UUID
- if (!m_module_sp && uuid_is_valid)
- {
- ModuleSpec module_spec;
- module_spec.GetUUID() = m_uuid;
- module_spec.GetArchitecture() = target.GetArchitecture();
-
- // For the kernel, we really do need an on-disk file copy of the binary to do anything useful.
- // This will force a clal to
- if (IsKernel())
- {
- if (Symbols::DownloadObjectAndSymbolFile (module_spec, true))
- {
- if (module_spec.GetFileSpec().Exists())
- {
- m_module_sp.reset(new Module (module_spec.GetFileSpec(), target.GetArchitecture()));
- if (m_module_sp.get() && m_module_sp->MatchesModuleSpec (module_spec))
- {
- ModuleList loaded_module_list;
- loaded_module_list.Append (m_module_sp);
- target.ModulesDidLoad (loaded_module_list);
- }
- }
- }
- }
+ ModuleSP memory_module_sp =
+ process->ReadModuleFromMemory(file_spec, m_load_address);
- // If the current platform is PlatformDarwinKernel, create a ModuleSpec with the filename set
- // to be the bundle ID for this kext, e.g. "com.apple.filesystems.msdosfs", and ask the platform
- // to find it.
- PlatformSP platform_sp (target.GetPlatform());
- if (!m_module_sp && platform_sp)
- {
- ConstString platform_name (platform_sp->GetPluginName());
- static ConstString g_platform_name (PlatformDarwinKernel::GetPluginNameStatic());
- if (platform_name == g_platform_name)
- {
- ModuleSpec kext_bundle_module_spec(module_spec);
- FileSpec kext_filespec(m_name.c_str(), false);
- kext_bundle_module_spec.GetFileSpec() = kext_filespec;
- platform_sp->GetSharedModule (kext_bundle_module_spec, process, m_module_sp, &target.GetExecutableSearchPaths(), NULL, NULL);
- }
- }
+ if (memory_module_sp.get() == NULL)
+ return false;
- // Ask the Target to find this file on the local system, if possible.
- // This will search in the list of currently-loaded files, look in the
- // standard search paths on the system, and on a Mac it will try calling
- // the DebugSymbols framework with the UUID to find the binary via its
- // search methods.
- if (!m_module_sp)
- {
- m_module_sp = target.GetSharedModule (module_spec);
- }
+ bool is_kernel = false;
+ if (memory_module_sp->GetObjectFile()) {
+ if (memory_module_sp->GetObjectFile()->GetType() ==
+ ObjectFile::eTypeExecutable &&
+ memory_module_sp->GetObjectFile()->GetStrata() ==
+ ObjectFile::eStrataKernel) {
+ is_kernel = true;
+ } else if (memory_module_sp->GetObjectFile()->GetType() ==
+ ObjectFile::eTypeSharedLibrary) {
+ is_kernel = false;
+ }
+ }
+
+ // If this is a kext, and the kernel specified what UUID we should find at
+ // this
+ // load address, require that the memory module have a matching UUID or
+ // something
+ // has gone wrong and we should discard it.
+ if (m_uuid.IsValid()) {
+ if (m_uuid != memory_module_sp->GetUUID()) {
+ if (log) {
+ log->Printf("KextImageInfo::ReadMemoryModule the kernel said to find "
+ "uuid %s at 0x%" PRIx64
+ " but instead we found uuid %s, throwing it away",
+ m_uuid.GetAsString().c_str(), m_load_address,
+ memory_module_sp->GetUUID().GetAsString().c_str());
+ }
+ return false;
+ }
+ }
+
+ // If the in-memory Module has a UUID, let's use that.
+ if (!m_uuid.IsValid() && memory_module_sp->GetUUID().IsValid()) {
+ m_uuid = memory_module_sp->GetUUID();
+ }
+
+ m_memory_module_sp = memory_module_sp;
+ m_kernel_image = is_kernel;
+ if (is_kernel) {
+ if (log) {
+ // This is unusual and probably not intended
+ log->Printf("KextImageInfo::ReadMemoryModule read the kernel binary out "
+ "of memory");
+ }
+ if (memory_module_sp->GetArchitecture().IsValid()) {
+ process->GetTarget().SetArchitecture(memory_module_sp->GetArchitecture());
+ }
+ if (m_uuid.IsValid()) {
+ ModuleSP exe_module_sp = process->GetTarget().GetExecutableModule();
+ if (exe_module_sp.get() && exe_module_sp->GetUUID().IsValid()) {
+ if (m_uuid != exe_module_sp->GetUUID()) {
+ // The user specified a kernel binary that has a different UUID than
+ // the kernel actually running in memory. This never ends well;
+ // clear the user specified kernel binary from the Target.
+
+ m_module_sp.reset();
+
+ ModuleList user_specified_kernel_list;
+ user_specified_kernel_list.Append(exe_module_sp);
+ process->GetTarget().GetImages().Remove(user_specified_kernel_list);
+ }
+ }
+ }
+ }
+
+ return true;
+}
+
+bool DynamicLoaderDarwinKernel::KextImageInfo::IsKernel() const {
+ return m_kernel_image == true;
+}
+
+void DynamicLoaderDarwinKernel::KextImageInfo::SetIsKernel(bool is_kernel) {
+ m_kernel_image = is_kernel;
+}
+
+bool DynamicLoaderDarwinKernel::KextImageInfo::LoadImageUsingMemoryModule(
+ Process *process) {
+ if (IsLoaded())
+ return true;
- if (IsKernel() && !m_module_sp)
- {
- Stream *s = target.GetDebugger().GetOutputFile().get();
- if (s)
- {
- s->Printf ("WARNING: Unable to locate kernel binary on the debugger system.\n");
- }
- }
- }
+ Target &target = process->GetTarget();
- // If we managed to find a module, append it to the target's list of images.
- // If we also have a memory module, require that they have matching UUIDs
- if (m_module_sp)
- {
- bool uuid_match_ok = true;
- if (m_memory_module_sp)
- {
- if (m_module_sp->GetUUID() != m_memory_module_sp->GetUUID())
- {
- uuid_match_ok = false;
- }
- }
- if (uuid_match_ok)
- {
- target.GetImages().AppendIfNeeded(m_module_sp);
- if (IsKernel() && target.GetExecutableModulePointer() != m_module_sp.get())
- {
- target.SetExecutableModule (m_module_sp, false);
- }
- }
- }
- }
-
- if (!m_module_sp && !IsKernel() && m_uuid.IsValid() && !m_name.empty())
- {
- Stream *s = target.GetDebugger().GetOutputFile().get();
- if (s)
- {
- s->Printf ("warning: Can't find binary/dSYM for %s (%s)\n",
- m_name.c_str(), m_uuid.GetAsString().c_str());
- }
- }
+ // If we don't have / can't create a memory module for this kext, don't try to
+ // load it - we won't
+ // have the correct segment load addresses.
+ if (!ReadMemoryModule(process)) {
+ Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
+ if (log)
+ log->Printf("Unable to read '%s' from memory at address 0x%" PRIx64
+ " to get the segment load addresses.",
+ m_name.c_str(), m_load_address);
+ return false;
+ }
- static ConstString g_section_name_LINKEDIT ("__LINKEDIT");
+ bool uuid_is_valid = m_uuid.IsValid();
- if (m_memory_module_sp && m_module_sp)
- {
- if (m_module_sp->GetUUID() == m_memory_module_sp->GetUUID())
- {
- ObjectFile *ondisk_object_file = m_module_sp->GetObjectFile();
- ObjectFile *memory_object_file = m_memory_module_sp->GetObjectFile();
-
- if (memory_object_file && ondisk_object_file)
- {
- // The memory_module for kexts may have an invalid __LINKEDIT seg; skip it.
- const bool ignore_linkedit = !IsKernel ();
-
- SectionList *ondisk_section_list = ondisk_object_file->GetSectionList ();
- SectionList *memory_section_list = memory_object_file->GetSectionList ();
- if (memory_section_list && ondisk_section_list)
- {
- const uint32_t num_ondisk_sections = ondisk_section_list->GetSize();
- // There may be CTF sections in the memory image so we can't
- // always just compare the number of sections (which are actually
- // segments in mach-o parlance)
- uint32_t sect_idx = 0;
-
- // Use the memory_module's addresses for each section to set the
- // file module's load address as appropriate. We don't want to use
- // a single slide value for the entire kext - different segments may
- // be slid different amounts by the kext loader.
-
- uint32_t num_sections_loaded = 0;
- for (sect_idx=0; sect_idx<num_ondisk_sections; ++sect_idx)
- {
- SectionSP ondisk_section_sp(ondisk_section_list->GetSectionAtIndex(sect_idx));
- if (ondisk_section_sp)
- {
- // Don't ever load __LINKEDIT as it may or may not be actually
- // mapped into memory and there is no current way to tell.
- // I filed rdar://problem/12851706 to track being able to tell
- // if the __LINKEDIT is actually mapped, but until then, we need
- // to not load the __LINKEDIT
- if (ignore_linkedit && ondisk_section_sp->GetName() == g_section_name_LINKEDIT)
- continue;
-
- const Section *memory_section = memory_section_list->FindSectionByName(ondisk_section_sp->GetName()).get();
- if (memory_section)
- {
- target.SetSectionLoadAddress (ondisk_section_sp, memory_section->GetFileAddress());
- ++num_sections_loaded;
- }
- }
- }
- if (num_sections_loaded > 0)
- m_load_process_stop_id = process->GetStopID();
- else
- m_module_sp.reset(); // No sections were loaded
- }
- else
- m_module_sp.reset(); // One or both section lists
- }
- else
- m_module_sp.reset(); // One or both object files missing
- }
- else
- m_module_sp.reset(); // UUID mismatch
- }
+ if (IsKernel() && uuid_is_valid && m_memory_module_sp.get()) {
+ Stream *s = target.GetDebugger().GetOutputFile().get();
+ if (s) {
+ s->Printf("Kernel UUID: %s\n",
+ m_memory_module_sp->GetUUID().GetAsString().c_str());
+ s->Printf("Load Address: 0x%" PRIx64 "\n", m_load_address);
+ }
+ }
+
+ if (!m_module_sp) {
+ // See if the kext has already been loaded into the target, probably by the
+ // user doing target modules add.
+ const ModuleList &target_images = target.GetImages();
+ m_module_sp = target_images.FindModule(m_uuid);
+
+ // Search for the kext on the local filesystem via the UUID
+ if (!m_module_sp && uuid_is_valid) {
+ ModuleSpec module_spec;
+ module_spec.GetUUID() = m_uuid;
+ module_spec.GetArchitecture() = target.GetArchitecture();
+
+ // For the kernel, we really do need an on-disk file copy of the binary to
+ // do anything useful.
+ // This will force a clal to
+ if (IsKernel()) {
+ if (Symbols::DownloadObjectAndSymbolFile(module_spec, true)) {
+ if (module_spec.GetFileSpec().Exists()) {
+ m_module_sp.reset(new Module(module_spec.GetFileSpec(),
+ target.GetArchitecture()));
+ if (m_module_sp.get() &&
+ m_module_sp->MatchesModuleSpec(module_spec)) {
+ ModuleList loaded_module_list;
+ loaded_module_list.Append(m_module_sp);
+ target.ModulesDidLoad(loaded_module_list);
+ }
+ }
+ }
+ }
+
+ // If the current platform is PlatformDarwinKernel, create a ModuleSpec
+ // with the filename set
+ // to be the bundle ID for this kext, e.g.
+ // "com.apple.filesystems.msdosfs", and ask the platform
+ // to find it.
+ PlatformSP platform_sp(target.GetPlatform());
+ if (!m_module_sp && platform_sp) {
+ ConstString platform_name(platform_sp->GetPluginName());
+ static ConstString g_platform_name(
+ PlatformDarwinKernel::GetPluginNameStatic());
+ if (platform_name == g_platform_name) {
+ ModuleSpec kext_bundle_module_spec(module_spec);
+ FileSpec kext_filespec(m_name.c_str(), false);
+ kext_bundle_module_spec.GetFileSpec() = kext_filespec;
+ platform_sp->GetSharedModule(
+ kext_bundle_module_spec, process, m_module_sp,
+ &target.GetExecutableSearchPaths(), NULL, NULL);
+ }
+ }
+
+ // Ask the Target to find this file on the local system, if possible.
+ // This will search in the list of currently-loaded files, look in the
+ // standard search paths on the system, and on a Mac it will try calling
+ // the DebugSymbols framework with the UUID to find the binary via its
+ // search methods.
+ if (!m_module_sp) {
+ m_module_sp = target.GetSharedModule(module_spec);
+ }
- bool is_loaded = IsLoaded();
-
- if (is_loaded && m_module_sp && IsKernel())
- {
+ if (IsKernel() && !m_module_sp) {
Stream *s = target.GetDebugger().GetOutputFile().get();
- if (s)
- {
- ObjectFile *kernel_object_file = m_module_sp->GetObjectFile();
- if (kernel_object_file)
- {
- addr_t file_address = kernel_object_file->GetHeaderAddress().GetFileAddress();
- if (m_load_address != LLDB_INVALID_ADDRESS && file_address != LLDB_INVALID_ADDRESS)
- {
- s->Printf ("Kernel slid 0x%" PRIx64 " in memory.\n", m_load_address - file_address);
- }
- }
- {
- s->Printf ("Loaded kernel file %s\n",
- m_module_sp->GetFileSpec().GetPath().c_str());
+ if (s) {
+ s->Printf("WARNING: Unable to locate kernel binary on the debugger "
+ "system.\n");
+ }
+ }
+ }
+
+ // If we managed to find a module, append it to the target's list of images.
+ // If we also have a memory module, require that they have matching UUIDs
+ if (m_module_sp) {
+ bool uuid_match_ok = true;
+ if (m_memory_module_sp) {
+ if (m_module_sp->GetUUID() != m_memory_module_sp->GetUUID()) {
+ uuid_match_ok = false;
+ }
+ }
+ if (uuid_match_ok) {
+ target.GetImages().AppendIfNeeded(m_module_sp);
+ if (IsKernel() &&
+ target.GetExecutableModulePointer() != m_module_sp.get()) {
+ target.SetExecutableModule(m_module_sp, false);
+ }
+ }
+ }
+ }
+
+ if (!m_module_sp && !IsKernel() && m_uuid.IsValid() && !m_name.empty()) {
+ Stream *s = target.GetDebugger().GetOutputFile().get();
+ if (s) {
+ s->Printf("warning: Can't find binary/dSYM for %s (%s)\n", m_name.c_str(),
+ m_uuid.GetAsString().c_str());
+ }
+ }
+
+ static ConstString g_section_name_LINKEDIT("__LINKEDIT");
+
+ if (m_memory_module_sp && m_module_sp) {
+ if (m_module_sp->GetUUID() == m_memory_module_sp->GetUUID()) {
+ ObjectFile *ondisk_object_file = m_module_sp->GetObjectFile();
+ ObjectFile *memory_object_file = m_memory_module_sp->GetObjectFile();
+
+ if (memory_object_file && ondisk_object_file) {
+ // The memory_module for kexts may have an invalid __LINKEDIT seg; skip
+ // it.
+ const bool ignore_linkedit = !IsKernel();
+
+ SectionList *ondisk_section_list = ondisk_object_file->GetSectionList();
+ SectionList *memory_section_list = memory_object_file->GetSectionList();
+ if (memory_section_list && ondisk_section_list) {
+ const uint32_t num_ondisk_sections = ondisk_section_list->GetSize();
+ // There may be CTF sections in the memory image so we can't
+ // always just compare the number of sections (which are actually
+ // segments in mach-o parlance)
+ uint32_t sect_idx = 0;
+
+ // Use the memory_module's addresses for each section to set the
+ // file module's load address as appropriate. We don't want to use
+ // a single slide value for the entire kext - different segments may
+ // be slid different amounts by the kext loader.
+
+ uint32_t num_sections_loaded = 0;
+ for (sect_idx = 0; sect_idx < num_ondisk_sections; ++sect_idx) {
+ SectionSP ondisk_section_sp(
+ ondisk_section_list->GetSectionAtIndex(sect_idx));
+ if (ondisk_section_sp) {
+ // Don't ever load __LINKEDIT as it may or may not be actually
+ // mapped into memory and there is no current way to tell.
+ // I filed rdar://problem/12851706 to track being able to tell
+ // if the __LINKEDIT is actually mapped, but until then, we need
+ // to not load the __LINKEDIT
+ if (ignore_linkedit &&
+ ondisk_section_sp->GetName() == g_section_name_LINKEDIT)
+ continue;
+
+ const Section *memory_section =
+ memory_section_list
+ ->FindSectionByName(ondisk_section_sp->GetName())
+ .get();
+ if (memory_section) {
+ target.SetSectionLoadAddress(ondisk_section_sp,
+ memory_section->GetFileAddress());
+ ++num_sections_loaded;
+ }
}
- s->Flush ();
- }
- }
- return is_loaded;
-}
-
-uint32_t
-DynamicLoaderDarwinKernel::KextImageInfo::GetAddressByteSize ()
-{
- if (m_memory_module_sp)
- return m_memory_module_sp->GetArchitecture().GetAddressByteSize();
- if (m_module_sp)
- return m_module_sp->GetArchitecture().GetAddressByteSize();
- return 0;
-}
-
-lldb::ByteOrder
-DynamicLoaderDarwinKernel::KextImageInfo::GetByteOrder()
-{
- if (m_memory_module_sp)
- return m_memory_module_sp->GetArchitecture().GetByteOrder();
- if (m_module_sp)
- return m_module_sp->GetArchitecture().GetByteOrder();
- return endian::InlHostByteOrder();
+ }
+ if (num_sections_loaded > 0)
+ m_load_process_stop_id = process->GetStopID();
+ else
+ m_module_sp.reset(); // No sections were loaded
+ } else
+ m_module_sp.reset(); // One or both section lists
+ } else
+ m_module_sp.reset(); // One or both object files missing
+ } else
+ m_module_sp.reset(); // UUID mismatch
+ }
+
+ bool is_loaded = IsLoaded();
+
+ if (is_loaded && m_module_sp && IsKernel()) {
+ Stream *s = target.GetDebugger().GetOutputFile().get();
+ if (s) {
+ ObjectFile *kernel_object_file = m_module_sp->GetObjectFile();
+ if (kernel_object_file) {
+ addr_t file_address =
+ kernel_object_file->GetHeaderAddress().GetFileAddress();
+ if (m_load_address != LLDB_INVALID_ADDRESS &&
+ file_address != LLDB_INVALID_ADDRESS) {
+ s->Printf("Kernel slid 0x%" PRIx64 " in memory.\n",
+ m_load_address - file_address);
+ }
+ }
+ {
+ s->Printf("Loaded kernel file %s\n",
+ m_module_sp->GetFileSpec().GetPath().c_str());
+ }
+ s->Flush();
+ }
+ }
+ return is_loaded;
+}
+
+uint32_t DynamicLoaderDarwinKernel::KextImageInfo::GetAddressByteSize() {
+ if (m_memory_module_sp)
+ return m_memory_module_sp->GetArchitecture().GetAddressByteSize();
+ if (m_module_sp)
+ return m_module_sp->GetArchitecture().GetAddressByteSize();
+ return 0;
+}
+
+lldb::ByteOrder DynamicLoaderDarwinKernel::KextImageInfo::GetByteOrder() {
+ if (m_memory_module_sp)
+ return m_memory_module_sp->GetArchitecture().GetByteOrder();
+ if (m_module_sp)
+ return m_module_sp->GetArchitecture().GetByteOrder();
+ return endian::InlHostByteOrder();
}
lldb_private::ArchSpec
-DynamicLoaderDarwinKernel::KextImageInfo::GetArchitecture () const
-{
- if (m_memory_module_sp)
- return m_memory_module_sp->GetArchitecture();
- if (m_module_sp)
- return m_module_sp->GetArchitecture();
- return lldb_private::ArchSpec ();
+DynamicLoaderDarwinKernel::KextImageInfo::GetArchitecture() const {
+ if (m_memory_module_sp)
+ return m_memory_module_sp->GetArchitecture();
+ if (m_module_sp)
+ return m_module_sp->GetArchitecture();
+ return lldb_private::ArchSpec();
}
-
//----------------------------------------------------------------------
// Load the kernel module and initialize the "m_kernel" member. Return
// true _only_ if the kernel is loaded the first time through (subsequent
// calls to this function should return false after the kernel has been
// already loaded).
//----------------------------------------------------------------------
-void
-DynamicLoaderDarwinKernel::LoadKernelModuleIfNeeded()
-{
- if (!m_kext_summary_header_ptr_addr.IsValid())
- {
- m_kernel.Clear();
- m_kernel.SetModule (m_process->GetTarget().GetExecutableModule());
- m_kernel.SetIsKernel(true);
-
- ConstString kernel_name("mach_kernel");
- if (m_kernel.GetModule().get()
- && m_kernel.GetModule()->GetObjectFile()
- && !m_kernel.GetModule()->GetObjectFile()->GetFileSpec().GetFilename().IsEmpty())
- {
- kernel_name = m_kernel.GetModule()->GetObjectFile()->GetFileSpec().GetFilename();
- }
- m_kernel.SetName (kernel_name.AsCString());
-
- if (m_kernel.GetLoadAddress() == LLDB_INVALID_ADDRESS)
- {
- m_kernel.SetLoadAddress(m_kernel_load_address);
- if (m_kernel.GetLoadAddress() == LLDB_INVALID_ADDRESS && m_kernel.GetModule())
- {
- // We didn't get a hint from the process, so we will
- // try the kernel at the address that it exists at in
- // the file if we have one
- ObjectFile *kernel_object_file = m_kernel.GetModule()->GetObjectFile();
- if (kernel_object_file)
- {
- addr_t load_address = kernel_object_file->GetHeaderAddress().GetLoadAddress(&m_process->GetTarget());
- addr_t file_address = kernel_object_file->GetHeaderAddress().GetFileAddress();
- if (load_address != LLDB_INVALID_ADDRESS && load_address != 0)
- {
- m_kernel.SetLoadAddress (load_address);
- if (load_address != file_address)
- {
- // Don't accidentally relocate the kernel to the File address --
- // the Load address has already been set to its actual in-memory address.
- // Mark it as IsLoaded.
- m_kernel.SetProcessStopId (m_process->GetStopID());
- }
- }
- else
- {
- m_kernel.SetLoadAddress(file_address);
- }
- }
- }
- }
-
- if (m_kernel.GetLoadAddress() != LLDB_INVALID_ADDRESS)
- {
- if (!m_kernel.LoadImageUsingMemoryModule (m_process))
- {
- m_kernel.LoadImageAtFileAddress (m_process);
- }
- }
+void DynamicLoaderDarwinKernel::LoadKernelModuleIfNeeded() {
+ if (!m_kext_summary_header_ptr_addr.IsValid()) {
+ m_kernel.Clear();
+ m_kernel.SetModule(m_process->GetTarget().GetExecutableModule());
+ m_kernel.SetIsKernel(true);
- if (m_kernel.IsLoaded() && m_kernel.GetModule())
- {
- static ConstString kext_summary_symbol ("gLoadedKextSummaries");
- const Symbol *symbol = m_kernel.GetModule()->FindFirstSymbolWithNameAndType (kext_summary_symbol, eSymbolTypeData);
- if (symbol)
- {
- m_kext_summary_header_ptr_addr = symbol->GetAddress();
- // Update all image infos
- ReadAllKextSummaries ();
- }
- }
- else
- {
- m_kernel.Clear();
- }
+ ConstString kernel_name("mach_kernel");
+ if (m_kernel.GetModule().get() && m_kernel.GetModule()->GetObjectFile() &&
+ !m_kernel.GetModule()
+ ->GetObjectFile()
+ ->GetFileSpec()
+ .GetFilename()
+ .IsEmpty()) {
+ kernel_name =
+ m_kernel.GetModule()->GetObjectFile()->GetFileSpec().GetFilename();
+ }
+ m_kernel.SetName(kernel_name.AsCString());
+
+ if (m_kernel.GetLoadAddress() == LLDB_INVALID_ADDRESS) {
+ m_kernel.SetLoadAddress(m_kernel_load_address);
+ if (m_kernel.GetLoadAddress() == LLDB_INVALID_ADDRESS &&
+ m_kernel.GetModule()) {
+ // We didn't get a hint from the process, so we will
+ // try the kernel at the address that it exists at in
+ // the file if we have one
+ ObjectFile *kernel_object_file = m_kernel.GetModule()->GetObjectFile();
+ if (kernel_object_file) {
+ addr_t load_address =
+ kernel_object_file->GetHeaderAddress().GetLoadAddress(
+ &m_process->GetTarget());
+ addr_t file_address =
+ kernel_object_file->GetHeaderAddress().GetFileAddress();
+ if (load_address != LLDB_INVALID_ADDRESS && load_address != 0) {
+ m_kernel.SetLoadAddress(load_address);
+ if (load_address != file_address) {
+ // Don't accidentally relocate the kernel to the File address --
+ // the Load address has already been set to its actual in-memory
+ // address.
+ // Mark it as IsLoaded.
+ m_kernel.SetProcessStopId(m_process->GetStopID());
+ }
+ } else {
+ m_kernel.SetLoadAddress(file_address);
+ }
+ }
+ }
+ }
+
+ if (m_kernel.GetLoadAddress() != LLDB_INVALID_ADDRESS) {
+ if (!m_kernel.LoadImageUsingMemoryModule(m_process)) {
+ m_kernel.LoadImageAtFileAddress(m_process);
+ }
+ }
+
+ if (m_kernel.IsLoaded() && m_kernel.GetModule()) {
+ static ConstString kext_summary_symbol("gLoadedKextSummaries");
+ const Symbol *symbol =
+ m_kernel.GetModule()->FindFirstSymbolWithNameAndType(
+ kext_summary_symbol, eSymbolTypeData);
+ if (symbol) {
+ m_kext_summary_header_ptr_addr = symbol->GetAddress();
+ // Update all image infos
+ ReadAllKextSummaries();
+ }
+ } else {
+ m_kernel.Clear();
}
+ }
}
//----------------------------------------------------------------------
@@ -1105,591 +1012,531 @@ DynamicLoaderDarwinKernel::LoadKernelMod
// let our super class DynamicLoader class decide if we should stop
// or not (based on global preference).
//----------------------------------------------------------------------
-bool
-DynamicLoaderDarwinKernel::BreakpointHitCallback (void *baton,
- StoppointCallbackContext *context,
- user_id_t break_id,
- user_id_t break_loc_id)
-{
- return static_cast<DynamicLoaderDarwinKernel*>(baton)->BreakpointHit (context, break_id, break_loc_id);
+bool DynamicLoaderDarwinKernel::BreakpointHitCallback(
+ void *baton, StoppointCallbackContext *context, user_id_t break_id,
+ user_id_t break_loc_id) {
+ return static_cast<DynamicLoaderDarwinKernel *>(baton)->BreakpointHit(
+ context, break_id, break_loc_id);
}
-bool
-DynamicLoaderDarwinKernel::BreakpointHit (StoppointCallbackContext *context,
- user_id_t break_id,
- user_id_t break_loc_id)
-{
- Log *log(GetLogIfAnyCategoriesSet (LIBLLDB_LOG_DYNAMIC_LOADER));
- if (log)
- log->Printf ("DynamicLoaderDarwinKernel::BreakpointHit (...)\n");
+bool DynamicLoaderDarwinKernel::BreakpointHit(StoppointCallbackContext *context,
+ user_id_t break_id,
+ user_id_t break_loc_id) {
+ Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
+ if (log)
+ log->Printf("DynamicLoaderDarwinKernel::BreakpointHit (...)\n");
- ReadAllKextSummaries ();
-
- if (log)
- PutToLog(log);
+ ReadAllKextSummaries();
- return GetStopWhenImagesChange();
+ if (log)
+ PutToLog(log);
+
+ return GetStopWhenImagesChange();
}
+bool DynamicLoaderDarwinKernel::ReadKextSummaryHeader() {
+ std::lock_guard<std::recursive_mutex> guard(m_mutex);
-bool
-DynamicLoaderDarwinKernel::ReadKextSummaryHeader ()
-{
- std::lock_guard<std::recursive_mutex> guard(m_mutex);
-
- // the all image infos is already valid for this process stop ID
-
- if (m_kext_summary_header_ptr_addr.IsValid())
- {
- const uint32_t addr_size = m_kernel.GetAddressByteSize ();
- const ByteOrder byte_order = m_kernel.GetByteOrder();
- Error error;
- // Read enough bytes for a "OSKextLoadedKextSummaryHeader" structure
- // which is currently 4 uint32_t and a pointer.
- uint8_t buf[24];
- DataExtractor data (buf, sizeof(buf), byte_order, addr_size);
- const size_t count = 4 * sizeof(uint32_t) + addr_size;
- const bool prefer_file_cache = false;
- if (m_process->GetTarget().ReadPointerFromMemory (m_kext_summary_header_ptr_addr,
- prefer_file_cache,
- error,
- m_kext_summary_header_addr))
- {
- // We got a valid address for our kext summary header and make sure it isn't NULL
- if (m_kext_summary_header_addr.IsValid() &&
- m_kext_summary_header_addr.GetFileAddress() != 0)
- {
- const size_t bytes_read = m_process->GetTarget().ReadMemory (m_kext_summary_header_addr, prefer_file_cache, buf, count, error);
- if (bytes_read == count)
- {
- lldb::offset_t offset = 0;
- m_kext_summary_header.version = data.GetU32(&offset);
- if (m_kext_summary_header.version > 128)
- {
- Stream *s = m_process->GetTarget().GetDebugger().GetOutputFile().get();
- s->Printf ("WARNING: Unable to read kext summary header, got improbable version number %u\n", m_kext_summary_header.version);
- // If we get an improbably large version number, we're probably getting bad memory.
- m_kext_summary_header_addr.Clear();
- return false;
- }
- if (m_kext_summary_header.version >= 2)
- {
- m_kext_summary_header.entry_size = data.GetU32(&offset);
- if (m_kext_summary_header.entry_size > 4096)
- {
- // If we get an improbably large entry_size, we're probably getting bad memory.
- Stream *s = m_process->GetTarget().GetDebugger().GetOutputFile().get();
- s->Printf ("WARNING: Unable to read kext summary header, got improbable entry_size %u\n", m_kext_summary_header.entry_size);
- m_kext_summary_header_addr.Clear();
- return false;
- }
- }
- else
- {
- // Versions less than 2 didn't have an entry size, it was hard coded
- m_kext_summary_header.entry_size = KERNEL_MODULE_ENTRY_SIZE_VERSION_1;
- }
- m_kext_summary_header.entry_count = data.GetU32(&offset);
- if (m_kext_summary_header.entry_count > 10000)
- {
- // If we get an improbably large number of kexts, we're probably getting bad memory.
- Stream *s = m_process->GetTarget().GetDebugger().GetOutputFile().get();
- s->Printf ("WARNING: Unable to read kext summary header, got improbable number of kexts %u\n", m_kext_summary_header.entry_count);
- m_kext_summary_header_addr.Clear();
- return false;
- }
- return true;
- }
- }
+ // the all image infos is already valid for this process stop ID
+
+ if (m_kext_summary_header_ptr_addr.IsValid()) {
+ const uint32_t addr_size = m_kernel.GetAddressByteSize();
+ const ByteOrder byte_order = m_kernel.GetByteOrder();
+ Error error;
+ // Read enough bytes for a "OSKextLoadedKextSummaryHeader" structure
+ // which is currently 4 uint32_t and a pointer.
+ uint8_t buf[24];
+ DataExtractor data(buf, sizeof(buf), byte_order, addr_size);
+ const size_t count = 4 * sizeof(uint32_t) + addr_size;
+ const bool prefer_file_cache = false;
+ if (m_process->GetTarget().ReadPointerFromMemory(
+ m_kext_summary_header_ptr_addr, prefer_file_cache, error,
+ m_kext_summary_header_addr)) {
+ // We got a valid address for our kext summary header and make sure it
+ // isn't NULL
+ if (m_kext_summary_header_addr.IsValid() &&
+ m_kext_summary_header_addr.GetFileAddress() != 0) {
+ const size_t bytes_read = m_process->GetTarget().ReadMemory(
+ m_kext_summary_header_addr, prefer_file_cache, buf, count, error);
+ if (bytes_read == count) {
+ lldb::offset_t offset = 0;
+ m_kext_summary_header.version = data.GetU32(&offset);
+ if (m_kext_summary_header.version > 128) {
+ Stream *s =
+ m_process->GetTarget().GetDebugger().GetOutputFile().get();
+ s->Printf("WARNING: Unable to read kext summary header, got "
+ "improbable version number %u\n",
+ m_kext_summary_header.version);
+ // If we get an improbably large version number, we're probably
+ // getting bad memory.
+ m_kext_summary_header_addr.Clear();
+ return false;
+ }
+ if (m_kext_summary_header.version >= 2) {
+ m_kext_summary_header.entry_size = data.GetU32(&offset);
+ if (m_kext_summary_header.entry_size > 4096) {
+ // If we get an improbably large entry_size, we're probably
+ // getting bad memory.
+ Stream *s =
+ m_process->GetTarget().GetDebugger().GetOutputFile().get();
+ s->Printf("WARNING: Unable to read kext summary header, got "
+ "improbable entry_size %u\n",
+ m_kext_summary_header.entry_size);
+ m_kext_summary_header_addr.Clear();
+ return false;
+ }
+ } else {
+ // Versions less than 2 didn't have an entry size, it was hard coded
+ m_kext_summary_header.entry_size =
+ KERNEL_MODULE_ENTRY_SIZE_VERSION_1;
+ }
+ m_kext_summary_header.entry_count = data.GetU32(&offset);
+ if (m_kext_summary_header.entry_count > 10000) {
+ // If we get an improbably large number of kexts, we're probably
+ // getting bad memory.
+ Stream *s =
+ m_process->GetTarget().GetDebugger().GetOutputFile().get();
+ s->Printf("WARNING: Unable to read kext summary header, got "
+ "improbable number of kexts %u\n",
+ m_kext_summary_header.entry_count);
+ m_kext_summary_header_addr.Clear();
+ return false;
+ }
+ return true;
}
+ }
}
- m_kext_summary_header_addr.Clear();
- return false;
+ }
+ m_kext_summary_header_addr.Clear();
+ return false;
}
-// We've either (a) just attached to a new kernel, or (b) the kexts-changed breakpoint was hit
+// We've either (a) just attached to a new kernel, or (b) the kexts-changed
+// breakpoint was hit
// and we need to figure out what kexts have been added or removed.
-// Read the kext summaries from the inferior kernel memory, compare them against the
-// m_known_kexts vector and update the m_known_kexts vector as needed to keep in sync with the
+// Read the kext summaries from the inferior kernel memory, compare them against
+// the
+// m_known_kexts vector and update the m_known_kexts vector as needed to keep in
+// sync with the
// inferior.
-bool
-DynamicLoaderDarwinKernel::ParseKextSummaries (const Address &kext_summary_addr, uint32_t count)
-{
- KextImageInfo::collection kext_summaries;
- Log *log(GetLogIfAnyCategoriesSet (LIBLLDB_LOG_DYNAMIC_LOADER));
- if (log)
- log->Printf ("Kexts-changed breakpoint hit, there are %d kexts currently.\n", count);
-
- std::lock_guard<std::recursive_mutex> guard(m_mutex);
-
- if (!ReadKextSummaries (kext_summary_addr, count, kext_summaries))
- return false;
-
- // read the plugin.dynamic-loader.darwin-kernel.load-kexts setting -- if the user requested no
- // kext loading, don't print any messages about kexts & don't try to read them.
- const bool load_kexts = GetGlobalProperties()->GetLoadKexts();
-
- // By default, all kexts we've loaded in the past are marked as "remove" and all of the kexts
- // we just found out about from ReadKextSummaries are marked as "add".
- std::vector<bool> to_be_removed(m_known_kexts.size(), true);
- std::vector<bool> to_be_added(count, true);
-
- int number_of_new_kexts_being_added = 0;
- int number_of_old_kexts_being_removed = m_known_kexts.size();
-
- const uint32_t new_kexts_size = kext_summaries.size();
- const uint32_t old_kexts_size = m_known_kexts.size();
-
- // The m_known_kexts vector may have entries that have been Cleared,
- // or are a kernel.
- for (uint32_t old_kext = 0; old_kext < old_kexts_size; old_kext++)
- {
- bool ignore = false;
- KextImageInfo &image_info = m_known_kexts[old_kext];
- if (image_info.IsKernel())
- {
- ignore = true;
- }
- else if (image_info.GetLoadAddress() == LLDB_INVALID_ADDRESS && !image_info.GetModule())
- {
- ignore = true;
- }
-
- if (ignore)
- {
- number_of_old_kexts_being_removed--;
- to_be_removed[old_kext] = false;
- }
- }
-
- // Scan over the list of kexts we just read from the kernel, note those that
- // need to be added and those already loaded.
- for (uint32_t new_kext = 0; new_kext < new_kexts_size; new_kext++)
- {
- bool add_this_one = true;
- for (uint32_t old_kext = 0; old_kext < old_kexts_size; old_kext++)
- {
- if (m_known_kexts[old_kext] == kext_summaries[new_kext])
- {
- // We already have this kext, don't re-load it.
- to_be_added[new_kext] = false;
- // This kext is still present, do not remove it.
- to_be_removed[old_kext] = false;
-
- number_of_old_kexts_being_removed--;
- add_this_one = false;
- break;
- }
- }
- if (add_this_one)
- {
- number_of_new_kexts_being_added++;
- }
- }
-
- if (number_of_new_kexts_being_added == 0 && number_of_old_kexts_being_removed == 0)
- return true;
-
- Stream *s = m_process->GetTarget().GetDebugger().GetOutputFile().get();
- if (s && load_kexts)
- {
- if (number_of_new_kexts_being_added > 0 && number_of_old_kexts_being_removed > 0)
- {
- s->Printf ("Loading %d kext modules and unloading %d kext modules ", number_of_new_kexts_being_added, number_of_old_kexts_being_removed);
- }
- else if (number_of_new_kexts_being_added > 0)
- {
- s->Printf ("Loading %d kext modules ", number_of_new_kexts_being_added);
- }
- else if (number_of_old_kexts_being_removed > 0)
- {
- s->Printf ("Unloading %d kext modules ", number_of_old_kexts_being_removed);
- }
- }
+bool DynamicLoaderDarwinKernel::ParseKextSummaries(
+ const Address &kext_summary_addr, uint32_t count) {
+ KextImageInfo::collection kext_summaries;
+ Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
+ if (log)
+ log->Printf("Kexts-changed breakpoint hit, there are %d kexts currently.\n",
+ count);
- if (log)
- {
- if (load_kexts)
- {
- log->Printf ("DynamicLoaderDarwinKernel::ParseKextSummaries: %d kexts added, %d kexts removed", number_of_new_kexts_being_added, number_of_old_kexts_being_removed);
- }
- else
- {
- log->Printf ("DynamicLoaderDarwinKernel::ParseKextSummaries kext loading is disabled, else would have %d kexts added, %d kexts removed", number_of_new_kexts_being_added, number_of_old_kexts_being_removed);
- }
- }
+ std::lock_guard<std::recursive_mutex> guard(m_mutex);
+ if (!ReadKextSummaries(kext_summary_addr, count, kext_summaries))
+ return false;
- if (number_of_new_kexts_being_added > 0)
- {
- ModuleList loaded_module_list;
-
- const uint32_t num_of_new_kexts = kext_summaries.size();
- for (uint32_t new_kext = 0; new_kext < num_of_new_kexts; new_kext++)
- {
- if (to_be_added[new_kext] == true)
- {
- KextImageInfo &image_info = kext_summaries[new_kext];
- if (load_kexts)
- {
- if (!image_info.LoadImageUsingMemoryModule (m_process))
- {
- image_info.LoadImageAtFileAddress (m_process);
- }
- }
-
- m_known_kexts.push_back(image_info);
-
- if (image_info.GetModule() && m_process->GetStopID() == image_info.GetProcessStopId())
- loaded_module_list.AppendIfNeeded (image_info.GetModule());
-
- if (s && load_kexts)
- s->Printf (".");
-
- if (log)
- kext_summaries[new_kext].PutToLog (log);
- }
- }
- m_process->GetTarget().ModulesDidLoad (loaded_module_list);
- }
+ // read the plugin.dynamic-loader.darwin-kernel.load-kexts setting -- if the
+ // user requested no
+ // kext loading, don't print any messages about kexts & don't try to read
+ // them.
+ const bool load_kexts = GetGlobalProperties()->GetLoadKexts();
+
+ // By default, all kexts we've loaded in the past are marked as "remove" and
+ // all of the kexts
+ // we just found out about from ReadKextSummaries are marked as "add".
+ std::vector<bool> to_be_removed(m_known_kexts.size(), true);
+ std::vector<bool> to_be_added(count, true);
+
+ int number_of_new_kexts_being_added = 0;
+ int number_of_old_kexts_being_removed = m_known_kexts.size();
+
+ const uint32_t new_kexts_size = kext_summaries.size();
+ const uint32_t old_kexts_size = m_known_kexts.size();
+
+ // The m_known_kexts vector may have entries that have been Cleared,
+ // or are a kernel.
+ for (uint32_t old_kext = 0; old_kext < old_kexts_size; old_kext++) {
+ bool ignore = false;
+ KextImageInfo &image_info = m_known_kexts[old_kext];
+ if (image_info.IsKernel()) {
+ ignore = true;
+ } else if (image_info.GetLoadAddress() == LLDB_INVALID_ADDRESS &&
+ !image_info.GetModule()) {
+ ignore = true;
+ }
+
+ if (ignore) {
+ number_of_old_kexts_being_removed--;
+ to_be_removed[old_kext] = false;
+ }
+ }
+
+ // Scan over the list of kexts we just read from the kernel, note those that
+ // need to be added and those already loaded.
+ for (uint32_t new_kext = 0; new_kext < new_kexts_size; new_kext++) {
+ bool add_this_one = true;
+ for (uint32_t old_kext = 0; old_kext < old_kexts_size; old_kext++) {
+ if (m_known_kexts[old_kext] == kext_summaries[new_kext]) {
+ // We already have this kext, don't re-load it.
+ to_be_added[new_kext] = false;
+ // This kext is still present, do not remove it.
+ to_be_removed[old_kext] = false;
- if (number_of_old_kexts_being_removed > 0)
- {
- ModuleList loaded_module_list;
- const uint32_t num_of_old_kexts = m_known_kexts.size();
- for (uint32_t old_kext = 0; old_kext < num_of_old_kexts; old_kext++)
- {
- ModuleList unloaded_module_list;
- if (to_be_removed[old_kext])
- {
- KextImageInfo &image_info = m_known_kexts[old_kext];
- // You can't unload the kernel.
- if (!image_info.IsKernel())
- {
- if (image_info.GetModule())
- {
- unloaded_module_list.AppendIfNeeded (image_info.GetModule());
- }
- if (s)
- s->Printf (".");
- image_info.Clear();
- // should pull it out of the KextImageInfos vector but that would mutate the list and invalidate
- // the to_be_removed bool vector; leaving it in place once Cleared() is relatively harmless.
- }
- }
- m_process->GetTarget().ModulesDidUnload (unloaded_module_list, false);
- }
+ number_of_old_kexts_being_removed--;
+ add_this_one = false;
+ break;
+ }
}
-
- if (s && load_kexts)
- {
- s->Printf (" done.\n");
- s->Flush ();
+ if (add_this_one) {
+ number_of_new_kexts_being_added++;
}
+ }
+ if (number_of_new_kexts_being_added == 0 &&
+ number_of_old_kexts_being_removed == 0)
return true;
-}
-uint32_t
-DynamicLoaderDarwinKernel::ReadKextSummaries (const Address &kext_summary_addr,
- uint32_t image_infos_count,
- KextImageInfo::collection &image_infos)
-{
- const ByteOrder endian = m_kernel.GetByteOrder();
- const uint32_t addr_size = m_kernel.GetAddressByteSize();
+ Stream *s = m_process->GetTarget().GetDebugger().GetOutputFile().get();
+ if (s && load_kexts) {
+ if (number_of_new_kexts_being_added > 0 &&
+ number_of_old_kexts_being_removed > 0) {
+ s->Printf("Loading %d kext modules and unloading %d kext modules ",
+ number_of_new_kexts_being_added,
+ number_of_old_kexts_being_removed);
+ } else if (number_of_new_kexts_being_added > 0) {
+ s->Printf("Loading %d kext modules ", number_of_new_kexts_being_added);
+ } else if (number_of_old_kexts_being_removed > 0) {
+ s->Printf("Unloading %d kext modules ",
+ number_of_old_kexts_being_removed);
+ }
+ }
+
+ if (log) {
+ if (load_kexts) {
+ log->Printf("DynamicLoaderDarwinKernel::ParseKextSummaries: %d kexts "
+ "added, %d kexts removed",
+ number_of_new_kexts_being_added,
+ number_of_old_kexts_being_removed);
+ } else {
+ log->Printf(
+ "DynamicLoaderDarwinKernel::ParseKextSummaries kext loading is "
+ "disabled, else would have %d kexts added, %d kexts removed",
+ number_of_new_kexts_being_added, number_of_old_kexts_being_removed);
+ }
+ }
+
+ if (number_of_new_kexts_being_added > 0) {
+ ModuleList loaded_module_list;
+
+ const uint32_t num_of_new_kexts = kext_summaries.size();
+ for (uint32_t new_kext = 0; new_kext < num_of_new_kexts; new_kext++) {
+ if (to_be_added[new_kext] == true) {
+ KextImageInfo &image_info = kext_summaries[new_kext];
+ if (load_kexts) {
+ if (!image_info.LoadImageUsingMemoryModule(m_process)) {
+ image_info.LoadImageAtFileAddress(m_process);
+ }
+ }
+
+ m_known_kexts.push_back(image_info);
+
+ if (image_info.GetModule() &&
+ m_process->GetStopID() == image_info.GetProcessStopId())
+ loaded_module_list.AppendIfNeeded(image_info.GetModule());
- image_infos.resize(image_infos_count);
- const size_t count = image_infos.size() * m_kext_summary_header.entry_size;
- DataBufferHeap data(count, 0);
- Error error;
-
- const bool prefer_file_cache = false;
- const size_t bytes_read = m_process->GetTarget().ReadMemory (kext_summary_addr,
- prefer_file_cache,
- data.GetBytes(),
- data.GetByteSize(),
- error);
- if (bytes_read == count)
- {
-
- DataExtractor extractor (data.GetBytes(), data.GetByteSize(), endian, addr_size);
- uint32_t i=0;
- for (uint32_t kext_summary_offset = 0;
- i < image_infos.size() && extractor.ValidOffsetForDataOfSize(kext_summary_offset, m_kext_summary_header.entry_size);
- ++i, kext_summary_offset += m_kext_summary_header.entry_size)
- {
- lldb::offset_t offset = kext_summary_offset;
- const void *name_data = extractor.GetData(&offset, KERNEL_MODULE_MAX_NAME);
- if (name_data == NULL)
- break;
- image_infos[i].SetName ((const char *) name_data);
- UUID uuid (extractor.GetData (&offset, 16), 16);
- image_infos[i].SetUUID (uuid);
- image_infos[i].SetLoadAddress (extractor.GetU64(&offset));
- image_infos[i].SetSize (extractor.GetU64(&offset));
- }
- if (i < image_infos.size())
- image_infos.resize(i);
- }
- else
- {
- image_infos.clear();
+ if (s && load_kexts)
+ s->Printf(".");
+
+ if (log)
+ kext_summaries[new_kext].PutToLog(log);
+ }
}
- return image_infos.size();
-}
+ m_process->GetTarget().ModulesDidLoad(loaded_module_list);
+ }
-bool
-DynamicLoaderDarwinKernel::ReadAllKextSummaries ()
-{
- std::lock_guard<std::recursive_mutex> guard(m_mutex);
-
- if (ReadKextSummaryHeader ())
- {
- if (m_kext_summary_header.entry_count > 0 && m_kext_summary_header_addr.IsValid())
- {
- Address summary_addr (m_kext_summary_header_addr);
- summary_addr.Slide(m_kext_summary_header.GetSize());
- if (!ParseKextSummaries (summary_addr, m_kext_summary_header.entry_count))
- {
- m_known_kexts.clear();
- }
- return true;
- }
+ if (number_of_old_kexts_being_removed > 0) {
+ ModuleList loaded_module_list;
+ const uint32_t num_of_old_kexts = m_known_kexts.size();
+ for (uint32_t old_kext = 0; old_kext < num_of_old_kexts; old_kext++) {
+ ModuleList unloaded_module_list;
+ if (to_be_removed[old_kext]) {
+ KextImageInfo &image_info = m_known_kexts[old_kext];
+ // You can't unload the kernel.
+ if (!image_info.IsKernel()) {
+ if (image_info.GetModule()) {
+ unloaded_module_list.AppendIfNeeded(image_info.GetModule());
+ }
+ if (s)
+ s->Printf(".");
+ image_info.Clear();
+ // should pull it out of the KextImageInfos vector but that would
+ // mutate the list and invalidate
+ // the to_be_removed bool vector; leaving it in place once Cleared()
+ // is relatively harmless.
+ }
+ }
+ m_process->GetTarget().ModulesDidUnload(unloaded_module_list, false);
+ }
+ }
+
+ if (s && load_kexts) {
+ s->Printf(" done.\n");
+ s->Flush();
+ }
+
+ return true;
+}
+
+uint32_t DynamicLoaderDarwinKernel::ReadKextSummaries(
+ const Address &kext_summary_addr, uint32_t image_infos_count,
+ KextImageInfo::collection &image_infos) {
+ const ByteOrder endian = m_kernel.GetByteOrder();
+ const uint32_t addr_size = m_kernel.GetAddressByteSize();
+
+ image_infos.resize(image_infos_count);
+ const size_t count = image_infos.size() * m_kext_summary_header.entry_size;
+ DataBufferHeap data(count, 0);
+ Error error;
+
+ const bool prefer_file_cache = false;
+ const size_t bytes_read = m_process->GetTarget().ReadMemory(
+ kext_summary_addr, prefer_file_cache, data.GetBytes(), data.GetByteSize(),
+ error);
+ if (bytes_read == count) {
+
+ DataExtractor extractor(data.GetBytes(), data.GetByteSize(), endian,
+ addr_size);
+ uint32_t i = 0;
+ for (uint32_t kext_summary_offset = 0;
+ i < image_infos.size() &&
+ extractor.ValidOffsetForDataOfSize(kext_summary_offset,
+ m_kext_summary_header.entry_size);
+ ++i, kext_summary_offset += m_kext_summary_header.entry_size) {
+ lldb::offset_t offset = kext_summary_offset;
+ const void *name_data =
+ extractor.GetData(&offset, KERNEL_MODULE_MAX_NAME);
+ if (name_data == NULL)
+ break;
+ image_infos[i].SetName((const char *)name_data);
+ UUID uuid(extractor.GetData(&offset, 16), 16);
+ image_infos[i].SetUUID(uuid);
+ image_infos[i].SetLoadAddress(extractor.GetU64(&offset));
+ image_infos[i].SetSize(extractor.GetU64(&offset));
+ }
+ if (i < image_infos.size())
+ image_infos.resize(i);
+ } else {
+ image_infos.clear();
+ }
+ return image_infos.size();
+}
+
+bool DynamicLoaderDarwinKernel::ReadAllKextSummaries() {
+ std::lock_guard<std::recursive_mutex> guard(m_mutex);
+
+ if (ReadKextSummaryHeader()) {
+ if (m_kext_summary_header.entry_count > 0 &&
+ m_kext_summary_header_addr.IsValid()) {
+ Address summary_addr(m_kext_summary_header_addr);
+ summary_addr.Slide(m_kext_summary_header.GetSize());
+ if (!ParseKextSummaries(summary_addr,
+ m_kext_summary_header.entry_count)) {
+ m_known_kexts.clear();
+ }
+ return true;
}
- return false;
+ }
+ return false;
}
//----------------------------------------------------------------------
// Dump an image info structure to the file handle provided.
//----------------------------------------------------------------------
-void
-DynamicLoaderDarwinKernel::KextImageInfo::PutToLog (Log *log) const
-{
- if (log == NULL)
- return;
- const uint8_t *u = (uint8_t *) m_uuid.GetBytes();
-
- if (m_load_address == LLDB_INVALID_ADDRESS)
- {
- if (u)
- {
- log->Printf("\tuuid=%2.2X%2.2X%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X%2.2X%2.2X%2.2X%2.2X name=\"%s\" (UNLOADED)",
- u[ 0], u[ 1], u[ 2], u[ 3],
- u[ 4], u[ 5], u[ 6], u[ 7],
- u[ 8], u[ 9], u[10], u[11],
- u[12], u[13], u[14], u[15],
- m_name.c_str());
- }
- else
- log->Printf("\tname=\"%s\" (UNLOADED)", m_name.c_str());
- }
- else
- {
- if (u)
- {
- log->Printf("\taddr=0x%16.16" PRIx64 " size=0x%16.16" PRIx64 " uuid=%2.2X%2.2X%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X%2.2X%2.2X%2.2X%2.2X name=\"%s\"",
- m_load_address, m_size,
- u[ 0], u[ 1], u[ 2], u[ 3], u[ 4], u[ 5], u[ 6], u[ 7],
- u[ 8], u[ 9], u[10], u[11], u[12], u[13], u[14], u[15],
- m_name.c_str());
- }
- else
- {
- log->Printf("\t[0x%16.16" PRIx64 " - 0x%16.16" PRIx64 ") name=\"%s\"",
- m_load_address, m_load_address+m_size, m_name.c_str());
- }
+void DynamicLoaderDarwinKernel::KextImageInfo::PutToLog(Log *log) const {
+ if (log == NULL)
+ return;
+ const uint8_t *u = (uint8_t *)m_uuid.GetBytes();
+
+ if (m_load_address == LLDB_INVALID_ADDRESS) {
+ if (u) {
+ log->Printf("\tuuid=%2.2X%2.2X%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2."
+ "2X-%2.2X%2.2X%2.2X%2.2X%2.2X%2.2X name=\"%s\" (UNLOADED)",
+ u[0], u[1], u[2], u[3], u[4], u[5], u[6], u[7], u[8], u[9],
+ u[10], u[11], u[12], u[13], u[14], u[15], m_name.c_str());
+ } else
+ log->Printf("\tname=\"%s\" (UNLOADED)", m_name.c_str());
+ } else {
+ if (u) {
+ log->Printf("\taddr=0x%16.16" PRIx64 " size=0x%16.16" PRIx64
+ " uuid=%2.2X%2.2X%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-"
+ "%2.2X%2.2X%2.2X%2.2X%2.2X%2.2X name=\"%s\"",
+ m_load_address, m_size, u[0], u[1], u[2], u[3], u[4], u[5],
+ u[6], u[7], u[8], u[9], u[10], u[11], u[12], u[13], u[14],
+ u[15], m_name.c_str());
+ } else {
+ log->Printf("\t[0x%16.16" PRIx64 " - 0x%16.16" PRIx64 ") name=\"%s\"",
+ m_load_address, m_load_address + m_size, m_name.c_str());
}
+ }
}
//----------------------------------------------------------------------
// Dump the _dyld_all_image_infos members and all current image infos
// that we have parsed to the file handle provided.
//----------------------------------------------------------------------
-void
-DynamicLoaderDarwinKernel::PutToLog(Log *log) const
-{
- if (log == NULL)
- return;
-
- std::lock_guard<std::recursive_mutex> guard(m_mutex);
- log->Printf("gLoadedKextSummaries = 0x%16.16" PRIx64 " { version=%u, entry_size=%u, entry_count=%u }",
- m_kext_summary_header_addr.GetFileAddress(),
- m_kext_summary_header.version,
- m_kext_summary_header.entry_size,
- m_kext_summary_header.entry_count);
-
- size_t i;
- const size_t count = m_known_kexts.size();
- if (count > 0)
- {
- log->PutCString("Loaded:");
- for (i = 0; i<count; i++)
- m_known_kexts[i].PutToLog(log);
- }
-}
-
-void
-DynamicLoaderDarwinKernel::PrivateInitialize(Process *process)
-{
- DEBUG_PRINTF("DynamicLoaderDarwinKernel::%s() process state = %s\n", __FUNCTION__, StateAsCString(m_process->GetState()));
- Clear(true);
- m_process = process;
-}
-
-void
-DynamicLoaderDarwinKernel::SetNotificationBreakpointIfNeeded ()
-{
- if (m_break_id == LLDB_INVALID_BREAK_ID && m_kernel.GetModule())
- {
- DEBUG_PRINTF("DynamicLoaderDarwinKernel::%s() process state = %s\n", __FUNCTION__, StateAsCString(m_process->GetState()));
-
-
- const bool internal_bp = true;
- const bool hardware = false;
- const LazyBool skip_prologue = eLazyBoolNo;
- FileSpecList module_spec_list;
- module_spec_list.Append (m_kernel.GetModule()->GetFileSpec());
- Breakpoint *bp = m_process->GetTarget().CreateBreakpoint (&module_spec_list,
- NULL,
- "OSKextLoadedKextSummariesUpdated",
- eFunctionNameTypeFull,
- eLanguageTypeUnknown,
- 0,
- skip_prologue,
- internal_bp,
- hardware).get();
-
- bp->SetCallback (DynamicLoaderDarwinKernel::BreakpointHitCallback, this, true);
- m_break_id = bp->GetID();
- }
+void DynamicLoaderDarwinKernel::PutToLog(Log *log) const {
+ if (log == NULL)
+ return;
+
+ std::lock_guard<std::recursive_mutex> guard(m_mutex);
+ log->Printf("gLoadedKextSummaries = 0x%16.16" PRIx64
+ " { version=%u, entry_size=%u, entry_count=%u }",
+ m_kext_summary_header_addr.GetFileAddress(),
+ m_kext_summary_header.version, m_kext_summary_header.entry_size,
+ m_kext_summary_header.entry_count);
+
+ size_t i;
+ const size_t count = m_known_kexts.size();
+ if (count > 0) {
+ log->PutCString("Loaded:");
+ for (i = 0; i < count; i++)
+ m_known_kexts[i].PutToLog(log);
+ }
+}
+
+void DynamicLoaderDarwinKernel::PrivateInitialize(Process *process) {
+ DEBUG_PRINTF("DynamicLoaderDarwinKernel::%s() process state = %s\n",
+ __FUNCTION__, StateAsCString(m_process->GetState()));
+ Clear(true);
+ m_process = process;
+}
+
+void DynamicLoaderDarwinKernel::SetNotificationBreakpointIfNeeded() {
+ if (m_break_id == LLDB_INVALID_BREAK_ID && m_kernel.GetModule()) {
+ DEBUG_PRINTF("DynamicLoaderDarwinKernel::%s() process state = %s\n",
+ __FUNCTION__, StateAsCString(m_process->GetState()));
+
+ const bool internal_bp = true;
+ const bool hardware = false;
+ const LazyBool skip_prologue = eLazyBoolNo;
+ FileSpecList module_spec_list;
+ module_spec_list.Append(m_kernel.GetModule()->GetFileSpec());
+ Breakpoint *bp =
+ m_process->GetTarget()
+ .CreateBreakpoint(&module_spec_list, NULL,
+ "OSKextLoadedKextSummariesUpdated",
+ eFunctionNameTypeFull, eLanguageTypeUnknown, 0,
+ skip_prologue, internal_bp, hardware)
+ .get();
+
+ bp->SetCallback(DynamicLoaderDarwinKernel::BreakpointHitCallback, this,
+ true);
+ m_break_id = bp->GetID();
+ }
}
//----------------------------------------------------------------------
// Member function that gets called when the process state changes.
//----------------------------------------------------------------------
-void
-DynamicLoaderDarwinKernel::PrivateProcessStateChanged (Process *process, StateType state)
-{
- DEBUG_PRINTF("DynamicLoaderDarwinKernel::%s(%s)\n", __FUNCTION__, StateAsCString(state));
- switch (state)
- {
- case eStateConnected:
- case eStateAttaching:
- case eStateLaunching:
- case eStateInvalid:
- case eStateUnloaded:
- case eStateExited:
- case eStateDetached:
- Clear(false);
- break;
+void DynamicLoaderDarwinKernel::PrivateProcessStateChanged(Process *process,
+ StateType state) {
+ DEBUG_PRINTF("DynamicLoaderDarwinKernel::%s(%s)\n", __FUNCTION__,
+ StateAsCString(state));
+ switch (state) {
+ case eStateConnected:
+ case eStateAttaching:
+ case eStateLaunching:
+ case eStateInvalid:
+ case eStateUnloaded:
+ case eStateExited:
+ case eStateDetached:
+ Clear(false);
+ break;
- case eStateStopped:
- UpdateIfNeeded();
- break;
+ case eStateStopped:
+ UpdateIfNeeded();
+ break;
- case eStateRunning:
- case eStateStepping:
- case eStateCrashed:
- case eStateSuspended:
- break;
- }
+ case eStateRunning:
+ case eStateStepping:
+ case eStateCrashed:
+ case eStateSuspended:
+ break;
+ }
}
ThreadPlanSP
-DynamicLoaderDarwinKernel::GetStepThroughTrampolinePlan (Thread &thread, bool stop_others)
-{
- ThreadPlanSP thread_plan_sp;
- Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
- if (log)
- log->Printf ("Could not find symbol for step through.");
- return thread_plan_sp;
+DynamicLoaderDarwinKernel::GetStepThroughTrampolinePlan(Thread &thread,
+ bool stop_others) {
+ ThreadPlanSP thread_plan_sp;
+ Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
+ if (log)
+ log->Printf("Could not find symbol for step through.");
+ return thread_plan_sp;
}
-Error
-DynamicLoaderDarwinKernel::CanLoadImage ()
-{
- Error error;
- error.SetErrorString("always unsafe to load or unload shared libraries in the darwin kernel");
- return error;
+Error DynamicLoaderDarwinKernel::CanLoadImage() {
+ Error error;
+ error.SetErrorString(
+ "always unsafe to load or unload shared libraries in the darwin kernel");
+ return error;
}
-void
-DynamicLoaderDarwinKernel::Initialize()
-{
- PluginManager::RegisterPlugin (GetPluginNameStatic(),
- GetPluginDescriptionStatic(),
- CreateInstance,
- DebuggerInitialize);
+void DynamicLoaderDarwinKernel::Initialize() {
+ PluginManager::RegisterPlugin(GetPluginNameStatic(),
+ GetPluginDescriptionStatic(), CreateInstance,
+ DebuggerInitialize);
}
-void
-DynamicLoaderDarwinKernel::Terminate()
-{
- PluginManager::UnregisterPlugin (CreateInstance);
+void DynamicLoaderDarwinKernel::Terminate() {
+ PluginManager::UnregisterPlugin(CreateInstance);
}
-void
-DynamicLoaderDarwinKernel::DebuggerInitialize (lldb_private::Debugger &debugger)
-{
- if (!PluginManager::GetSettingForDynamicLoaderPlugin (debugger, DynamicLoaderDarwinKernelProperties::GetSettingName()))
- {
- const bool is_global_setting = true;
- PluginManager::CreateSettingForDynamicLoaderPlugin (debugger,
- GetGlobalProperties()->GetValueProperties(),
- ConstString ("Properties for the DynamicLoaderDarwinKernel plug-in."),
- is_global_setting);
- }
+void DynamicLoaderDarwinKernel::DebuggerInitialize(
+ lldb_private::Debugger &debugger) {
+ if (!PluginManager::GetSettingForDynamicLoaderPlugin(
+ debugger, DynamicLoaderDarwinKernelProperties::GetSettingName())) {
+ const bool is_global_setting = true;
+ PluginManager::CreateSettingForDynamicLoaderPlugin(
+ debugger, GetGlobalProperties()->GetValueProperties(),
+ ConstString("Properties for the DynamicLoaderDarwinKernel plug-in."),
+ is_global_setting);
+ }
}
-lldb_private::ConstString
-DynamicLoaderDarwinKernel::GetPluginNameStatic()
-{
- static ConstString g_name("darwin-kernel");
- return g_name;
+lldb_private::ConstString DynamicLoaderDarwinKernel::GetPluginNameStatic() {
+ static ConstString g_name("darwin-kernel");
+ return g_name;
}
-const char *
-DynamicLoaderDarwinKernel::GetPluginDescriptionStatic()
-{
- return "Dynamic loader plug-in that watches for shared library loads/unloads in the MacOSX kernel.";
+const char *DynamicLoaderDarwinKernel::GetPluginDescriptionStatic() {
+ return "Dynamic loader plug-in that watches for shared library loads/unloads "
+ "in the MacOSX kernel.";
}
-
//------------------------------------------------------------------
// PluginInterface protocol
//------------------------------------------------------------------
-lldb_private::ConstString
-DynamicLoaderDarwinKernel::GetPluginName()
-{
- return GetPluginNameStatic();
+lldb_private::ConstString DynamicLoaderDarwinKernel::GetPluginName() {
+ return GetPluginNameStatic();
}
-uint32_t
-DynamicLoaderDarwinKernel::GetPluginVersion()
-{
- return 1;
-}
+uint32_t DynamicLoaderDarwinKernel::GetPluginVersion() { return 1; }
lldb::ByteOrder
-DynamicLoaderDarwinKernel::GetByteOrderFromMagic (uint32_t magic)
-{
- switch (magic)
- {
- case llvm::MachO::MH_MAGIC:
- case llvm::MachO::MH_MAGIC_64:
- return endian::InlHostByteOrder();
-
- case llvm::MachO::MH_CIGAM:
- case llvm::MachO::MH_CIGAM_64:
- if (endian::InlHostByteOrder() == lldb::eByteOrderBig)
- return lldb::eByteOrderLittle;
- else
- return lldb::eByteOrderBig;
-
- default:
- break;
- }
- return lldb::eByteOrderInvalid;
-}
+DynamicLoaderDarwinKernel::GetByteOrderFromMagic(uint32_t magic) {
+ switch (magic) {
+ case llvm::MachO::MH_MAGIC:
+ case llvm::MachO::MH_MAGIC_64:
+ return endian::InlHostByteOrder();
+ case llvm::MachO::MH_CIGAM:
+ case llvm::MachO::MH_CIGAM_64:
+ if (endian::InlHostByteOrder() == lldb::eByteOrderBig)
+ return lldb::eByteOrderLittle;
+ else
+ return lldb::eByteOrderBig;
+
+ default:
+ break;
+ }
+ return lldb::eByteOrderInvalid;
+}
Modified: lldb/trunk/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.h (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.h Tue Sep 6 15:57:50 2016
@@ -18,354 +18,289 @@
// Other libraries and framework includes
// Project includes
-#include "lldb/Target/DynamicLoader.h"
+#include "lldb/Core/UUID.h"
#include "lldb/Host/FileSpec.h"
#include "lldb/Host/TimeValue.h"
-#include "lldb/Core/UUID.h"
+#include "lldb/Target/DynamicLoader.h"
#include "lldb/Target/Process.h"
-class DynamicLoaderDarwinKernel : public lldb_private::DynamicLoader
-{
+class DynamicLoaderDarwinKernel : public lldb_private::DynamicLoader {
public:
- DynamicLoaderDarwinKernel(lldb_private::Process *process, lldb::addr_t kernel_addr);
+ DynamicLoaderDarwinKernel(lldb_private::Process *process,
+ lldb::addr_t kernel_addr);
- ~DynamicLoaderDarwinKernel() override;
+ ~DynamicLoaderDarwinKernel() override;
- //------------------------------------------------------------------
- // Static Functions
- //------------------------------------------------------------------
- static void
- Initialize();
-
- static void
- Terminate();
-
- static lldb_private::ConstString
- GetPluginNameStatic();
-
- static const char *
- GetPluginDescriptionStatic();
-
- static lldb_private::DynamicLoader *
- CreateInstance (lldb_private::Process *process, bool force);
-
- static void
- DebuggerInitialize (lldb_private::Debugger &debugger);
-
- static lldb::addr_t
- SearchForDarwinKernel (lldb_private::Process *process);
-
- //------------------------------------------------------------------
- /// Called after attaching a process.
- ///
- /// Allow DynamicLoader plug-ins to execute some code after
- /// attaching to a process.
- //------------------------------------------------------------------
- void
- DidAttach() override;
-
- void
- DidLaunch() override;
-
- lldb::ThreadPlanSP
- GetStepThroughTrampolinePlan(lldb_private::Thread &thread,
- bool stop_others) override;
-
- lldb_private::Error
- CanLoadImage() override;
-
- //------------------------------------------------------------------
- // PluginInterface protocol
- //------------------------------------------------------------------
- lldb_private::ConstString
- GetPluginName() override;
+ //------------------------------------------------------------------
+ // Static Functions
+ //------------------------------------------------------------------
+ static void Initialize();
- uint32_t
- GetPluginVersion() override;
+ static void Terminate();
+
+ static lldb_private::ConstString GetPluginNameStatic();
+
+ static const char *GetPluginDescriptionStatic();
+
+ static lldb_private::DynamicLoader *
+ CreateInstance(lldb_private::Process *process, bool force);
+
+ static void DebuggerInitialize(lldb_private::Debugger &debugger);
+
+ static lldb::addr_t SearchForDarwinKernel(lldb_private::Process *process);
+
+ //------------------------------------------------------------------
+ /// Called after attaching a process.
+ ///
+ /// Allow DynamicLoader plug-ins to execute some code after
+ /// attaching to a process.
+ //------------------------------------------------------------------
+ void DidAttach() override;
+
+ void DidLaunch() override;
+
+ lldb::ThreadPlanSP GetStepThroughTrampolinePlan(lldb_private::Thread &thread,
+ bool stop_others) override;
+
+ lldb_private::Error CanLoadImage() override;
+
+ //------------------------------------------------------------------
+ // PluginInterface protocol
+ //------------------------------------------------------------------
+ lldb_private::ConstString GetPluginName() override;
+
+ uint32_t GetPluginVersion() override;
protected:
- void
- PrivateInitialize (lldb_private::Process *process);
+ void PrivateInitialize(lldb_private::Process *process);
- void
- PrivateProcessStateChanged (lldb_private::Process *process,
- lldb::StateType state);
-
- void
- UpdateIfNeeded();
-
- void
- LoadKernelModuleIfNeeded ();
-
- void
- Clear (bool clear_process);
-
- void
- PutToLog (lldb_private::Log *log) const;
-
- static bool
- BreakpointHitCallback (void *baton,
- lldb_private::StoppointCallbackContext *context,
- lldb::user_id_t break_id,
- lldb::user_id_t break_loc_id);
-
- bool
- BreakpointHit (lldb_private::StoppointCallbackContext *context,
- lldb::user_id_t break_id,
- lldb::user_id_t break_loc_id);
- uint32_t
- GetAddrByteSize()
- {
- return m_kernel.GetAddressByteSize();
+ void PrivateProcessStateChanged(lldb_private::Process *process,
+ lldb::StateType state);
+
+ void UpdateIfNeeded();
+
+ void LoadKernelModuleIfNeeded();
+
+ void Clear(bool clear_process);
+
+ void PutToLog(lldb_private::Log *log) const;
+
+ static bool
+ BreakpointHitCallback(void *baton,
+ lldb_private::StoppointCallbackContext *context,
+ lldb::user_id_t break_id, lldb::user_id_t break_loc_id);
+
+ bool BreakpointHit(lldb_private::StoppointCallbackContext *context,
+ lldb::user_id_t break_id, lldb::user_id_t break_loc_id);
+ uint32_t GetAddrByteSize() { return m_kernel.GetAddressByteSize(); }
+
+ static lldb::ByteOrder GetByteOrderFromMagic(uint32_t magic);
+
+ enum {
+ KERNEL_MODULE_MAX_NAME = 64u,
+ // Versions less than 2 didn't have an entry size,
+ // they had a 64 bit name, 16 byte UUID, 8 byte addr,
+ // 8 byte size, 8 byte version, 4 byte load tag, and
+ // 4 byte flags
+ KERNEL_MODULE_ENTRY_SIZE_VERSION_1 = 64u + 16u + 8u + 8u + 8u + 4u + 4u
+ };
+
+ // class KextImageInfo represents a single kext or kernel binary image.
+ // The class was designed to hold the information from the
+ // OSKextLoadedKextSummary
+ // structure (in libkern/libkern/OSKextLibPrivate.h from xnu). The kernel
+ // maintains
+ // a list of loded kexts in memory (the OSKextLoadedKextSummaryHeader
+ // structure,
+ // which points to an array of OSKextLoadedKextSummary's).
+ //
+ // A KextImageInfos may have -
+ //
+ // 1. The load address, name, UUID, and size of a kext/kernel binary in memory
+ // (read straight out of the kernel's list-of-kexts loaded)
+ // 2. A ModuleSP based on a MemoryModule read out of the kernel's memory
+ // (very unlikely to have any symbolic information)
+ // 3. A ModuleSP for an on-disk copy of the kext binary, possibly with debug
+ // info
+ // or a dSYM
+ //
+ // For performance reasons, the developer may prefer that lldb not load the
+ // kexts out
+ // of memory at the start of a kernel session. But we should build up /
+ // maintain a
+ // list of kexts that the kernel has told us about so we can relocate a kext
+ // module
+ // later if the user explicitly adds it to the target.
+
+ class KextImageInfo {
+ public:
+ KextImageInfo()
+ : m_name(), m_module_sp(), m_memory_module_sp(),
+ m_load_process_stop_id(UINT32_MAX), m_uuid(),
+ m_load_address(LLDB_INVALID_ADDRESS), m_size(0),
+ m_kernel_image(false) {}
+
+ void Clear() {
+ m_load_address = LLDB_INVALID_ADDRESS;
+ m_size = 0;
+ m_name.clear();
+ m_uuid.Clear();
+ m_module_sp.reset();
+ m_memory_module_sp.reset();
+ m_load_process_stop_id = UINT32_MAX;
}
- static lldb::ByteOrder
- GetByteOrderFromMagic (uint32_t magic);
+ bool LoadImageAtFileAddress(lldb_private::Process *process);
+
+ bool LoadImageUsingMemoryModule(lldb_private::Process *process);
+
+ bool IsLoaded() { return m_load_process_stop_id != UINT32_MAX; }
+
+ void SetLoadAddress(
+ lldb::addr_t load_addr); // Address of the Mach-O header for this binary
+
+ lldb::addr_t
+ GetLoadAddress() const; // Address of the Mach-O header for this binary
+
+ lldb_private::UUID GetUUID() const;
+
+ void SetUUID(const lldb_private::UUID &uuid);
+
+ void SetName(const char *);
+
+ std::string GetName() const;
+
+ void SetModule(lldb::ModuleSP module);
- enum
- {
- KERNEL_MODULE_MAX_NAME = 64u,
- // Versions less than 2 didn't have an entry size,
- // they had a 64 bit name, 16 byte UUID, 8 byte addr,
- // 8 byte size, 8 byte version, 4 byte load tag, and
- // 4 byte flags
- KERNEL_MODULE_ENTRY_SIZE_VERSION_1 = 64u + 16u + 8u + 8u + 8u + 4u + 4u
- };
-
- // class KextImageInfo represents a single kext or kernel binary image.
- // The class was designed to hold the information from the OSKextLoadedKextSummary
- // structure (in libkern/libkern/OSKextLibPrivate.h from xnu). The kernel maintains
- // a list of loded kexts in memory (the OSKextLoadedKextSummaryHeader structure,
- // which points to an array of OSKextLoadedKextSummary's).
- //
- // A KextImageInfos may have -
- //
- // 1. The load address, name, UUID, and size of a kext/kernel binary in memory
- // (read straight out of the kernel's list-of-kexts loaded)
- // 2. A ModuleSP based on a MemoryModule read out of the kernel's memory
- // (very unlikely to have any symbolic information)
- // 3. A ModuleSP for an on-disk copy of the kext binary, possibly with debug info
- // or a dSYM
- //
- // For performance reasons, the developer may prefer that lldb not load the kexts out
- // of memory at the start of a kernel session. But we should build up / maintain a
- // list of kexts that the kernel has told us about so we can relocate a kext module
- // later if the user explicitly adds it to the target.
-
- class KextImageInfo
- {
- public:
- KextImageInfo () :
- m_name (),
- m_module_sp (),
- m_memory_module_sp (),
- m_load_process_stop_id (UINT32_MAX),
- m_uuid (),
- m_load_address (LLDB_INVALID_ADDRESS),
- m_size (0),
- m_kernel_image (false)
- { }
-
- void
- Clear ()
- {
- m_load_address = LLDB_INVALID_ADDRESS;
- m_size = 0;
- m_name.clear ();
- m_uuid.Clear();
- m_module_sp.reset();
- m_memory_module_sp.reset();
- m_load_process_stop_id = UINT32_MAX;
- }
-
- bool
- LoadImageAtFileAddress (lldb_private::Process *process);
-
- bool
- LoadImageUsingMemoryModule (lldb_private::Process *process);
-
- bool
- IsLoaded ()
- {
- return m_load_process_stop_id != UINT32_MAX;
- }
-
- void
- SetLoadAddress (lldb::addr_t load_addr); // Address of the Mach-O header for this binary
-
- lldb::addr_t
- GetLoadAddress () const; // Address of the Mach-O header for this binary
-
- lldb_private::UUID
- GetUUID () const;
-
- void
- SetUUID (const lldb_private::UUID &uuid);
-
- void
- SetName (const char *);
-
- std::string
- GetName () const;
-
- void
- SetModule (lldb::ModuleSP module);
-
- lldb::ModuleSP
- GetModule ();
-
- // try to fill in m_memory_module_sp from memory based on the m_load_address
- bool
- ReadMemoryModule (lldb_private::Process *process);
-
- bool
- IsKernel () const; // true if this is the mach_kernel; false if this is a kext
-
- void
- SetIsKernel (bool is_kernel);
-
- uint64_t
- GetSize () const;
-
- void
- SetSize (uint64_t size);
-
- uint32_t
- GetProcessStopId () const; // the stop-id when this binary was first noticed
-
- void
- SetProcessStopId (uint32_t stop_id);
-
- bool
- operator== (const KextImageInfo &rhs);
-
- uint32_t
- GetAddressByteSize (); // as determined by Mach-O header
-
- lldb::ByteOrder
- GetByteOrder(); // as determined by Mach-O header
-
- lldb_private::ArchSpec
- GetArchitecture () const; // as determined by Mach-O header
-
- void
- PutToLog (lldb_private::Log *log) const;
-
- typedef std::vector<KextImageInfo> collection;
- typedef collection::iterator iterator;
- typedef collection::const_iterator const_iterator;
-
- private:
- std::string m_name;
- lldb::ModuleSP m_module_sp;
- lldb::ModuleSP m_memory_module_sp;
- uint32_t m_load_process_stop_id; // the stop-id when this module was added to the Target
- lldb_private::UUID m_uuid; // UUID for this dylib if it has one, else all zeros
- lldb::addr_t m_load_address;
- uint64_t m_size;
- bool m_kernel_image; // true if this is the kernel, false if this is a kext
- };
-
- struct OSKextLoadedKextSummaryHeader
- {
- uint32_t version;
- uint32_t entry_size;
- uint32_t entry_count;
- lldb::addr_t image_infos_addr;
-
- OSKextLoadedKextSummaryHeader() :
- version (0),
- entry_size (0),
- entry_count (0),
- image_infos_addr (LLDB_INVALID_ADDRESS)
- {
- }
-
- uint32_t
- GetSize()
- {
- switch (version)
- {
- case 0: return 0; // Can't know the size without a valid version
- case 1: return 8; // Version 1 only had a version + entry_count
- default: break;
- }
- // Version 2 and above has version, entry_size, entry_count, and reserved
- return 16;
- }
-
- void
- Clear()
- {
- version = 0;
- entry_size = 0;
- entry_count = 0;
- image_infos_addr = LLDB_INVALID_ADDRESS;
- }
-
- bool
- IsValid() const
- {
- return version >= 1 || version <= 2;
- }
- };
-
- void
- RegisterNotificationCallbacks();
-
- void
- UnregisterNotificationCallbacks();
-
- void
- SetNotificationBreakpointIfNeeded ();
-
- bool
- ReadAllKextSummaries ();
-
- bool
- ReadKextSummaryHeader ();
-
- bool
- ParseKextSummaries (const lldb_private::Address &kext_summary_addr,
- uint32_t count);
-
- void
- UpdateImageInfosHeaderAndLoadCommands(KextImageInfo::collection &image_infos,
- uint32_t infos_count,
- bool update_executable);
+ lldb::ModuleSP GetModule();
+
+ // try to fill in m_memory_module_sp from memory based on the m_load_address
+ bool ReadMemoryModule(lldb_private::Process *process);
+
+ bool IsKernel()
+ const; // true if this is the mach_kernel; false if this is a kext
+
+ void SetIsKernel(bool is_kernel);
+
+ uint64_t GetSize() const;
+
+ void SetSize(uint64_t size);
uint32_t
- ReadKextSummaries (const lldb_private::Address &kext_summary_addr,
- uint32_t image_infos_count,
- KextImageInfo::collection &image_infos);
-
- static lldb::addr_t
- SearchForKernelAtSameLoadAddr (lldb_private::Process *process);
-
- static lldb::addr_t
- SearchForKernelWithDebugHints (lldb_private::Process *process);
-
- static lldb::addr_t
- SearchForKernelNearPC (lldb_private::Process *process);
-
- static lldb::addr_t
- SearchForKernelViaExhaustiveSearch (lldb_private::Process *process);
-
- static lldb_private::UUID
- CheckForKernelImageAtAddress (lldb::addr_t addr, lldb_private::Process *process);
-
- lldb::addr_t m_kernel_load_address;
- KextImageInfo m_kernel; // Info about the current kernel image being used
-
- lldb_private::Address m_kext_summary_header_ptr_addr;
- lldb_private::Address m_kext_summary_header_addr;
- OSKextLoadedKextSummaryHeader m_kext_summary_header;
- KextImageInfo::collection m_known_kexts;
- mutable std::recursive_mutex m_mutex;
- lldb::user_id_t m_break_id;
+ GetProcessStopId() const; // the stop-id when this binary was first noticed
+
+ void SetProcessStopId(uint32_t stop_id);
+
+ bool operator==(const KextImageInfo &rhs);
+
+ uint32_t GetAddressByteSize(); // as determined by Mach-O header
+
+ lldb::ByteOrder GetByteOrder(); // as determined by Mach-O header
+
+ lldb_private::ArchSpec
+ GetArchitecture() const; // as determined by Mach-O header
+
+ void PutToLog(lldb_private::Log *log) const;
+
+ typedef std::vector<KextImageInfo> collection;
+ typedef collection::iterator iterator;
+ typedef collection::const_iterator const_iterator;
+
+ private:
+ std::string m_name;
+ lldb::ModuleSP m_module_sp;
+ lldb::ModuleSP m_memory_module_sp;
+ uint32_t m_load_process_stop_id; // the stop-id when this module was added
+ // to the Target
+ lldb_private::UUID
+ m_uuid; // UUID for this dylib if it has one, else all zeros
+ lldb::addr_t m_load_address;
+ uint64_t m_size;
+ bool m_kernel_image; // true if this is the kernel, false if this is a kext
+ };
+
+ struct OSKextLoadedKextSummaryHeader {
+ uint32_t version;
+ uint32_t entry_size;
+ uint32_t entry_count;
+ lldb::addr_t image_infos_addr;
+
+ OSKextLoadedKextSummaryHeader()
+ : version(0), entry_size(0), entry_count(0),
+ image_infos_addr(LLDB_INVALID_ADDRESS) {}
+
+ uint32_t GetSize() {
+ switch (version) {
+ case 0:
+ return 0; // Can't know the size without a valid version
+ case 1:
+ return 8; // Version 1 only had a version + entry_count
+ default:
+ break;
+ }
+ // Version 2 and above has version, entry_size, entry_count, and reserved
+ return 16;
+ }
+
+ void Clear() {
+ version = 0;
+ entry_size = 0;
+ entry_count = 0;
+ image_infos_addr = LLDB_INVALID_ADDRESS;
+ }
+
+ bool IsValid() const { return version >= 1 || version <= 2; }
+ };
+
+ void RegisterNotificationCallbacks();
+
+ void UnregisterNotificationCallbacks();
+
+ void SetNotificationBreakpointIfNeeded();
+
+ bool ReadAllKextSummaries();
+
+ bool ReadKextSummaryHeader();
+
+ bool ParseKextSummaries(const lldb_private::Address &kext_summary_addr,
+ uint32_t count);
+
+ void
+ UpdateImageInfosHeaderAndLoadCommands(KextImageInfo::collection &image_infos,
+ uint32_t infos_count,
+ bool update_executable);
+
+ uint32_t ReadKextSummaries(const lldb_private::Address &kext_summary_addr,
+ uint32_t image_infos_count,
+ KextImageInfo::collection &image_infos);
+
+ static lldb::addr_t
+ SearchForKernelAtSameLoadAddr(lldb_private::Process *process);
+
+ static lldb::addr_t
+ SearchForKernelWithDebugHints(lldb_private::Process *process);
+
+ static lldb::addr_t SearchForKernelNearPC(lldb_private::Process *process);
+
+ static lldb::addr_t
+ SearchForKernelViaExhaustiveSearch(lldb_private::Process *process);
+
+ static lldb_private::UUID
+ CheckForKernelImageAtAddress(lldb::addr_t addr,
+ lldb_private::Process *process);
+
+ lldb::addr_t m_kernel_load_address;
+ KextImageInfo m_kernel; // Info about the current kernel image being used
+
+ lldb_private::Address m_kext_summary_header_ptr_addr;
+ lldb_private::Address m_kext_summary_header_addr;
+ OSKextLoadedKextSummaryHeader m_kext_summary_header;
+ KextImageInfo::collection m_known_kexts;
+ mutable std::recursive_mutex m_mutex;
+ lldb::user_id_t m_break_id;
private:
- DISALLOW_COPY_AND_ASSIGN (DynamicLoaderDarwinKernel);
+ DISALLOW_COPY_AND_ASSIGN(DynamicLoaderDarwinKernel);
};
#endif // liblldb_DynamicLoaderDarwinKernel_h_
Modified: lldb/trunk/source/Plugins/DynamicLoader/Hexagon-DYLD/DynamicLoaderHexagonDYLD.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/Hexagon-DYLD/DynamicLoaderHexagonDYLD.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/Hexagon-DYLD/DynamicLoaderHexagonDYLD.cpp (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/Hexagon-DYLD/DynamicLoaderHexagonDYLD.cpp Tue Sep 6 15:57:50 2016
@@ -10,17 +10,17 @@
// C Includes
// C++ Includes
// Other libraries and framework includes
-#include "lldb/Core/PluginManager.h"
+#include "lldb/Breakpoint/BreakpointLocation.h"
#include "lldb/Core/Log.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/ModuleSpec.h"
+#include "lldb/Core/PluginManager.h"
#include "lldb/Core/Section.h"
#include "lldb/Symbol/ObjectFile.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/Thread.h"
#include "lldb/Target/ThreadPlanRunToAddress.h"
-#include "lldb/Breakpoint/BreakpointLocation.h"
#include "DynamicLoaderHexagonDYLD.h"
@@ -31,562 +31,490 @@ using namespace lldb_private;
//
// Notes about hexagon dynamic loading:
//
-// When we connect to a target we find the dyld breakpoint address. We put a
+// When we connect to a target we find the dyld breakpoint address. We put
+// a
// breakpoint there with a callback 'RendezvousBreakpointHit()'.
//
-// It is possible to find the dyld structure address from the ELF symbol table,
-// but in the case of the simulator it has not been initialized before the
+// It is possible to find the dyld structure address from the ELF symbol
+// table,
+// but in the case of the simulator it has not been initialized before the
// target calls dlinit().
//
-// We can only safely parse the dyld structure after we hit the dyld breakpoint
+// We can only safely parse the dyld structure after we hit the dyld
+// breakpoint
// since at that time we know dlinit() must have been called.
//
// Find the load address of a symbol
-static lldb::addr_t findSymbolAddress( Process *proc, ConstString findName )
-{
- assert( proc != nullptr );
-
- ModuleSP module = proc->GetTarget().GetExecutableModule();
- assert( module.get() != nullptr );
-
- ObjectFile *exe = module->GetObjectFile();
- assert( exe != nullptr );
-
- lldb_private::Symtab *symtab = exe->GetSymtab( );
- assert( symtab != nullptr );
-
- for ( size_t i = 0; i < symtab->GetNumSymbols( ); i++ )
- {
- const Symbol* sym = symtab->SymbolAtIndex( i );
- assert( sym != nullptr );
- const ConstString &symName = sym->GetName( );
-
- if ( ConstString::Compare( findName, symName ) == 0 )
- {
- Address addr = sym->GetAddress();
- return addr.GetLoadAddress( & proc->GetTarget() );
- }
+static lldb::addr_t findSymbolAddress(Process *proc, ConstString findName) {
+ assert(proc != nullptr);
+
+ ModuleSP module = proc->GetTarget().GetExecutableModule();
+ assert(module.get() != nullptr);
+
+ ObjectFile *exe = module->GetObjectFile();
+ assert(exe != nullptr);
+
+ lldb_private::Symtab *symtab = exe->GetSymtab();
+ assert(symtab != nullptr);
+
+ for (size_t i = 0; i < symtab->GetNumSymbols(); i++) {
+ const Symbol *sym = symtab->SymbolAtIndex(i);
+ assert(sym != nullptr);
+ const ConstString &symName = sym->GetName();
+
+ if (ConstString::Compare(findName, symName) == 0) {
+ Address addr = sym->GetAddress();
+ return addr.GetLoadAddress(&proc->GetTarget());
}
- return LLDB_INVALID_ADDRESS;
+ }
+ return LLDB_INVALID_ADDRESS;
}
-void
-DynamicLoaderHexagonDYLD::Initialize()
-{
- PluginManager::RegisterPlugin(GetPluginNameStatic(),
- GetPluginDescriptionStatic(),
- CreateInstance);
-}
-
-void
-DynamicLoaderHexagonDYLD::Terminate()
-{
-}
-
-lldb_private::ConstString
-DynamicLoaderHexagonDYLD::GetPluginName()
-{
- return GetPluginNameStatic();
-}
-
-lldb_private::ConstString
-DynamicLoaderHexagonDYLD::GetPluginNameStatic()
-{
- static ConstString g_name("hexagon-dyld");
- return g_name;
-}
-
-const char *
-DynamicLoaderHexagonDYLD::GetPluginDescriptionStatic()
-{
- return "Dynamic loader plug-in that watches for shared library "
- "loads/unloads in Hexagon processes.";
-}
-
-uint32_t
-DynamicLoaderHexagonDYLD::GetPluginVersion()
-{
- return 1;
-}
-
-DynamicLoader *
-DynamicLoaderHexagonDYLD::CreateInstance(Process *process, bool force)
-{
- bool create = force;
- if (!create)
- {
- const llvm::Triple &triple_ref = process->GetTarget().GetArchitecture().GetTriple();
- if (triple_ref.getArch() == llvm::Triple::hexagon)
- create = true;
- }
-
- if (create)
- return new DynamicLoaderHexagonDYLD(process);
- return NULL;
+void DynamicLoaderHexagonDYLD::Initialize() {
+ PluginManager::RegisterPlugin(GetPluginNameStatic(),
+ GetPluginDescriptionStatic(), CreateInstance);
}
-DynamicLoaderHexagonDYLD::DynamicLoaderHexagonDYLD(Process *process)
- : DynamicLoader(process)
- , m_rendezvous (process)
- , m_load_offset(LLDB_INVALID_ADDRESS)
- , m_entry_point(LLDB_INVALID_ADDRESS)
- , m_dyld_bid (LLDB_INVALID_BREAK_ID)
-{
+void DynamicLoaderHexagonDYLD::Terminate() {}
+
+lldb_private::ConstString DynamicLoaderHexagonDYLD::GetPluginName() {
+ return GetPluginNameStatic();
}
-DynamicLoaderHexagonDYLD::~DynamicLoaderHexagonDYLD()
-{
- if (m_dyld_bid != LLDB_INVALID_BREAK_ID)
- {
- m_process->GetTarget().RemoveBreakpointByID (m_dyld_bid);
- m_dyld_bid = LLDB_INVALID_BREAK_ID;
- }
+lldb_private::ConstString DynamicLoaderHexagonDYLD::GetPluginNameStatic() {
+ static ConstString g_name("hexagon-dyld");
+ return g_name;
}
-void
-DynamicLoaderHexagonDYLD::DidAttach()
-{
- ModuleSP executable;
- addr_t load_offset;
-
- executable = GetTargetExecutable();
-
- // Find the difference between the desired load address in the elf file
- // and the real load address in memory
- load_offset = ComputeLoadOffset();
-
- // Check that there is a valid executable
- if ( executable.get( ) == nullptr )
- return;
-
- // Disable JIT for hexagon targets because its not supported
- m_process->SetCanJIT(false);
-
- // Enable Interpreting of function call expressions
- m_process->SetCanInterpretFunctionCalls(true);
-
- // Add the current executable to the module list
- ModuleList module_list;
- module_list.Append(executable);
-
- // Map the loaded sections of this executable
- if ( load_offset != LLDB_INVALID_ADDRESS )
- UpdateLoadedSections(executable, LLDB_INVALID_ADDRESS, load_offset, true);
-
- // AD: confirm this?
- // Load into LLDB all of the currently loaded executables in the stub
- LoadAllCurrentModules();
-
- // AD: confirm this?
- // Callback for the target to give it the loaded module list
- m_process->GetTarget().ModulesDidLoad(module_list);
-
- // Try to set a breakpoint at the rendezvous breakpoint.
- // DidLaunch uses ProbeEntry() instead. That sets a breakpoint,
- // at the dyld breakpoint address, with a callback so that when hit,
- // the dyld structure can be parsed.
- if (! SetRendezvousBreakpoint() )
- {
- // fail
- }
+const char *DynamicLoaderHexagonDYLD::GetPluginDescriptionStatic() {
+ return "Dynamic loader plug-in that watches for shared library "
+ "loads/unloads in Hexagon processes.";
+}
+
+uint32_t DynamicLoaderHexagonDYLD::GetPluginVersion() { return 1; }
+
+DynamicLoader *DynamicLoaderHexagonDYLD::CreateInstance(Process *process,
+ bool force) {
+ bool create = force;
+ if (!create) {
+ const llvm::Triple &triple_ref =
+ process->GetTarget().GetArchitecture().GetTriple();
+ if (triple_ref.getArch() == llvm::Triple::hexagon)
+ create = true;
+ }
+
+ if (create)
+ return new DynamicLoaderHexagonDYLD(process);
+ return NULL;
+}
+
+DynamicLoaderHexagonDYLD::DynamicLoaderHexagonDYLD(Process *process)
+ : DynamicLoader(process), m_rendezvous(process),
+ m_load_offset(LLDB_INVALID_ADDRESS), m_entry_point(LLDB_INVALID_ADDRESS),
+ m_dyld_bid(LLDB_INVALID_BREAK_ID) {}
+
+DynamicLoaderHexagonDYLD::~DynamicLoaderHexagonDYLD() {
+ if (m_dyld_bid != LLDB_INVALID_BREAK_ID) {
+ m_process->GetTarget().RemoveBreakpointByID(m_dyld_bid);
+ m_dyld_bid = LLDB_INVALID_BREAK_ID;
+ }
}
-void
-DynamicLoaderHexagonDYLD::DidLaunch()
-{
+void DynamicLoaderHexagonDYLD::DidAttach() {
+ ModuleSP executable;
+ addr_t load_offset;
+
+ executable = GetTargetExecutable();
+
+ // Find the difference between the desired load address in the elf file
+ // and the real load address in memory
+ load_offset = ComputeLoadOffset();
+
+ // Check that there is a valid executable
+ if (executable.get() == nullptr)
+ return;
+
+ // Disable JIT for hexagon targets because its not supported
+ m_process->SetCanJIT(false);
+
+ // Enable Interpreting of function call expressions
+ m_process->SetCanInterpretFunctionCalls(true);
+
+ // Add the current executable to the module list
+ ModuleList module_list;
+ module_list.Append(executable);
+
+ // Map the loaded sections of this executable
+ if (load_offset != LLDB_INVALID_ADDRESS)
+ UpdateLoadedSections(executable, LLDB_INVALID_ADDRESS, load_offset, true);
+
+ // AD: confirm this?
+ // Load into LLDB all of the currently loaded executables in the stub
+ LoadAllCurrentModules();
+
+ // AD: confirm this?
+ // Callback for the target to give it the loaded module list
+ m_process->GetTarget().ModulesDidLoad(module_list);
+
+ // Try to set a breakpoint at the rendezvous breakpoint.
+ // DidLaunch uses ProbeEntry() instead. That sets a breakpoint,
+ // at the dyld breakpoint address, with a callback so that when hit,
+ // the dyld structure can be parsed.
+ if (!SetRendezvousBreakpoint()) {
+ // fail
+ }
}
+void DynamicLoaderHexagonDYLD::DidLaunch() {}
+
/// Checks to see if the target module has changed, updates the target
/// accordingly and returns the target executable module.
-ModuleSP
-DynamicLoaderHexagonDYLD::GetTargetExecutable()
-{
- Target &target = m_process->GetTarget();
- ModuleSP executable = target.GetExecutableModule();
-
- // There is no executable
- if (! executable.get())
- return executable;
-
- // The target executable file does not exits
- if (! executable->GetFileSpec().Exists())
- return executable;
-
- // Prep module for loading
- ModuleSpec module_spec(executable->GetFileSpec(), executable->GetArchitecture());
- ModuleSP module_sp (new Module (module_spec));
-
- // Check if the executable has changed and set it to the target executable if they differ.
- if (module_sp.get() && module_sp->GetUUID().IsValid() && executable->GetUUID().IsValid())
- {
- // if the executable has changed ??
- if (module_sp->GetUUID() != executable->GetUUID())
- executable.reset();
- }
- else if (executable->FileHasChanged())
- executable.reset();
+ModuleSP DynamicLoaderHexagonDYLD::GetTargetExecutable() {
+ Target &target = m_process->GetTarget();
+ ModuleSP executable = target.GetExecutableModule();
- if ( executable.get( ) )
- return executable;
+ // There is no executable
+ if (!executable.get())
+ return executable;
- // TODO: What case is this code used?
- executable = target.GetSharedModule(module_spec);
- if (executable.get() != target.GetExecutableModulePointer())
- {
- // Don't load dependent images since we are in dyld where we will know
- // and find out about all images that are loaded
- const bool get_dependent_images = false;
- target.SetExecutableModule(executable, get_dependent_images);
- }
-
+ // The target executable file does not exits
+ if (!executable->GetFileSpec().Exists())
return executable;
-}
-//AD: Needs to be updated?
-Error
-DynamicLoaderHexagonDYLD::CanLoadImage()
-{
- return Error();
-}
-
-void
-DynamicLoaderHexagonDYLD::UpdateLoadedSections(ModuleSP module,
- addr_t link_map_addr,
- addr_t base_addr,
- bool base_addr_is_offset)
-{
- Target &target = m_process->GetTarget();
- const SectionList *sections = GetSectionListFromModule(module);
-
- assert(sections && "SectionList missing from loaded module.");
-
- m_loaded_modules[module] = link_map_addr;
-
- const size_t num_sections = sections->GetSize();
-
- for (unsigned i = 0; i < num_sections; ++i)
- {
- SectionSP section_sp (sections->GetSectionAtIndex(i));
- lldb::addr_t new_load_addr = section_sp->GetFileAddress() + base_addr;
-
- // AD: 02/05/14
- // since our memory map starts from address 0, we must not ignore
- // sections that load to address 0. This violates the reference
- // ELF spec, however is used for Hexagon.
-
- // If the file address of the section is zero then this is not an
- // allocatable/loadable section (property of ELF sh_addr). Skip it.
-// if (new_load_addr == base_addr)
-// continue;
+ // Prep module for loading
+ ModuleSpec module_spec(executable->GetFileSpec(),
+ executable->GetArchitecture());
+ ModuleSP module_sp(new Module(module_spec));
+
+ // Check if the executable has changed and set it to the target executable if
+ // they differ.
+ if (module_sp.get() && module_sp->GetUUID().IsValid() &&
+ executable->GetUUID().IsValid()) {
+ // if the executable has changed ??
+ if (module_sp->GetUUID() != executable->GetUUID())
+ executable.reset();
+ } else if (executable->FileHasChanged())
+ executable.reset();
- target.SetSectionLoadAddress(section_sp, new_load_addr);
- }
+ if (executable.get())
+ return executable;
+
+ // TODO: What case is this code used?
+ executable = target.GetSharedModule(module_spec);
+ if (executable.get() != target.GetExecutableModulePointer()) {
+ // Don't load dependent images since we are in dyld where we will know
+ // and find out about all images that are loaded
+ const bool get_dependent_images = false;
+ target.SetExecutableModule(executable, get_dependent_images);
+ }
+
+ return executable;
+}
+
+// AD: Needs to be updated?
+Error DynamicLoaderHexagonDYLD::CanLoadImage() { return Error(); }
+
+void DynamicLoaderHexagonDYLD::UpdateLoadedSections(ModuleSP module,
+ addr_t link_map_addr,
+ addr_t base_addr,
+ bool base_addr_is_offset) {
+ Target &target = m_process->GetTarget();
+ const SectionList *sections = GetSectionListFromModule(module);
+
+ assert(sections && "SectionList missing from loaded module.");
+
+ m_loaded_modules[module] = link_map_addr;
+
+ const size_t num_sections = sections->GetSize();
+
+ for (unsigned i = 0; i < num_sections; ++i) {
+ SectionSP section_sp(sections->GetSectionAtIndex(i));
+ lldb::addr_t new_load_addr = section_sp->GetFileAddress() + base_addr;
+
+ // AD: 02/05/14
+ // since our memory map starts from address 0, we must not ignore
+ // sections that load to address 0. This violates the reference
+ // ELF spec, however is used for Hexagon.
+
+ // If the file address of the section is zero then this is not an
+ // allocatable/loadable section (property of ELF sh_addr). Skip it.
+ // if (new_load_addr == base_addr)
+ // continue;
+
+ target.SetSectionLoadAddress(section_sp, new_load_addr);
+ }
}
/// Removes the loaded sections from the target in @p module.
///
/// @param module The module to traverse.
-void
-DynamicLoaderHexagonDYLD::UnloadSections(const ModuleSP module)
-{
- Target &target = m_process->GetTarget();
- const SectionList *sections = GetSectionListFromModule(module);
-
- assert(sections && "SectionList missing from unloaded module.");
-
- m_loaded_modules.erase(module);
-
- const size_t num_sections = sections->GetSize();
- for (size_t i = 0; i < num_sections; ++i)
- {
- SectionSP section_sp (sections->GetSectionAtIndex(i));
- target.SetSectionUnloaded(section_sp);
- }
+void DynamicLoaderHexagonDYLD::UnloadSections(const ModuleSP module) {
+ Target &target = m_process->GetTarget();
+ const SectionList *sections = GetSectionListFromModule(module);
+
+ assert(sections && "SectionList missing from unloaded module.");
+
+ m_loaded_modules.erase(module);
+
+ const size_t num_sections = sections->GetSize();
+ for (size_t i = 0; i < num_sections; ++i) {
+ SectionSP section_sp(sections->GetSectionAtIndex(i));
+ target.SetSectionUnloaded(section_sp);
+ }
}
// Place a breakpoint on <_rtld_debug_state>
-bool
-DynamicLoaderHexagonDYLD::SetRendezvousBreakpoint()
-{
- Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
+bool DynamicLoaderHexagonDYLD::SetRendezvousBreakpoint() {
+ Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
- // This is the original code, which want to look in the rendezvous structure
- // to find the breakpoint address. Its backwards for us, since we can easily
- // find the breakpoint address, since it is exported in our executable.
- // We however know that we cant read the Rendezvous structure until we have hit
- // the breakpoint once.
- const ConstString dyldBpName( "_rtld_debug_state" );
- addr_t break_addr = findSymbolAddress( m_process, dyldBpName );
-
- Target &target = m_process->GetTarget();
-
- // Do not try to set the breakpoint if we don't know where to put it
- if ( break_addr == LLDB_INVALID_ADDRESS )
- {
- if ( log )
- log->Printf( "Unable to locate _rtld_debug_state breakpoint address" );
+ // This is the original code, which want to look in the rendezvous structure
+ // to find the breakpoint address. Its backwards for us, since we can easily
+ // find the breakpoint address, since it is exported in our executable.
+ // We however know that we cant read the Rendezvous structure until we have
+ // hit
+ // the breakpoint once.
+ const ConstString dyldBpName("_rtld_debug_state");
+ addr_t break_addr = findSymbolAddress(m_process, dyldBpName);
- return false;
- }
+ Target &target = m_process->GetTarget();
- // Save the address of the rendezvous structure
- m_rendezvous.SetBreakAddress( break_addr );
+ // Do not try to set the breakpoint if we don't know where to put it
+ if (break_addr == LLDB_INVALID_ADDRESS) {
+ if (log)
+ log->Printf("Unable to locate _rtld_debug_state breakpoint address");
- // If we haven't set the breakpoint before then set it
- if (m_dyld_bid == LLDB_INVALID_BREAK_ID)
- {
- Breakpoint *dyld_break = target.CreateBreakpoint (break_addr, true, false).get();
- dyld_break->SetCallback(RendezvousBreakpointHit, this, true);
- dyld_break->SetBreakpointKind ("shared-library-event");
- m_dyld_bid = dyld_break->GetID();
-
- // Make sure our breakpoint is at the right address.
- assert
- (
- target.GetBreakpointByID(m_dyld_bid)->
- FindLocationByAddress(break_addr)->
- GetBreakpoint().GetID()
- == m_dyld_bid
- );
+ return false;
+ }
- if ( log && dyld_break == nullptr )
- log->Printf( "Failed to create _rtld_debug_state breakpoint" );
+ // Save the address of the rendezvous structure
+ m_rendezvous.SetBreakAddress(break_addr);
- // check we have successfully set bp
- return (dyld_break != nullptr);
- }
- else
- // rendezvous already set
- return true;
+ // If we haven't set the breakpoint before then set it
+ if (m_dyld_bid == LLDB_INVALID_BREAK_ID) {
+ Breakpoint *dyld_break =
+ target.CreateBreakpoint(break_addr, true, false).get();
+ dyld_break->SetCallback(RendezvousBreakpointHit, this, true);
+ dyld_break->SetBreakpointKind("shared-library-event");
+ m_dyld_bid = dyld_break->GetID();
+
+ // Make sure our breakpoint is at the right address.
+ assert(target.GetBreakpointByID(m_dyld_bid)
+ ->FindLocationByAddress(break_addr)
+ ->GetBreakpoint()
+ .GetID() == m_dyld_bid);
+
+ if (log && dyld_break == nullptr)
+ log->Printf("Failed to create _rtld_debug_state breakpoint");
+
+ // check we have successfully set bp
+ return (dyld_break != nullptr);
+ } else
+ // rendezvous already set
+ return true;
}
// We have just hit our breakpoint at <_rtld_debug_state>
-bool
-DynamicLoaderHexagonDYLD::RendezvousBreakpointHit(void *baton,
- StoppointCallbackContext *context,
- user_id_t break_id,
- user_id_t break_loc_id)
-{
- Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
+bool DynamicLoaderHexagonDYLD::RendezvousBreakpointHit(
+ void *baton, StoppointCallbackContext *context, user_id_t break_id,
+ user_id_t break_loc_id) {
+ Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
- if ( log )
- log->Printf( "Rendezvous breakpoint hit!" );
+ if (log)
+ log->Printf("Rendezvous breakpoint hit!");
- DynamicLoaderHexagonDYLD* dyld_instance = nullptr;
- dyld_instance = static_cast<DynamicLoaderHexagonDYLD*>(baton);
+ DynamicLoaderHexagonDYLD *dyld_instance = nullptr;
+ dyld_instance = static_cast<DynamicLoaderHexagonDYLD *>(baton);
- // if the dyld_instance is still not valid then
- // try to locate it on the symbol table
- if ( !dyld_instance->m_rendezvous.IsValid( ) )
- {
- Process *proc = dyld_instance->m_process;
-
- const ConstString dyldStructName( "_rtld_debug" );
- addr_t structAddr = findSymbolAddress( proc, dyldStructName );
-
- if ( structAddr != LLDB_INVALID_ADDRESS )
- {
- dyld_instance->m_rendezvous.SetRendezvousAddress( structAddr );
-
- if ( log )
- log->Printf( "Found _rtld_debug structure @ 0x%08" PRIx64, structAddr );
- }
- else
- {
- if ( log )
- log->Printf( "Unable to resolve the _rtld_debug structure" );
- }
+ // if the dyld_instance is still not valid then
+ // try to locate it on the symbol table
+ if (!dyld_instance->m_rendezvous.IsValid()) {
+ Process *proc = dyld_instance->m_process;
+
+ const ConstString dyldStructName("_rtld_debug");
+ addr_t structAddr = findSymbolAddress(proc, dyldStructName);
+
+ if (structAddr != LLDB_INVALID_ADDRESS) {
+ dyld_instance->m_rendezvous.SetRendezvousAddress(structAddr);
+
+ if (log)
+ log->Printf("Found _rtld_debug structure @ 0x%08" PRIx64, structAddr);
+ } else {
+ if (log)
+ log->Printf("Unable to resolve the _rtld_debug structure");
}
+ }
- dyld_instance->RefreshModules();
+ dyld_instance->RefreshModules();
- // Return true to stop the target, false to just let the target run.
- return dyld_instance->GetStopWhenImagesChange();
+ // Return true to stop the target, false to just let the target run.
+ return dyld_instance->GetStopWhenImagesChange();
}
/// Helper method for RendezvousBreakpointHit. Updates LLDB's current set
/// of loaded modules.
-void
-DynamicLoaderHexagonDYLD::RefreshModules()
-{
- Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
-
- if (!m_rendezvous.Resolve())
- return;
+void DynamicLoaderHexagonDYLD::RefreshModules() {
+ Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
- HexagonDYLDRendezvous::iterator I;
- HexagonDYLDRendezvous::iterator E;
+ if (!m_rendezvous.Resolve())
+ return;
- ModuleList &loaded_modules = m_process->GetTarget().GetImages();
+ HexagonDYLDRendezvous::iterator I;
+ HexagonDYLDRendezvous::iterator E;
- if (m_rendezvous.ModulesDidLoad())
- {
- ModuleList new_modules;
-
- E = m_rendezvous.loaded_end();
- for (I = m_rendezvous.loaded_begin(); I != E; ++I)
- {
- FileSpec file(I->path.c_str(), true);
- ModuleSP module_sp = LoadModuleAtAddress(file, I->link_addr, I->base_addr, true);
- if (module_sp.get())
- {
- loaded_modules.AppendIfNeeded( module_sp );
- new_modules.Append(module_sp);
- }
-
- if (log)
- {
- log->Printf( "Target is loading '%s'", I->path.c_str() );
- if (! module_sp.get() )
- log->Printf( "LLDB failed to load '%s'", I->path.c_str() );
- else
- log->Printf( "LLDB successfully loaded '%s'", I->path.c_str() );
- }
-
- }
- m_process->GetTarget().ModulesDidLoad(new_modules);
+ ModuleList &loaded_modules = m_process->GetTarget().GetImages();
+
+ if (m_rendezvous.ModulesDidLoad()) {
+ ModuleList new_modules;
+
+ E = m_rendezvous.loaded_end();
+ for (I = m_rendezvous.loaded_begin(); I != E; ++I) {
+ FileSpec file(I->path.c_str(), true);
+ ModuleSP module_sp =
+ LoadModuleAtAddress(file, I->link_addr, I->base_addr, true);
+ if (module_sp.get()) {
+ loaded_modules.AppendIfNeeded(module_sp);
+ new_modules.Append(module_sp);
+ }
+
+ if (log) {
+ log->Printf("Target is loading '%s'", I->path.c_str());
+ if (!module_sp.get())
+ log->Printf("LLDB failed to load '%s'", I->path.c_str());
+ else
+ log->Printf("LLDB successfully loaded '%s'", I->path.c_str());
+ }
}
-
- if (m_rendezvous.ModulesDidUnload())
- {
- ModuleList old_modules;
-
- E = m_rendezvous.unloaded_end();
- for (I = m_rendezvous.unloaded_begin(); I != E; ++I)
- {
- FileSpec file(I->path.c_str(), true);
- ModuleSpec module_spec(file);
- ModuleSP module_sp = loaded_modules.FindFirstModule (module_spec);
-
- if (module_sp.get())
- {
- old_modules.Append(module_sp);
- UnloadSections(module_sp);
- }
-
- if (log)
- log->Printf( "Target is unloading '%s'", I->path.c_str() );
-
- }
- loaded_modules.Remove(old_modules);
- m_process->GetTarget().ModulesDidUnload(old_modules, false);
+ m_process->GetTarget().ModulesDidLoad(new_modules);
+ }
+
+ if (m_rendezvous.ModulesDidUnload()) {
+ ModuleList old_modules;
+
+ E = m_rendezvous.unloaded_end();
+ for (I = m_rendezvous.unloaded_begin(); I != E; ++I) {
+ FileSpec file(I->path.c_str(), true);
+ ModuleSpec module_spec(file);
+ ModuleSP module_sp = loaded_modules.FindFirstModule(module_spec);
+
+ if (module_sp.get()) {
+ old_modules.Append(module_sp);
+ UnloadSections(module_sp);
+ }
+
+ if (log)
+ log->Printf("Target is unloading '%s'", I->path.c_str());
}
+ loaded_modules.Remove(old_modules);
+ m_process->GetTarget().ModulesDidUnload(old_modules, false);
+ }
}
-//AD: This is very different to the Static Loader code.
+// AD: This is very different to the Static Loader code.
// It may be wise to look over this and its relation to stack
// unwinding.
ThreadPlanSP
-DynamicLoaderHexagonDYLD::GetStepThroughTrampolinePlan(Thread &thread, bool stop)
-{
- ThreadPlanSP thread_plan_sp;
-
- StackFrame *frame = thread.GetStackFrameAtIndex(0).get();
- const SymbolContext &context = frame->GetSymbolContext(eSymbolContextSymbol);
- Symbol *sym = context.symbol;
-
- if (sym == NULL || !sym->IsTrampoline())
- return thread_plan_sp;
-
- const ConstString sym_name = sym->GetMangled().GetName(lldb::eLanguageTypeUnknown, Mangled::ePreferMangled);
- if (!sym_name)
- return thread_plan_sp;
-
- SymbolContextList target_symbols;
- Target &target = thread.GetProcess()->GetTarget();
- const ModuleList &images = target.GetImages();
-
- images.FindSymbolsWithNameAndType(sym_name, eSymbolTypeCode, target_symbols);
- size_t num_targets = target_symbols.GetSize();
- if (!num_targets)
- return thread_plan_sp;
-
- typedef std::vector<lldb::addr_t> AddressVector;
- AddressVector addrs;
- for (size_t i = 0; i < num_targets; ++i)
- {
- SymbolContext context;
- AddressRange range;
- if (target_symbols.GetContextAtIndex(i, context))
- {
- context.GetAddressRange(eSymbolContextEverything, 0, false, range);
- lldb::addr_t addr = range.GetBaseAddress().GetLoadAddress(&target);
- if (addr != LLDB_INVALID_ADDRESS)
- addrs.push_back(addr);
- }
- }
+DynamicLoaderHexagonDYLD::GetStepThroughTrampolinePlan(Thread &thread,
+ bool stop) {
+ ThreadPlanSP thread_plan_sp;
+
+ StackFrame *frame = thread.GetStackFrameAtIndex(0).get();
+ const SymbolContext &context = frame->GetSymbolContext(eSymbolContextSymbol);
+ Symbol *sym = context.symbol;
- if (addrs.size() > 0)
- {
- AddressVector::iterator start = addrs.begin();
- AddressVector::iterator end = addrs.end();
-
- std::sort(start, end);
- addrs.erase(std::unique(start, end), end);
- thread_plan_sp.reset(new ThreadPlanRunToAddress(thread, addrs, stop));
- }
+ if (sym == NULL || !sym->IsTrampoline())
+ return thread_plan_sp;
+
+ const ConstString sym_name = sym->GetMangled().GetName(
+ lldb::eLanguageTypeUnknown, Mangled::ePreferMangled);
+ if (!sym_name)
+ return thread_plan_sp;
+ SymbolContextList target_symbols;
+ Target &target = thread.GetProcess()->GetTarget();
+ const ModuleList &images = target.GetImages();
+
+ images.FindSymbolsWithNameAndType(sym_name, eSymbolTypeCode, target_symbols);
+ size_t num_targets = target_symbols.GetSize();
+ if (!num_targets)
return thread_plan_sp;
+
+ typedef std::vector<lldb::addr_t> AddressVector;
+ AddressVector addrs;
+ for (size_t i = 0; i < num_targets; ++i) {
+ SymbolContext context;
+ AddressRange range;
+ if (target_symbols.GetContextAtIndex(i, context)) {
+ context.GetAddressRange(eSymbolContextEverything, 0, false, range);
+ lldb::addr_t addr = range.GetBaseAddress().GetLoadAddress(&target);
+ if (addr != LLDB_INVALID_ADDRESS)
+ addrs.push_back(addr);
+ }
+ }
+
+ if (addrs.size() > 0) {
+ AddressVector::iterator start = addrs.begin();
+ AddressVector::iterator end = addrs.end();
+
+ std::sort(start, end);
+ addrs.erase(std::unique(start, end), end);
+ thread_plan_sp.reset(new ThreadPlanRunToAddress(thread, addrs, stop));
+ }
+
+ return thread_plan_sp;
}
/// Helper for the entry breakpoint callback. Resolves the load addresses
/// of all dependent modules.
-void
-DynamicLoaderHexagonDYLD::LoadAllCurrentModules()
-{
- HexagonDYLDRendezvous::iterator I;
- HexagonDYLDRendezvous::iterator E;
- ModuleList module_list;
-
- if (!m_rendezvous.Resolve())
- {
- Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
- if (log)
- log->Printf("DynamicLoaderHexagonDYLD::%s unable to resolve rendezvous address", __FUNCTION__);
- return;
- }
-
- // The rendezvous class doesn't enumerate the main module, so track
- // that ourselves here.
- ModuleSP executable = GetTargetExecutable();
- m_loaded_modules[executable] = m_rendezvous.GetLinkMapAddress();
-
+void DynamicLoaderHexagonDYLD::LoadAllCurrentModules() {
+ HexagonDYLDRendezvous::iterator I;
+ HexagonDYLDRendezvous::iterator E;
+ ModuleList module_list;
- for (I = m_rendezvous.begin(), E = m_rendezvous.end(); I != E; ++I)
- {
- const char *module_path = I->path.c_str();
- FileSpec file(module_path, false);
- ModuleSP module_sp = LoadModuleAtAddress(file, I->link_addr, I->base_addr, true);
- if (module_sp.get())
- {
- module_list.Append(module_sp);
- }
- else
- {
- Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
- if (log)
- log->Printf("DynamicLoaderHexagonDYLD::%s failed loading module %s at 0x%" PRIx64,
- __FUNCTION__, module_path, I->base_addr);
- }
+ if (!m_rendezvous.Resolve()) {
+ Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
+ if (log)
+ log->Printf(
+ "DynamicLoaderHexagonDYLD::%s unable to resolve rendezvous address",
+ __FUNCTION__);
+ return;
+ }
+
+ // The rendezvous class doesn't enumerate the main module, so track
+ // that ourselves here.
+ ModuleSP executable = GetTargetExecutable();
+ m_loaded_modules[executable] = m_rendezvous.GetLinkMapAddress();
+
+ for (I = m_rendezvous.begin(), E = m_rendezvous.end(); I != E; ++I) {
+ const char *module_path = I->path.c_str();
+ FileSpec file(module_path, false);
+ ModuleSP module_sp =
+ LoadModuleAtAddress(file, I->link_addr, I->base_addr, true);
+ if (module_sp.get()) {
+ module_list.Append(module_sp);
+ } else {
+ Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
+ if (log)
+ log->Printf("DynamicLoaderHexagonDYLD::%s failed loading module %s at "
+ "0x%" PRIx64,
+ __FUNCTION__, module_path, I->base_addr);
}
+ }
- m_process->GetTarget().ModulesDidLoad(module_list);
+ m_process->GetTarget().ModulesDidLoad(module_list);
}
/// Computes a value for m_load_offset returning the computed address on
/// success and LLDB_INVALID_ADDRESS on failure.
-addr_t
-DynamicLoaderHexagonDYLD::ComputeLoadOffset()
-{
- // Here we could send a GDB packet to know the load offset
- //
- // send: $qOffsets#4b
- // get: Text=0;Data=0;Bss=0
- //
- // Currently qOffsets is not supported by pluginProcessGDBRemote
- //
- return 0;
+addr_t DynamicLoaderHexagonDYLD::ComputeLoadOffset() {
+ // Here we could send a GDB packet to know the load offset
+ //
+ // send: $qOffsets#4b
+ // get: Text=0;Data=0;Bss=0
+ //
+ // Currently qOffsets is not supported by pluginProcessGDBRemote
+ //
+ return 0;
}
// Here we must try to read the entry point directly from
@@ -596,100 +524,97 @@ DynamicLoaderHexagonDYLD::ComputeLoadOff
// an alternative is to look at the PC if we can be sure
// that we have connected when the process is at the entry point.
// I dont think that is reliable for us.
-addr_t
-DynamicLoaderHexagonDYLD::GetEntryPoint()
-{
- if (m_entry_point != LLDB_INVALID_ADDRESS)
- return m_entry_point;
- // check we have a valid process
- if ( m_process == nullptr )
- return LLDB_INVALID_ADDRESS;
- // Get the current executable module
- Module & module = *( m_process->GetTarget( ).GetExecutableModule( ).get( ) );
- // Get the object file (elf file) for this module
- lldb_private::ObjectFile &object = *( module.GetObjectFile( ) );
- // Check if the file is executable (ie, not shared object or relocatable)
- if ( object.IsExecutable() )
- {
- // Get the entry point address for this object
- lldb_private::Address entry = object.GetEntryPointAddress( );
- // Return the entry point address
- return entry.GetFileAddress( );
- }
- // No idea so back out
+addr_t DynamicLoaderHexagonDYLD::GetEntryPoint() {
+ if (m_entry_point != LLDB_INVALID_ADDRESS)
+ return m_entry_point;
+ // check we have a valid process
+ if (m_process == nullptr)
return LLDB_INVALID_ADDRESS;
+ // Get the current executable module
+ Module &module = *(m_process->GetTarget().GetExecutableModule().get());
+ // Get the object file (elf file) for this module
+ lldb_private::ObjectFile &object = *(module.GetObjectFile());
+ // Check if the file is executable (ie, not shared object or relocatable)
+ if (object.IsExecutable()) {
+ // Get the entry point address for this object
+ lldb_private::Address entry = object.GetEntryPointAddress();
+ // Return the entry point address
+ return entry.GetFileAddress();
+ }
+ // No idea so back out
+ return LLDB_INVALID_ADDRESS;
+}
+
+const SectionList *DynamicLoaderHexagonDYLD::GetSectionListFromModule(
+ const ModuleSP module) const {
+ SectionList *sections = nullptr;
+ if (module.get()) {
+ ObjectFile *obj_file = module->GetObjectFile();
+ if (obj_file) {
+ sections = obj_file->GetSectionList();
+ }
+ }
+ return sections;
+}
+
+static int ReadInt(Process *process, addr_t addr) {
+ Error error;
+ int value = (int)process->ReadUnsignedIntegerFromMemory(
+ addr, sizeof(uint32_t), 0, error);
+ if (error.Fail())
+ return -1;
+ else
+ return value;
}
-const SectionList *
-DynamicLoaderHexagonDYLD::GetSectionListFromModule(const ModuleSP module) const
-{
- SectionList *sections = nullptr;
- if (module.get())
- {
- ObjectFile *obj_file = module->GetObjectFile();
- if (obj_file)
- {
- sections = obj_file->GetSectionList();
- }
- }
- return sections;
-}
+lldb::addr_t
+DynamicLoaderHexagonDYLD::GetThreadLocalData(const lldb::ModuleSP module,
+ const lldb::ThreadSP thread,
+ lldb::addr_t tls_file_addr) {
+ auto it = m_loaded_modules.find(module);
+ if (it == m_loaded_modules.end())
+ return LLDB_INVALID_ADDRESS;
-static int ReadInt(Process *process, addr_t addr)
-{
- Error error;
- int value = (int)process->ReadUnsignedIntegerFromMemory(addr, sizeof(uint32_t), 0, error);
- if (error.Fail())
- return -1;
- else
- return value;
-}
+ addr_t link_map = it->second;
+ if (link_map == LLDB_INVALID_ADDRESS)
+ return LLDB_INVALID_ADDRESS;
-lldb::addr_t
-DynamicLoaderHexagonDYLD::GetThreadLocalData(const lldb::ModuleSP module, const lldb::ThreadSP thread,
- lldb::addr_t tls_file_addr)
-{
- auto it = m_loaded_modules.find (module);
- if (it == m_loaded_modules.end())
- return LLDB_INVALID_ADDRESS;
-
- addr_t link_map = it->second;
- if (link_map == LLDB_INVALID_ADDRESS)
- return LLDB_INVALID_ADDRESS;
-
- const HexagonDYLDRendezvous::ThreadInfo &metadata = m_rendezvous.GetThreadInfo();
- if (!metadata.valid)
- return LLDB_INVALID_ADDRESS;
-
- // Get the thread pointer.
- addr_t tp = thread->GetThreadPointer ();
- if (tp == LLDB_INVALID_ADDRESS)
- return LLDB_INVALID_ADDRESS;
-
- // Find the module's modid.
- int modid = ReadInt (m_process, link_map + metadata.modid_offset);
- if (modid == -1)
- return LLDB_INVALID_ADDRESS;
-
- // Lookup the DTV structure for this thread.
- addr_t dtv_ptr = tp + metadata.dtv_offset;
- addr_t dtv = ReadPointer (dtv_ptr);
- if (dtv == LLDB_INVALID_ADDRESS)
- return LLDB_INVALID_ADDRESS;
-
- // Find the TLS block for this module.
- addr_t dtv_slot = dtv + metadata.dtv_slot_size*modid;
- addr_t tls_block = ReadPointer (dtv_slot + metadata.tls_offset);
+ const HexagonDYLDRendezvous::ThreadInfo &metadata =
+ m_rendezvous.GetThreadInfo();
+ if (!metadata.valid)
+ return LLDB_INVALID_ADDRESS;
- Module *mod = module.get();
- Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
- if (log)
- log->Printf("DynamicLoaderHexagonDYLD::Performed TLS lookup: "
- "module=%s, link_map=0x%" PRIx64 ", tp=0x%" PRIx64 ", modid=%i, tls_block=0x%" PRIx64,
- mod->GetObjectName().AsCString(""), link_map, tp, modid, tls_block);
-
- if (tls_block == LLDB_INVALID_ADDRESS)
- return LLDB_INVALID_ADDRESS;
- else
- return tls_block + tls_file_addr;
+ // Get the thread pointer.
+ addr_t tp = thread->GetThreadPointer();
+ if (tp == LLDB_INVALID_ADDRESS)
+ return LLDB_INVALID_ADDRESS;
+
+ // Find the module's modid.
+ int modid = ReadInt(m_process, link_map + metadata.modid_offset);
+ if (modid == -1)
+ return LLDB_INVALID_ADDRESS;
+
+ // Lookup the DTV structure for this thread.
+ addr_t dtv_ptr = tp + metadata.dtv_offset;
+ addr_t dtv = ReadPointer(dtv_ptr);
+ if (dtv == LLDB_INVALID_ADDRESS)
+ return LLDB_INVALID_ADDRESS;
+
+ // Find the TLS block for this module.
+ addr_t dtv_slot = dtv + metadata.dtv_slot_size * modid;
+ addr_t tls_block = ReadPointer(dtv_slot + metadata.tls_offset);
+
+ Module *mod = module.get();
+ Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
+ if (log)
+ log->Printf("DynamicLoaderHexagonDYLD::Performed TLS lookup: "
+ "module=%s, link_map=0x%" PRIx64 ", tp=0x%" PRIx64
+ ", modid=%i, tls_block=0x%" PRIx64,
+ mod->GetObjectName().AsCString(""), link_map, tp, modid,
+ tls_block);
+
+ if (tls_block == LLDB_INVALID_ADDRESS)
+ return LLDB_INVALID_ADDRESS;
+ else
+ return tls_block + tls_file_addr;
}
Modified: lldb/trunk/source/Plugins/DynamicLoader/Hexagon-DYLD/DynamicLoaderHexagonDYLD.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/Hexagon-DYLD/DynamicLoaderHexagonDYLD.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/Hexagon-DYLD/DynamicLoaderHexagonDYLD.h (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/Hexagon-DYLD/DynamicLoaderHexagonDYLD.h Tue Sep 6 15:57:50 2016
@@ -19,150 +19,129 @@
#include "HexagonDYLDRendezvous.h"
-class DynamicLoaderHexagonDYLD : public lldb_private::DynamicLoader
-{
+class DynamicLoaderHexagonDYLD : public lldb_private::DynamicLoader {
public:
- DynamicLoaderHexagonDYLD(lldb_private::Process *process);
+ DynamicLoaderHexagonDYLD(lldb_private::Process *process);
- ~DynamicLoaderHexagonDYLD() override;
+ ~DynamicLoaderHexagonDYLD() override;
- static void
- Initialize();
+ static void Initialize();
- static void
- Terminate();
+ static void Terminate();
- static lldb_private::ConstString
- GetPluginNameStatic();
+ static lldb_private::ConstString GetPluginNameStatic();
- static const char *
- GetPluginDescriptionStatic();
+ static const char *GetPluginDescriptionStatic();
- static lldb_private::DynamicLoader *
- CreateInstance(lldb_private::Process *process, bool force);
+ static lldb_private::DynamicLoader *
+ CreateInstance(lldb_private::Process *process, bool force);
- //------------------------------------------------------------------
- // DynamicLoader protocol
- //------------------------------------------------------------------
+ //------------------------------------------------------------------
+ // DynamicLoader protocol
+ //------------------------------------------------------------------
- void
- DidAttach() override;
+ void DidAttach() override;
- void
- DidLaunch() override;
+ void DidLaunch() override;
- lldb::ThreadPlanSP
- GetStepThroughTrampolinePlan(lldb_private::Thread &thread,
- bool stop_others) override;
+ lldb::ThreadPlanSP GetStepThroughTrampolinePlan(lldb_private::Thread &thread,
+ bool stop_others) override;
- lldb_private::Error
- CanLoadImage() override;
+ lldb_private::Error CanLoadImage() override;
- lldb::addr_t
- GetThreadLocalData(const lldb::ModuleSP module, const lldb::ThreadSP thread, lldb::addr_t tls_file_addr) override;
+ lldb::addr_t GetThreadLocalData(const lldb::ModuleSP module,
+ const lldb::ThreadSP thread,
+ lldb::addr_t tls_file_addr) override;
- //------------------------------------------------------------------
- // PluginInterface protocol
- //------------------------------------------------------------------
- lldb_private::ConstString
- GetPluginName() override;
+ //------------------------------------------------------------------
+ // PluginInterface protocol
+ //------------------------------------------------------------------
+ lldb_private::ConstString GetPluginName() override;
- uint32_t
- GetPluginVersion() override;
+ uint32_t GetPluginVersion() override;
protected:
- /// Runtime linker rendezvous structure.
- HexagonDYLDRendezvous m_rendezvous;
+ /// Runtime linker rendezvous structure.
+ HexagonDYLDRendezvous m_rendezvous;
- /// Virtual load address of the inferior process.
- lldb::addr_t m_load_offset;
+ /// Virtual load address of the inferior process.
+ lldb::addr_t m_load_offset;
- /// Virtual entry address of the inferior process.
- lldb::addr_t m_entry_point;
+ /// Virtual entry address of the inferior process.
+ lldb::addr_t m_entry_point;
- /// Rendezvous breakpoint.
- lldb::break_id_t m_dyld_bid;
-
- /// Loaded module list. (link map for each module)
- std::map<lldb::ModuleWP, lldb::addr_t, std::owner_less<lldb::ModuleWP>> m_loaded_modules;
-
- /// Enables a breakpoint on a function called by the runtime
- /// linker each time a module is loaded or unloaded.
- bool
- SetRendezvousBreakpoint();
-
- /// Callback routine which updates the current list of loaded modules based
- /// on the information supplied by the runtime linker.
- static bool
- RendezvousBreakpointHit(void *baton,
- lldb_private::StoppointCallbackContext *context,
- lldb::user_id_t break_id,
- lldb::user_id_t break_loc_id);
-
- /// Helper method for RendezvousBreakpointHit. Updates LLDB's current set
- /// of loaded modules.
- void
- RefreshModules();
-
- /// Updates the load address of every allocatable section in @p module.
- ///
- /// @param module The module to traverse.
- ///
- /// @param link_map_addr The virtual address of the link map for the @p module.
- ///
- /// @param base_addr The virtual base address @p module is loaded at.
- void
- UpdateLoadedSections(lldb::ModuleSP module,
- lldb::addr_t link_map_addr,
- lldb::addr_t base_addr,
- bool base_addr_is_offset) override;
-
- /// Removes the loaded sections from the target in @p module.
- ///
- /// @param module The module to traverse.
- void
- UnloadSections(const lldb::ModuleSP module) override;
-
- /// Callback routine invoked when we hit the breakpoint on process entry.
- ///
- /// This routine is responsible for resolving the load addresses of all
- /// dependent modules required by the inferior and setting up the rendezvous
- /// breakpoint.
- static bool
- EntryBreakpointHit(void *baton,
- lldb_private::StoppointCallbackContext *context,
- lldb::user_id_t break_id,
- lldb::user_id_t break_loc_id);
-
- /// Helper for the entry breakpoint callback. Resolves the load addresses
- /// of all dependent modules.
- void
- LoadAllCurrentModules();
-
- /// Computes a value for m_load_offset returning the computed address on
- /// success and LLDB_INVALID_ADDRESS on failure.
- lldb::addr_t
- ComputeLoadOffset();
-
- /// Computes a value for m_entry_point returning the computed address on
- /// success and LLDB_INVALID_ADDRESS on failure.
- lldb::addr_t
- GetEntryPoint();
-
- /// Checks to see if the target module has changed, updates the target
- /// accordingly and returns the target executable module.
- lldb::ModuleSP
- GetTargetExecutable();
-
- /// return the address of the Rendezvous breakpoint
- lldb::addr_t
- FindRendezvousBreakpointAddress( );
+ /// Rendezvous breakpoint.
+ lldb::break_id_t m_dyld_bid;
+
+ /// Loaded module list. (link map for each module)
+ std::map<lldb::ModuleWP, lldb::addr_t, std::owner_less<lldb::ModuleWP>>
+ m_loaded_modules;
+
+ /// Enables a breakpoint on a function called by the runtime
+ /// linker each time a module is loaded or unloaded.
+ bool SetRendezvousBreakpoint();
+
+ /// Callback routine which updates the current list of loaded modules based
+ /// on the information supplied by the runtime linker.
+ static bool RendezvousBreakpointHit(
+ void *baton, lldb_private::StoppointCallbackContext *context,
+ lldb::user_id_t break_id, lldb::user_id_t break_loc_id);
+
+ /// Helper method for RendezvousBreakpointHit. Updates LLDB's current set
+ /// of loaded modules.
+ void RefreshModules();
+
+ /// Updates the load address of every allocatable section in @p module.
+ ///
+ /// @param module The module to traverse.
+ ///
+ /// @param link_map_addr The virtual address of the link map for the @p
+ /// module.
+ ///
+ /// @param base_addr The virtual base address @p module is loaded at.
+ void UpdateLoadedSections(lldb::ModuleSP module, lldb::addr_t link_map_addr,
+ lldb::addr_t base_addr,
+ bool base_addr_is_offset) override;
+
+ /// Removes the loaded sections from the target in @p module.
+ ///
+ /// @param module The module to traverse.
+ void UnloadSections(const lldb::ModuleSP module) override;
+
+ /// Callback routine invoked when we hit the breakpoint on process entry.
+ ///
+ /// This routine is responsible for resolving the load addresses of all
+ /// dependent modules required by the inferior and setting up the rendezvous
+ /// breakpoint.
+ static bool
+ EntryBreakpointHit(void *baton,
+ lldb_private::StoppointCallbackContext *context,
+ lldb::user_id_t break_id, lldb::user_id_t break_loc_id);
+
+ /// Helper for the entry breakpoint callback. Resolves the load addresses
+ /// of all dependent modules.
+ void LoadAllCurrentModules();
+
+ /// Computes a value for m_load_offset returning the computed address on
+ /// success and LLDB_INVALID_ADDRESS on failure.
+ lldb::addr_t ComputeLoadOffset();
+
+ /// Computes a value for m_entry_point returning the computed address on
+ /// success and LLDB_INVALID_ADDRESS on failure.
+ lldb::addr_t GetEntryPoint();
+
+ /// Checks to see if the target module has changed, updates the target
+ /// accordingly and returns the target executable module.
+ lldb::ModuleSP GetTargetExecutable();
+
+ /// return the address of the Rendezvous breakpoint
+ lldb::addr_t FindRendezvousBreakpointAddress();
private:
- const lldb_private::SectionList *
- GetSectionListFromModule(const lldb::ModuleSP module) const;
+ const lldb_private::SectionList *
+ GetSectionListFromModule(const lldb::ModuleSP module) const;
- DISALLOW_COPY_AND_ASSIGN(DynamicLoaderHexagonDYLD);
+ DISALLOW_COPY_AND_ASSIGN(DynamicLoaderHexagonDYLD);
};
#endif // liblldb_DynamicLoaderHexagonDYLD_h_
Modified: lldb/trunk/source/Plugins/DynamicLoader/Hexagon-DYLD/HexagonDYLDRendezvous.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/Hexagon-DYLD/HexagonDYLDRendezvous.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/Hexagon-DYLD/HexagonDYLDRendezvous.cpp (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/Hexagon-DYLD/HexagonDYLDRendezvous.cpp Tue Sep 6 15:57:50 2016
@@ -30,375 +30,343 @@ using namespace lldb_private;
/// Locates the address of the rendezvous structure. Returns the address on
/// success and LLDB_INVALID_ADDRESS on failure.
-static addr_t
-ResolveRendezvousAddress(Process *process)
-{
- addr_t info_location;
- addr_t info_addr;
- Error error;
-
- info_location = process->GetImageInfoAddress();
-
- if (info_location == LLDB_INVALID_ADDRESS)
- return LLDB_INVALID_ADDRESS;
-
- info_addr = process->ReadPointerFromMemory(info_location, error);
- if (error.Fail())
- return LLDB_INVALID_ADDRESS;
+static addr_t ResolveRendezvousAddress(Process *process) {
+ addr_t info_location;
+ addr_t info_addr;
+ Error error;
- if (info_addr == 0)
- return LLDB_INVALID_ADDRESS;
+ info_location = process->GetImageInfoAddress();
- return info_addr;
+ if (info_location == LLDB_INVALID_ADDRESS)
+ return LLDB_INVALID_ADDRESS;
+
+ info_addr = process->ReadPointerFromMemory(info_location, error);
+ if (error.Fail())
+ return LLDB_INVALID_ADDRESS;
+
+ if (info_addr == 0)
+ return LLDB_INVALID_ADDRESS;
+
+ return info_addr;
}
HexagonDYLDRendezvous::HexagonDYLDRendezvous(Process *process)
- : m_process(process),
- m_rendezvous_addr(LLDB_INVALID_ADDRESS),
- m_current(),
- m_previous(),
- m_soentries(),
- m_added_soentries(),
- m_removed_soentries()
-{
- m_thread_info.valid = false;
-
- // Cache a copy of the executable path
- if (m_process)
- {
- Module *exe_mod = m_process->GetTarget().GetExecutableModulePointer();
- if (exe_mod)
- exe_mod->GetFileSpec().GetPath(m_exe_path, PATH_MAX);
- }
+ : m_process(process), m_rendezvous_addr(LLDB_INVALID_ADDRESS), m_current(),
+ m_previous(), m_soentries(), m_added_soentries(), m_removed_soentries() {
+ m_thread_info.valid = false;
+
+ // Cache a copy of the executable path
+ if (m_process) {
+ Module *exe_mod = m_process->GetTarget().GetExecutableModulePointer();
+ if (exe_mod)
+ exe_mod->GetFileSpec().GetPath(m_exe_path, PATH_MAX);
+ }
+}
+
+bool HexagonDYLDRendezvous::Resolve() {
+ const size_t word_size = 4;
+ Rendezvous info;
+ size_t address_size;
+ size_t padding;
+ addr_t info_addr;
+ addr_t cursor;
+
+ address_size = m_process->GetAddressByteSize();
+ padding = address_size - word_size;
+
+ if (m_rendezvous_addr == LLDB_INVALID_ADDRESS)
+ cursor = info_addr = ResolveRendezvousAddress(m_process);
+ else
+ cursor = info_addr = m_rendezvous_addr;
+
+ if (cursor == LLDB_INVALID_ADDRESS)
+ return false;
+
+ if (!(cursor = ReadWord(cursor, &info.version, word_size)))
+ return false;
+
+ if (!(cursor = ReadPointer(cursor + padding, &info.map_addr)))
+ return false;
+
+ if (!(cursor = ReadPointer(cursor, &info.brk)))
+ return false;
+
+ if (!(cursor = ReadWord(cursor, &info.state, word_size)))
+ return false;
+
+ if (!(cursor = ReadPointer(cursor + padding, &info.ldbase)))
+ return false;
+
+ // The rendezvous was successfully read. Update our internal state.
+ m_rendezvous_addr = info_addr;
+ m_previous = m_current;
+ m_current = info;
+
+ return UpdateSOEntries();
+}
+
+void HexagonDYLDRendezvous::SetRendezvousAddress(lldb::addr_t addr) {
+ m_rendezvous_addr = addr;
+}
+
+bool HexagonDYLDRendezvous::IsValid() {
+ return m_rendezvous_addr != LLDB_INVALID_ADDRESS;
}
-bool
-HexagonDYLDRendezvous::Resolve()
-{
- const size_t word_size = 4;
- Rendezvous info;
- size_t address_size;
- size_t padding;
- addr_t info_addr;
- addr_t cursor;
-
- address_size = m_process->GetAddressByteSize();
- padding = address_size - word_size;
-
- if (m_rendezvous_addr == LLDB_INVALID_ADDRESS)
- cursor = info_addr = ResolveRendezvousAddress(m_process);
- else
- cursor = info_addr = m_rendezvous_addr;
-
- if (cursor == LLDB_INVALID_ADDRESS)
- return false;
-
- if (!(cursor = ReadWord(cursor, &info.version, word_size)))
- return false;
-
- if (!(cursor = ReadPointer(cursor + padding, &info.map_addr)))
- return false;
-
- if (!(cursor = ReadPointer(cursor, &info.brk)))
- return false;
-
- if (!(cursor = ReadWord(cursor, &info.state, word_size)))
- return false;
-
- if (!(cursor = ReadPointer(cursor + padding, &info.ldbase)))
- return false;
-
- // The rendezvous was successfully read. Update our internal state.
- m_rendezvous_addr = info_addr;
- m_previous = m_current;
- m_current = info;
-
- return UpdateSOEntries();
-}
-
-void
-HexagonDYLDRendezvous::SetRendezvousAddress( lldb::addr_t addr )
-{
- m_rendezvous_addr = addr;
-}
-
-bool
-HexagonDYLDRendezvous::IsValid()
-{
- return m_rendezvous_addr != LLDB_INVALID_ADDRESS;
-}
-
-bool
-HexagonDYLDRendezvous::UpdateSOEntries()
-{
- SOEntry entry;
-
- if (m_current.map_addr == 0)
- return false;
-
- // When the previous and current states are consistent this is the first
- // time we have been asked to update. Just take a snapshot of the currently
- // loaded modules.
- if (m_previous.state == eConsistent && m_current.state == eConsistent)
- return TakeSnapshot(m_soentries);
-
- // If we are about to add or remove a shared object clear out the current
- // state and take a snapshot of the currently loaded images.
- if (m_current.state == eAdd || m_current.state == eDelete)
- {
- // this is a fudge so that we can clear the assert below.
- m_previous.state = eConsistent;
- // We hit this assert on the 2nd run of this function after running the calc example
- assert(m_previous.state == eConsistent);
- m_soentries.clear();
- m_added_soentries.clear();
- m_removed_soentries.clear();
- return TakeSnapshot(m_soentries);
+bool HexagonDYLDRendezvous::UpdateSOEntries() {
+ SOEntry entry;
+
+ if (m_current.map_addr == 0)
+ return false;
+
+ // When the previous and current states are consistent this is the first
+ // time we have been asked to update. Just take a snapshot of the currently
+ // loaded modules.
+ if (m_previous.state == eConsistent && m_current.state == eConsistent)
+ return TakeSnapshot(m_soentries);
+
+ // If we are about to add or remove a shared object clear out the current
+ // state and take a snapshot of the currently loaded images.
+ if (m_current.state == eAdd || m_current.state == eDelete) {
+ // this is a fudge so that we can clear the assert below.
+ m_previous.state = eConsistent;
+ // We hit this assert on the 2nd run of this function after running the calc
+ // example
+ assert(m_previous.state == eConsistent);
+ m_soentries.clear();
+ m_added_soentries.clear();
+ m_removed_soentries.clear();
+ return TakeSnapshot(m_soentries);
+ }
+ assert(m_current.state == eConsistent);
+
+ // Otherwise check the previous state to determine what to expect and update
+ // accordingly.
+ if (m_previous.state == eAdd)
+ return UpdateSOEntriesForAddition();
+ else if (m_previous.state == eDelete)
+ return UpdateSOEntriesForDeletion();
+
+ return false;
+}
+
+bool HexagonDYLDRendezvous::UpdateSOEntriesForAddition() {
+ SOEntry entry;
+ iterator pos;
+
+ assert(m_previous.state == eAdd);
+
+ if (m_current.map_addr == 0)
+ return false;
+
+ for (addr_t cursor = m_current.map_addr; cursor != 0; cursor = entry.next) {
+ if (!ReadSOEntryFromMemory(cursor, entry))
+ return false;
+
+ // Only add shared libraries and not the executable.
+ // On Linux this is indicated by an empty path in the entry.
+ // On FreeBSD it is the name of the executable.
+ if (entry.path.empty() || ::strcmp(entry.path.c_str(), m_exe_path) == 0)
+ continue;
+
+ pos = std::find(m_soentries.begin(), m_soentries.end(), entry);
+ if (pos == m_soentries.end()) {
+ m_soentries.push_back(entry);
+ m_added_soentries.push_back(entry);
}
- assert(m_current.state == eConsistent);
+ }
- // Otherwise check the previous state to determine what to expect and update
- // accordingly.
- if (m_previous.state == eAdd)
- return UpdateSOEntriesForAddition();
- else if (m_previous.state == eDelete)
- return UpdateSOEntriesForDeletion();
+ return true;
+}
+
+bool HexagonDYLDRendezvous::UpdateSOEntriesForDeletion() {
+ SOEntryList entry_list;
+ iterator pos;
+ assert(m_previous.state == eDelete);
+
+ if (!TakeSnapshot(entry_list))
return false;
+
+ for (iterator I = begin(); I != end(); ++I) {
+ pos = std::find(entry_list.begin(), entry_list.end(), *I);
+ if (pos == entry_list.end())
+ m_removed_soentries.push_back(*I);
+ }
+
+ m_soentries = entry_list;
+ return true;
}
-
-bool
-HexagonDYLDRendezvous::UpdateSOEntriesForAddition()
-{
- SOEntry entry;
- iterator pos;
-
- assert(m_previous.state == eAdd);
-
- if (m_current.map_addr == 0)
- return false;
-
- for (addr_t cursor = m_current.map_addr; cursor != 0; cursor = entry.next)
- {
- if (!ReadSOEntryFromMemory(cursor, entry))
- return false;
-
- // Only add shared libraries and not the executable.
- // On Linux this is indicated by an empty path in the entry.
- // On FreeBSD it is the name of the executable.
- if (entry.path.empty() || ::strcmp(entry.path.c_str(), m_exe_path) == 0)
- continue;
-
- pos = std::find(m_soentries.begin(), m_soentries.end(), entry);
- if (pos == m_soentries.end())
- {
- m_soentries.push_back(entry);
- m_added_soentries.push_back(entry);
- }
- }
- return true;
+bool HexagonDYLDRendezvous::TakeSnapshot(SOEntryList &entry_list) {
+ SOEntry entry;
+
+ if (m_current.map_addr == 0)
+ return false;
+
+ for (addr_t cursor = m_current.map_addr; cursor != 0; cursor = entry.next) {
+ if (!ReadSOEntryFromMemory(cursor, entry))
+ return false;
+
+ // Only add shared libraries and not the executable.
+ // On Linux this is indicated by an empty path in the entry.
+ // On FreeBSD it is the name of the executable.
+ if (entry.path.empty() || ::strcmp(entry.path.c_str(), m_exe_path) == 0)
+ continue;
+
+ entry_list.push_back(entry);
+ }
+
+ return true;
}
-bool
-HexagonDYLDRendezvous::UpdateSOEntriesForDeletion()
-{
- SOEntryList entry_list;
- iterator pos;
+addr_t HexagonDYLDRendezvous::ReadWord(addr_t addr, uint64_t *dst,
+ size_t size) {
+ Error error;
- assert(m_previous.state == eDelete);
+ *dst = m_process->ReadUnsignedIntegerFromMemory(addr, size, 0, error);
+ if (error.Fail())
+ return 0;
- if (!TakeSnapshot(entry_list))
- return false;
+ return addr + size;
+}
- for (iterator I = begin(); I != end(); ++I)
- {
- pos = std::find(entry_list.begin(), entry_list.end(), *I);
- if (pos == entry_list.end())
- m_removed_soentries.push_back(*I);
- }
+addr_t HexagonDYLDRendezvous::ReadPointer(addr_t addr, addr_t *dst) {
+ Error error;
- m_soentries = entry_list;
- return true;
+ *dst = m_process->ReadPointerFromMemory(addr, error);
+ if (error.Fail())
+ return 0;
+
+ return addr + m_process->GetAddressByteSize();
}
-bool
-HexagonDYLDRendezvous::TakeSnapshot(SOEntryList &entry_list)
-{
- SOEntry entry;
-
- if (m_current.map_addr == 0)
- return false;
-
- for (addr_t cursor = m_current.map_addr; cursor != 0; cursor = entry.next)
- {
- if (!ReadSOEntryFromMemory(cursor, entry))
- return false;
-
- // Only add shared libraries and not the executable.
- // On Linux this is indicated by an empty path in the entry.
- // On FreeBSD it is the name of the executable.
- if (entry.path.empty() || ::strcmp(entry.path.c_str(), m_exe_path) == 0)
- continue;
+std::string HexagonDYLDRendezvous::ReadStringFromMemory(addr_t addr) {
+ std::string str;
+ Error error;
+ size_t size;
+ char c;
+
+ if (addr == LLDB_INVALID_ADDRESS)
+ return std::string();
- entry_list.push_back(entry);
+ for (;;) {
+ size = m_process->DoReadMemory(addr, &c, 1, error);
+ if (size != 1 || error.Fail())
+ return std::string();
+ if (c == 0)
+ break;
+ else {
+ str.push_back(c);
+ addr++;
}
+ }
- return true;
+ return str;
}
-addr_t
-HexagonDYLDRendezvous::ReadWord(addr_t addr, uint64_t *dst, size_t size)
-{
- Error error;
-
- *dst = m_process->ReadUnsignedIntegerFromMemory(addr, size, 0, error);
- if (error.Fail())
- return 0;
-
- return addr + size;
-}
-
-addr_t
-HexagonDYLDRendezvous::ReadPointer(addr_t addr, addr_t *dst)
-{
- Error error;
-
- *dst = m_process->ReadPointerFromMemory(addr, error);
- if (error.Fail())
- return 0;
-
- return addr + m_process->GetAddressByteSize();
-}
-
-std::string
-HexagonDYLDRendezvous::ReadStringFromMemory(addr_t addr)
-{
- std::string str;
- Error error;
- size_t size;
- char c;
-
- if (addr == LLDB_INVALID_ADDRESS)
- return std::string();
-
- for (;;) {
- size = m_process->DoReadMemory(addr, &c, 1, error);
- if (size != 1 || error.Fail())
- return std::string();
- if (c == 0)
- break;
- else {
- str.push_back(c);
- addr++;
- }
- }
+bool HexagonDYLDRendezvous::ReadSOEntryFromMemory(lldb::addr_t addr,
+ SOEntry &entry) {
+ entry.clear();
+ entry.link_addr = addr;
+
+ if (!(addr = ReadPointer(addr, &entry.base_addr)))
+ return false;
+
+ if (!(addr = ReadPointer(addr, &entry.path_addr)))
+ return false;
+
+ if (!(addr = ReadPointer(addr, &entry.dyn_addr)))
+ return false;
+
+ if (!(addr = ReadPointer(addr, &entry.next)))
+ return false;
+
+ if (!(addr = ReadPointer(addr, &entry.prev)))
+ return false;
+
+ entry.path = ReadStringFromMemory(entry.path_addr);
- return str;
+ return true;
}
-bool
-HexagonDYLDRendezvous::ReadSOEntryFromMemory(lldb::addr_t addr, SOEntry &entry)
-{
- entry.clear();
- entry.link_addr = addr;
-
- if (!(addr = ReadPointer(addr, &entry.base_addr)))
- return false;
-
- if (!(addr = ReadPointer(addr, &entry.path_addr)))
- return false;
-
- if (!(addr = ReadPointer(addr, &entry.dyn_addr)))
- return false;
-
- if (!(addr = ReadPointer(addr, &entry.next)))
- return false;
-
- if (!(addr = ReadPointer(addr, &entry.prev)))
- return false;
-
- entry.path = ReadStringFromMemory(entry.path_addr);
-
- return true;
-}
-
-bool
-HexagonDYLDRendezvous::FindMetadata(const char *name, PThreadField field, uint32_t& value)
-{
- Target& target = m_process->GetTarget();
-
- SymbolContextList list;
- if (!target.GetImages().FindSymbolsWithNameAndType (ConstString(name), eSymbolTypeAny, list))
- return false;
-
- Address address = list[0].symbol->GetAddress();
- addr_t addr = address.GetLoadAddress (&target);
- if (addr == LLDB_INVALID_ADDRESS)
- return false;
-
- Error error;
- value = (uint32_t)m_process->ReadUnsignedIntegerFromMemory(addr + field*sizeof(uint32_t), sizeof(uint32_t), 0, error);
- if (error.Fail())
- return false;
-
- if (field == eSize)
- value /= 8; // convert bits to bytes
-
- return true;
-}
-
-const HexagonDYLDRendezvous::ThreadInfo&
-HexagonDYLDRendezvous::GetThreadInfo()
-{
- if (!m_thread_info.valid)
- {
- bool ok = true;
-
- ok &= FindMetadata ("_thread_db_pthread_dtvp", eOffset, m_thread_info.dtv_offset);
- ok &= FindMetadata ("_thread_db_dtv_dtv", eSize, m_thread_info.dtv_slot_size);
- ok &= FindMetadata ("_thread_db_link_map_l_tls_modid", eOffset, m_thread_info.modid_offset);
- ok &= FindMetadata ("_thread_db_dtv_t_pointer_val", eOffset, m_thread_info.tls_offset);
+bool HexagonDYLDRendezvous::FindMetadata(const char *name, PThreadField field,
+ uint32_t &value) {
+ Target &target = m_process->GetTarget();
- if (ok)
- m_thread_info.valid = true;
- }
+ SymbolContextList list;
+ if (!target.GetImages().FindSymbolsWithNameAndType(ConstString(name),
+ eSymbolTypeAny, list))
+ return false;
+
+ Address address = list[0].symbol->GetAddress();
+ addr_t addr = address.GetLoadAddress(&target);
+ if (addr == LLDB_INVALID_ADDRESS)
+ return false;
- return m_thread_info;
+ Error error;
+ value = (uint32_t)m_process->ReadUnsignedIntegerFromMemory(
+ addr + field * sizeof(uint32_t), sizeof(uint32_t), 0, error);
+ if (error.Fail())
+ return false;
+
+ if (field == eSize)
+ value /= 8; // convert bits to bytes
+
+ return true;
}
-void
-HexagonDYLDRendezvous::DumpToLog(Log *log) const
-{
- int state = GetState();
-
- if (!log)
- return;
-
- log->PutCString("HexagonDYLDRendezvous:");
- log->Printf(" Address: %" PRIx64, GetRendezvousAddress());
- log->Printf(" Version: %" PRIu64, GetVersion());
- log->Printf(" Link : %" PRIx64, GetLinkMapAddress());
- log->Printf(" Break : %" PRIx64, GetBreakAddress());
- log->Printf(" LDBase : %" PRIx64, GetLDBase());
- log->Printf(" State : %s",
- (state == eConsistent) ? "consistent" :
- (state == eAdd) ? "add" :
- (state == eDelete) ? "delete" : "unknown");
-
- iterator I = begin();
- iterator E = end();
-
- if (I != E)
- log->PutCString("HexagonDYLDRendezvous SOEntries:");
-
- for (int i = 1; I != E; ++I, ++i)
- {
- log->Printf("\n SOEntry [%d] %s", i, I->path.c_str());
- log->Printf(" Base : %" PRIx64, I->base_addr);
- log->Printf(" Path : %" PRIx64, I->path_addr);
- log->Printf(" Dyn : %" PRIx64, I->dyn_addr);
- log->Printf(" Next : %" PRIx64, I->next);
- log->Printf(" Prev : %" PRIx64, I->prev);
- }
+const HexagonDYLDRendezvous::ThreadInfo &
+HexagonDYLDRendezvous::GetThreadInfo() {
+ if (!m_thread_info.valid) {
+ bool ok = true;
+
+ ok &= FindMetadata("_thread_db_pthread_dtvp", eOffset,
+ m_thread_info.dtv_offset);
+ ok &=
+ FindMetadata("_thread_db_dtv_dtv", eSize, m_thread_info.dtv_slot_size);
+ ok &= FindMetadata("_thread_db_link_map_l_tls_modid", eOffset,
+ m_thread_info.modid_offset);
+ ok &= FindMetadata("_thread_db_dtv_t_pointer_val", eOffset,
+ m_thread_info.tls_offset);
+
+ if (ok)
+ m_thread_info.valid = true;
+ }
+
+ return m_thread_info;
+}
+
+void HexagonDYLDRendezvous::DumpToLog(Log *log) const {
+ int state = GetState();
+
+ if (!log)
+ return;
+
+ log->PutCString("HexagonDYLDRendezvous:");
+ log->Printf(" Address: %" PRIx64, GetRendezvousAddress());
+ log->Printf(" Version: %" PRIu64, GetVersion());
+ log->Printf(" Link : %" PRIx64, GetLinkMapAddress());
+ log->Printf(" Break : %" PRIx64, GetBreakAddress());
+ log->Printf(" LDBase : %" PRIx64, GetLDBase());
+ log->Printf(" State : %s",
+ (state == eConsistent)
+ ? "consistent"
+ : (state == eAdd) ? "add" : (state == eDelete) ? "delete"
+ : "unknown");
+
+ iterator I = begin();
+ iterator E = end();
+
+ if (I != E)
+ log->PutCString("HexagonDYLDRendezvous SOEntries:");
+
+ for (int i = 1; I != E; ++I, ++i) {
+ log->Printf("\n SOEntry [%d] %s", i, I->path.c_str());
+ log->Printf(" Base : %" PRIx64, I->base_addr);
+ log->Printf(" Path : %" PRIx64, I->path_addr);
+ log->Printf(" Dyn : %" PRIx64, I->dyn_addr);
+ log->Printf(" Next : %" PRIx64, I->next);
+ log->Printf(" Prev : %" PRIx64, I->prev);
+ }
}
Modified: lldb/trunk/source/Plugins/DynamicLoader/Hexagon-DYLD/HexagonDYLDRendezvous.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/Hexagon-DYLD/HexagonDYLDRendezvous.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/Hexagon-DYLD/HexagonDYLDRendezvous.h (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/Hexagon-DYLD/HexagonDYLDRendezvous.h Tue Sep 6 15:57:50 2016
@@ -19,9 +19,8 @@
#include "lldb/lldb-defines.h"
#include "lldb/lldb-types.h"
-namespace lldb_private
-{
- class Process;
+namespace lldb_private {
+class Process;
}
/// @class HexagonDYLDRendezvous
@@ -31,249 +30,218 @@ namespace lldb_private
/// runtime liker each time a module is loaded or unloaded. This class provides
/// an interface to this structure and maintains a consistent snapshot of the
/// currently loaded modules.
-class HexagonDYLDRendezvous
-{
+class HexagonDYLDRendezvous {
- // This structure is used to hold the contents of the debug rendezvous
- // information (struct r_debug) as found in the inferiors memory. Note that
- // the layout of this struct is not binary compatible, it is simply large
- // enough to hold the information on both 32 and 64 bit platforms.
- struct Rendezvous {
- uint64_t version;
- lldb::addr_t map_addr;
- lldb::addr_t brk;
- uint64_t state;
- lldb::addr_t ldbase;
-
- Rendezvous()
- : version (0)
- , map_addr(LLDB_INVALID_ADDRESS)
- , brk (LLDB_INVALID_ADDRESS)
- , state (0)
- , ldbase (0)
- { }
-
- };
+ // This structure is used to hold the contents of the debug rendezvous
+ // information (struct r_debug) as found in the inferiors memory. Note that
+ // the layout of this struct is not binary compatible, it is simply large
+ // enough to hold the information on both 32 and 64 bit platforms.
+ struct Rendezvous {
+ uint64_t version;
+ lldb::addr_t map_addr;
+ lldb::addr_t brk;
+ uint64_t state;
+ lldb::addr_t ldbase;
+
+ Rendezvous()
+ : version(0), map_addr(LLDB_INVALID_ADDRESS), brk(LLDB_INVALID_ADDRESS),
+ state(0), ldbase(0) {}
+ };
public:
- // Various metadata supplied by the inferior's threading library to describe
- // the per-thread state.
- struct ThreadInfo {
- bool valid; // whether we read valid metadata
- uint32_t dtv_offset; // offset of DTV pointer within pthread
- uint32_t dtv_slot_size; // size of one DTV slot
- uint32_t modid_offset; // offset of module ID within link_map
- uint32_t tls_offset; // offset of TLS pointer within DTV slot
- };
-
- HexagonDYLDRendezvous(lldb_private::Process *process);
-
- /// Update the internal snapshot of runtime linker rendezvous and recompute
- /// the currently loaded modules.
- ///
- /// This method should be called once one start up, then once each time the
- /// runtime linker enters the function given by GetBreakAddress().
- ///
- /// @returns true on success and false on failure.
- ///
- /// @see GetBreakAddress().
- bool
- Resolve();
-
- /// @returns true if this rendezvous has been located in the inferiors
- /// address space and false otherwise.
- bool
- IsValid();
-
- /// @returns the address of the rendezvous structure in the inferiors
- /// address space.
- lldb::addr_t
- GetRendezvousAddress() const { return m_rendezvous_addr; }
-
- /// Provide the dyld structure address
- void
- SetRendezvousAddress( lldb::addr_t );
-
- /// @returns the version of the rendezvous protocol being used.
- uint64_t
- GetVersion() const { return m_current.version; }
-
- /// @returns address in the inferiors address space containing the linked
- /// list of shared object descriptors.
- lldb::addr_t
- GetLinkMapAddress() const { return m_current.map_addr; }
-
- /// A breakpoint should be set at this address and Resolve called on each
- /// hit.
- ///
- /// @returns the address of a function called by the runtime linker each
- /// time a module is loaded/unloaded, or about to be loaded/unloaded.
- ///
- /// @see Resolve()
- lldb::addr_t
- GetBreakAddress() const { return m_current.brk; }
-
- /// In hexagon it is possible that we can know the dyld breakpoint without
- /// having to find it from the rendezvous structure
- ///
- void
- SetBreakAddress( lldb::addr_t addr ) { m_current.brk = addr; }
-
- /// Returns the current state of the rendezvous structure.
- uint64_t
- GetState() const { return m_current.state; }
-
- /// @returns the base address of the runtime linker in the inferiors address
- /// space.
- lldb::addr_t
- GetLDBase() const { return m_current.ldbase; }
-
- /// @returns the thread layout metadata from the inferiors thread library.
- const ThreadInfo&
- GetThreadInfo();
-
- /// @returns true if modules have been loaded into the inferior since the
- /// last call to Resolve().
- bool
- ModulesDidLoad() const { return !m_added_soentries.empty(); }
-
- /// @returns true if modules have been unloaded from the inferior since the
- /// last call to Resolve().
- bool
- ModulesDidUnload() const { return !m_removed_soentries.empty(); }
-
- void
- DumpToLog(lldb_private::Log *log) const;
-
- /// @brief Constants describing the state of the rendezvous.
- ///
- /// @see GetState().
- enum RendezvousState
- {
- eConsistent = 0,
- eAdd ,
- eDelete ,
- };
-
- /// @brief Structure representing the shared objects currently loaded into
- /// the inferior process.
- ///
- /// This object is a rough analogue to the struct link_map object which
- /// actually lives in the inferiors memory.
- struct SOEntry {
- lldb::addr_t link_addr; ///< Address of this link_map.
- lldb::addr_t base_addr; ///< Base address of the loaded object.
- lldb::addr_t path_addr; ///< String naming the shared object.
- lldb::addr_t dyn_addr; ///< Dynamic section of shared object.
- lldb::addr_t next; ///< Address of next so_entry.
- lldb::addr_t prev; ///< Address of previous so_entry.
- std::string path; ///< File name of shared object.
-
- SOEntry() { clear(); }
-
- bool operator ==(const SOEntry &entry) {
- return this->path == entry.path;
- }
-
- void clear() {
- link_addr = 0;
- base_addr = 0;
- path_addr = 0;
- dyn_addr = 0;
- next = 0;
- prev = 0;
- path.clear();
- }
- };
+ // Various metadata supplied by the inferior's threading library to describe
+ // the per-thread state.
+ struct ThreadInfo {
+ bool valid; // whether we read valid metadata
+ uint32_t dtv_offset; // offset of DTV pointer within pthread
+ uint32_t dtv_slot_size; // size of one DTV slot
+ uint32_t modid_offset; // offset of module ID within link_map
+ uint32_t tls_offset; // offset of TLS pointer within DTV slot
+ };
+
+ HexagonDYLDRendezvous(lldb_private::Process *process);
+
+ /// Update the internal snapshot of runtime linker rendezvous and recompute
+ /// the currently loaded modules.
+ ///
+ /// This method should be called once one start up, then once each time the
+ /// runtime linker enters the function given by GetBreakAddress().
+ ///
+ /// @returns true on success and false on failure.
+ ///
+ /// @see GetBreakAddress().
+ bool Resolve();
+
+ /// @returns true if this rendezvous has been located in the inferiors
+ /// address space and false otherwise.
+ bool IsValid();
+
+ /// @returns the address of the rendezvous structure in the inferiors
+ /// address space.
+ lldb::addr_t GetRendezvousAddress() const { return m_rendezvous_addr; }
+
+ /// Provide the dyld structure address
+ void SetRendezvousAddress(lldb::addr_t);
+
+ /// @returns the version of the rendezvous protocol being used.
+ uint64_t GetVersion() const { return m_current.version; }
+
+ /// @returns address in the inferiors address space containing the linked
+ /// list of shared object descriptors.
+ lldb::addr_t GetLinkMapAddress() const { return m_current.map_addr; }
+
+ /// A breakpoint should be set at this address and Resolve called on each
+ /// hit.
+ ///
+ /// @returns the address of a function called by the runtime linker each
+ /// time a module is loaded/unloaded, or about to be loaded/unloaded.
+ ///
+ /// @see Resolve()
+ lldb::addr_t GetBreakAddress() const { return m_current.brk; }
+
+ /// In hexagon it is possible that we can know the dyld breakpoint without
+ /// having to find it from the rendezvous structure
+ ///
+ void SetBreakAddress(lldb::addr_t addr) { m_current.brk = addr; }
+
+ /// Returns the current state of the rendezvous structure.
+ uint64_t GetState() const { return m_current.state; }
+
+ /// @returns the base address of the runtime linker in the inferiors address
+ /// space.
+ lldb::addr_t GetLDBase() const { return m_current.ldbase; }
+
+ /// @returns the thread layout metadata from the inferiors thread library.
+ const ThreadInfo &GetThreadInfo();
+
+ /// @returns true if modules have been loaded into the inferior since the
+ /// last call to Resolve().
+ bool ModulesDidLoad() const { return !m_added_soentries.empty(); }
+
+ /// @returns true if modules have been unloaded from the inferior since the
+ /// last call to Resolve().
+ bool ModulesDidUnload() const { return !m_removed_soentries.empty(); }
+
+ void DumpToLog(lldb_private::Log *log) const;
+
+ /// @brief Constants describing the state of the rendezvous.
+ ///
+ /// @see GetState().
+ enum RendezvousState {
+ eConsistent = 0,
+ eAdd,
+ eDelete,
+ };
+
+ /// @brief Structure representing the shared objects currently loaded into
+ /// the inferior process.
+ ///
+ /// This object is a rough analogue to the struct link_map object which
+ /// actually lives in the inferiors memory.
+ struct SOEntry {
+ lldb::addr_t link_addr; ///< Address of this link_map.
+ lldb::addr_t base_addr; ///< Base address of the loaded object.
+ lldb::addr_t path_addr; ///< String naming the shared object.
+ lldb::addr_t dyn_addr; ///< Dynamic section of shared object.
+ lldb::addr_t next; ///< Address of next so_entry.
+ lldb::addr_t prev; ///< Address of previous so_entry.
+ std::string path; ///< File name of shared object.
+
+ SOEntry() { clear(); }
+
+ bool operator==(const SOEntry &entry) { return this->path == entry.path; }
+
+ void clear() {
+ link_addr = 0;
+ base_addr = 0;
+ path_addr = 0;
+ dyn_addr = 0;
+ next = 0;
+ prev = 0;
+ path.clear();
+ }
+ };
protected:
- typedef std::list<SOEntry> SOEntryList;
+ typedef std::list<SOEntry> SOEntryList;
public:
- typedef SOEntryList::const_iterator iterator;
+ typedef SOEntryList::const_iterator iterator;
+
+ /// Iterators over all currently loaded modules.
+ iterator begin() const { return m_soentries.begin(); }
+ iterator end() const { return m_soentries.end(); }
+
+ /// Iterators over all modules loaded into the inferior since the last call
+ /// to Resolve().
+ iterator loaded_begin() const { return m_added_soentries.begin(); }
+ iterator loaded_end() const { return m_added_soentries.end(); }
+
+ /// Iterators over all modules unloaded from the inferior since the last
+ /// call to Resolve().
+ iterator unloaded_begin() const { return m_removed_soentries.begin(); }
+ iterator unloaded_end() const { return m_removed_soentries.end(); }
- /// Iterators over all currently loaded modules.
- iterator begin() const { return m_soentries.begin(); }
- iterator end() const { return m_soentries.end(); }
-
- /// Iterators over all modules loaded into the inferior since the last call
- /// to Resolve().
- iterator loaded_begin() const { return m_added_soentries.begin(); }
- iterator loaded_end() const { return m_added_soentries.end(); }
-
- /// Iterators over all modules unloaded from the inferior since the last
- /// call to Resolve().
- iterator unloaded_begin() const { return m_removed_soentries.begin(); }
- iterator unloaded_end() const { return m_removed_soentries.end(); }
-
protected:
- lldb_private::Process *m_process;
+ lldb_private::Process *m_process;
- // Cached copy of executable pathname
- char m_exe_path[PATH_MAX];
+ // Cached copy of executable pathname
+ char m_exe_path[PATH_MAX];
- /// Location of the r_debug structure in the inferiors address space.
- lldb::addr_t m_rendezvous_addr;
+ /// Location of the r_debug structure in the inferiors address space.
+ lldb::addr_t m_rendezvous_addr;
- /// Current and previous snapshots of the rendezvous structure.
- Rendezvous m_current;
- Rendezvous m_previous;
+ /// Current and previous snapshots of the rendezvous structure.
+ Rendezvous m_current;
+ Rendezvous m_previous;
- /// List of SOEntry objects corresponding to the current link map state.
- SOEntryList m_soentries;
+ /// List of SOEntry objects corresponding to the current link map state.
+ SOEntryList m_soentries;
- /// List of SOEntry's added to the link map since the last call to Resolve().
- SOEntryList m_added_soentries;
+ /// List of SOEntry's added to the link map since the last call to Resolve().
+ SOEntryList m_added_soentries;
- /// List of SOEntry's removed from the link map since the last call to
- /// Resolve().
- SOEntryList m_removed_soentries;
+ /// List of SOEntry's removed from the link map since the last call to
+ /// Resolve().
+ SOEntryList m_removed_soentries;
- /// Threading metadata read from the inferior.
- ThreadInfo m_thread_info;
+ /// Threading metadata read from the inferior.
+ ThreadInfo m_thread_info;
- /// Reads an unsigned integer of @p size bytes from the inferior's address
- /// space starting at @p addr.
- ///
- /// @returns addr + size if the read was successful and false otherwise.
- lldb::addr_t
- ReadWord(lldb::addr_t addr, uint64_t *dst, size_t size);
+ /// Reads an unsigned integer of @p size bytes from the inferior's address
+ /// space starting at @p addr.
+ ///
+ /// @returns addr + size if the read was successful and false otherwise.
+ lldb::addr_t ReadWord(lldb::addr_t addr, uint64_t *dst, size_t size);
- /// Reads an address from the inferior's address space starting at @p addr.
- ///
- /// @returns addr + target address size if the read was successful and
- /// 0 otherwise.
- lldb::addr_t
- ReadPointer(lldb::addr_t addr, lldb::addr_t *dst);
+ /// Reads an address from the inferior's address space starting at @p addr.
+ ///
+ /// @returns addr + target address size if the read was successful and
+ /// 0 otherwise.
+ lldb::addr_t ReadPointer(lldb::addr_t addr, lldb::addr_t *dst);
- /// Reads a null-terminated C string from the memory location starting at @p
- /// addr.
- std::string
- ReadStringFromMemory(lldb::addr_t addr);
+ /// Reads a null-terminated C string from the memory location starting at @p
+ /// addr.
+ std::string ReadStringFromMemory(lldb::addr_t addr);
- /// Reads an SOEntry starting at @p addr.
- bool
- ReadSOEntryFromMemory(lldb::addr_t addr, SOEntry &entry);
+ /// Reads an SOEntry starting at @p addr.
+ bool ReadSOEntryFromMemory(lldb::addr_t addr, SOEntry &entry);
- /// Updates the current set of SOEntries, the set of added entries, and the
- /// set of removed entries.
- bool
- UpdateSOEntries();
+ /// Updates the current set of SOEntries, the set of added entries, and the
+ /// set of removed entries.
+ bool UpdateSOEntries();
- bool
- UpdateSOEntriesForAddition();
+ bool UpdateSOEntriesForAddition();
- bool
- UpdateSOEntriesForDeletion();
+ bool UpdateSOEntriesForDeletion();
- /// Reads the current list of shared objects according to the link map
- /// supplied by the runtime linker.
- bool
- TakeSnapshot(SOEntryList &entry_list);
+ /// Reads the current list of shared objects according to the link map
+ /// supplied by the runtime linker.
+ bool TakeSnapshot(SOEntryList &entry_list);
- enum PThreadField { eSize, eNElem, eOffset };
+ enum PThreadField { eSize, eNElem, eOffset };
- bool FindMetadata(const char *name, PThreadField field, uint32_t& value);
+ bool FindMetadata(const char *name, PThreadField field, uint32_t &value);
};
#endif // liblldb_HexagonDYLDRendezvous_H_
Modified: lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp Tue Sep 6 15:57:50 2016
@@ -35,7 +35,7 @@
//#define ENABLE_DEBUG_PRINTF // COMMENT THIS LINE OUT PRIOR TO CHECKIN
#ifdef ENABLE_DEBUG_PRINTF
#include <stdio.h>
-#define DEBUG_PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__)
+#define DEBUG_PRINTF(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#define DEBUG_PRINTF(fmt, ...)
#endif
@@ -49,29 +49,18 @@
using namespace lldb;
using namespace lldb_private;
-
//----------------------------------------------------------------------
// Constructor
//----------------------------------------------------------------------
-DynamicLoaderDarwin::DynamicLoaderDarwin (Process* process)
- : DynamicLoader(process),
- m_dyld_module_wp(),
- m_libpthread_module_wp(),
- m_pthread_getspecific_addr(),
- m_tid_to_tls_map(),
- m_dyld_image_infos(),
- m_dyld_image_infos_stop_id(UINT32_MAX),
- m_dyld(),
- m_mutex()
-{
-}
+DynamicLoaderDarwin::DynamicLoaderDarwin(Process *process)
+ : DynamicLoader(process), m_dyld_module_wp(), m_libpthread_module_wp(),
+ m_pthread_getspecific_addr(), m_tid_to_tls_map(), m_dyld_image_infos(),
+ m_dyld_image_infos_stop_id(UINT32_MAX), m_dyld(), m_mutex() {}
//----------------------------------------------------------------------
// Destructor
//----------------------------------------------------------------------
-DynamicLoaderDarwin::~DynamicLoaderDarwin()
-{
-}
+DynamicLoaderDarwin::~DynamicLoaderDarwin() {}
//------------------------------------------------------------------
/// Called after attaching a process.
@@ -79,12 +68,10 @@ DynamicLoaderDarwin::~DynamicLoaderDarwi
/// Allow DynamicLoader plug-ins to execute some code after
/// attaching to a process.
//------------------------------------------------------------------
-void
-DynamicLoaderDarwin::DidAttach ()
-{
- PrivateInitialize(m_process);
- DoInitialImageFetch ();
- SetNotificationBreakpoint ();
+void DynamicLoaderDarwin::DidAttach() {
+ PrivateInitialize(m_process);
+ DoInitialImageFetch();
+ SetNotificationBreakpoint();
}
//------------------------------------------------------------------
@@ -93,640 +80,618 @@ DynamicLoaderDarwin::DidAttach ()
/// Allow DynamicLoader plug-ins to execute some code after
/// attaching to a process.
//------------------------------------------------------------------
-void
-DynamicLoaderDarwin::DidLaunch ()
-{
- PrivateInitialize(m_process);
- DoInitialImageFetch ();
- SetNotificationBreakpoint ();
+void DynamicLoaderDarwin::DidLaunch() {
+ PrivateInitialize(m_process);
+ DoInitialImageFetch();
+ SetNotificationBreakpoint();
}
-
//----------------------------------------------------------------------
// Clear out the state of this class.
//----------------------------------------------------------------------
-void
-DynamicLoaderDarwin::Clear (bool clear_process)
-{
- std::lock_guard<std::recursive_mutex> guard(m_mutex);
- if (clear_process)
- m_process = NULL;
- m_dyld_image_infos.clear();
- m_dyld_image_infos_stop_id = UINT32_MAX;
- m_dyld.Clear(false);
-}
-
-ModuleSP
-DynamicLoaderDarwin::FindTargetModuleForImageInfo (ImageInfo &image_info, bool can_create, bool *did_create_ptr)
-{
- if (did_create_ptr)
- *did_create_ptr = false;
-
- Target &target = m_process->GetTarget();
- const ModuleList &target_images = target.GetImages();
- ModuleSpec module_spec (image_info.file_spec);
- module_spec.GetUUID() = image_info.uuid;
- ModuleSP module_sp (target_images.FindFirstModule (module_spec));
-
- if (module_sp && !module_spec.GetUUID().IsValid() && !module_sp->GetUUID().IsValid())
- {
- // No UUID, we must rely upon the cached module modification
- // time and the modification time of the file on disk
- if (module_sp->GetModificationTime() != module_sp->GetFileSpec().GetModificationTime())
- module_sp.reset();
- }
-
- if (!module_sp)
- {
- if (can_create)
- {
- module_sp = target.GetSharedModule (module_spec);
- if (!module_sp || module_sp->GetObjectFile() == NULL)
- module_sp = m_process->ReadModuleFromMemory (image_info.file_spec, image_info.address);
-
- if (did_create_ptr)
- *did_create_ptr = (bool) module_sp;
- }
- }
- return module_sp;
-}
-
-void
-DynamicLoaderDarwin::UnloadImages (const std::vector<lldb::addr_t> &solib_addresses)
-{
- std::lock_guard<std::recursive_mutex> guard(m_mutex);
- if (m_process->GetStopID() == m_dyld_image_infos_stop_id)
- return;
-
- Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_DYNAMIC_LOADER));
- Target &target = m_process->GetTarget();
- if (log)
- log->Printf ("Removing %" PRId64 " modules.", (uint64_t) solib_addresses.size());
-
- ModuleList unloaded_module_list;
-
- for (addr_t solib_addr : solib_addresses)
- {
- Address header;
- if (header.SetLoadAddress (solib_addr, &target))
- {
- if (header.GetOffset() == 0)
- {
- ModuleSP module_to_remove (header.GetModule());
- if (module_to_remove.get())
- {
- if (log)
- log->Printf ("Removing module at address 0x%" PRIx64, solib_addr);
- // remove the sections from the Target
- UnloadSections (module_to_remove);
- // add this to the list of modules to remove
- unloaded_module_list.AppendIfNeeded (module_to_remove);
- // remove the entry from the m_dyld_image_infos
- ImageInfo::collection::iterator pos, end = m_dyld_image_infos.end();
- for (pos = m_dyld_image_infos.begin(); pos != end; pos++)
- {
- if (solib_addr == (*pos).address)
- {
- m_dyld_image_infos.erase(pos);
- break;
- }
- }
- }
+void DynamicLoaderDarwin::Clear(bool clear_process) {
+ std::lock_guard<std::recursive_mutex> guard(m_mutex);
+ if (clear_process)
+ m_process = NULL;
+ m_dyld_image_infos.clear();
+ m_dyld_image_infos_stop_id = UINT32_MAX;
+ m_dyld.Clear(false);
+}
+
+ModuleSP DynamicLoaderDarwin::FindTargetModuleForImageInfo(
+ ImageInfo &image_info, bool can_create, bool *did_create_ptr) {
+ if (did_create_ptr)
+ *did_create_ptr = false;
+
+ Target &target = m_process->GetTarget();
+ const ModuleList &target_images = target.GetImages();
+ ModuleSpec module_spec(image_info.file_spec);
+ module_spec.GetUUID() = image_info.uuid;
+ ModuleSP module_sp(target_images.FindFirstModule(module_spec));
+
+ if (module_sp && !module_spec.GetUUID().IsValid() &&
+ !module_sp->GetUUID().IsValid()) {
+ // No UUID, we must rely upon the cached module modification
+ // time and the modification time of the file on disk
+ if (module_sp->GetModificationTime() !=
+ module_sp->GetFileSpec().GetModificationTime())
+ module_sp.reset();
+ }
+
+ if (!module_sp) {
+ if (can_create) {
+ module_sp = target.GetSharedModule(module_spec);
+ if (!module_sp || module_sp->GetObjectFile() == NULL)
+ module_sp = m_process->ReadModuleFromMemory(image_info.file_spec,
+ image_info.address);
+
+ if (did_create_ptr)
+ *did_create_ptr = (bool)module_sp;
+ }
+ }
+ return module_sp;
+}
+
+void DynamicLoaderDarwin::UnloadImages(
+ const std::vector<lldb::addr_t> &solib_addresses) {
+ std::lock_guard<std::recursive_mutex> guard(m_mutex);
+ if (m_process->GetStopID() == m_dyld_image_infos_stop_id)
+ return;
+
+ Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
+ Target &target = m_process->GetTarget();
+ if (log)
+ log->Printf("Removing %" PRId64 " modules.",
+ (uint64_t)solib_addresses.size());
+
+ ModuleList unloaded_module_list;
+
+ for (addr_t solib_addr : solib_addresses) {
+ Address header;
+ if (header.SetLoadAddress(solib_addr, &target)) {
+ if (header.GetOffset() == 0) {
+ ModuleSP module_to_remove(header.GetModule());
+ if (module_to_remove.get()) {
+ if (log)
+ log->Printf("Removing module at address 0x%" PRIx64, solib_addr);
+ // remove the sections from the Target
+ UnloadSections(module_to_remove);
+ // add this to the list of modules to remove
+ unloaded_module_list.AppendIfNeeded(module_to_remove);
+ // remove the entry from the m_dyld_image_infos
+ ImageInfo::collection::iterator pos, end = m_dyld_image_infos.end();
+ for (pos = m_dyld_image_infos.begin(); pos != end; pos++) {
+ if (solib_addr == (*pos).address) {
+ m_dyld_image_infos.erase(pos);
+ break;
}
+ }
}
+ }
}
+ }
- if (unloaded_module_list.GetSize() > 0)
- {
- if (log)
- {
- log->PutCString("Unloaded:");
- unloaded_module_list.LogUUIDAndPaths (log, "DynamicLoaderDarwin::UnloadModules");
- }
- m_process->GetTarget().GetImages().Remove (unloaded_module_list);
- m_dyld_image_infos_stop_id = m_process->GetStopID();
+ if (unloaded_module_list.GetSize() > 0) {
+ if (log) {
+ log->PutCString("Unloaded:");
+ unloaded_module_list.LogUUIDAndPaths(
+ log, "DynamicLoaderDarwin::UnloadModules");
}
+ m_process->GetTarget().GetImages().Remove(unloaded_module_list);
+ m_dyld_image_infos_stop_id = m_process->GetStopID();
+ }
}
-void
-DynamicLoaderDarwin::UnloadAllImages ()
-{
- Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_DYNAMIC_LOADER));
- ModuleList unloaded_modules_list;
+void DynamicLoaderDarwin::UnloadAllImages() {
+ Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
+ ModuleList unloaded_modules_list;
- Target &target = m_process->GetTarget();
- const ModuleList &target_modules = target.GetImages();
- std::lock_guard<std::recursive_mutex> guard(target_modules.GetMutex());
+ Target &target = m_process->GetTarget();
+ const ModuleList &target_modules = target.GetImages();
+ std::lock_guard<std::recursive_mutex> guard(target_modules.GetMutex());
- size_t num_modules = target_modules.GetSize();
- ModuleSP dyld_sp (GetDYLDModule());
+ size_t num_modules = target_modules.GetSize();
+ ModuleSP dyld_sp(GetDYLDModule());
- for (size_t i = 0; i < num_modules; i++)
- {
- ModuleSP module_sp = target_modules.GetModuleAtIndexUnlocked (i);
-
- // Don't remove dyld - else we'll lose our breakpoint notifying us about libraries
- // being re-loaded...
- if (module_sp.get() != nullptr
- && module_sp.get() != dyld_sp.get())
- {
- UnloadSections (module_sp);
- unloaded_modules_list.Append (module_sp);
- }
+ for (size_t i = 0; i < num_modules; i++) {
+ ModuleSP module_sp = target_modules.GetModuleAtIndexUnlocked(i);
+
+ // Don't remove dyld - else we'll lose our breakpoint notifying us about
+ // libraries
+ // being re-loaded...
+ if (module_sp.get() != nullptr && module_sp.get() != dyld_sp.get()) {
+ UnloadSections(module_sp);
+ unloaded_modules_list.Append(module_sp);
}
+ }
- if (unloaded_modules_list.GetSize() != 0)
- {
- if (log)
- {
- log->PutCString("Unloaded:");
- unloaded_modules_list.LogUUIDAndPaths (log, "DynamicLoaderDarwin::UnloadAllImages");
- }
- target.GetImages().Remove(unloaded_modules_list);
- m_dyld_image_infos.clear();
- m_dyld_image_infos_stop_id = m_process->GetStopID();
+ if (unloaded_modules_list.GetSize() != 0) {
+ if (log) {
+ log->PutCString("Unloaded:");
+ unloaded_modules_list.LogUUIDAndPaths(
+ log, "DynamicLoaderDarwin::UnloadAllImages");
}
+ target.GetImages().Remove(unloaded_modules_list);
+ m_dyld_image_infos.clear();
+ m_dyld_image_infos_stop_id = m_process->GetStopID();
+ }
}
//----------------------------------------------------------------------
// Update the load addresses for all segments in MODULE using the
// updated INFO that is passed in.
//----------------------------------------------------------------------
-bool
-DynamicLoaderDarwin::UpdateImageLoadAddress (Module *module, ImageInfo& info)
-{
- bool changed = false;
- if (module)
- {
- ObjectFile *image_object_file = module->GetObjectFile();
- if (image_object_file)
- {
- SectionList *section_list = image_object_file->GetSectionList ();
- if (section_list)
- {
- std::vector<uint32_t> inaccessible_segment_indexes;
- // We now know the slide amount, so go through all sections
- // and update the load addresses with the correct values.
- const size_t num_segments = info.segments.size();
- for (size_t i=0; i<num_segments; ++i)
- {
- // Only load a segment if it has protections. Things like
- // __PAGEZERO don't have any protections, and they shouldn't
- // be slid
- SectionSP section_sp(section_list->FindSectionByName(info.segments[i].name));
-
- if (info.segments[i].maxprot == 0)
- {
- inaccessible_segment_indexes.push_back(i);
- }
- else
- {
- const addr_t new_section_load_addr = info.segments[i].vmaddr + info.slide;
- static ConstString g_section_name_LINKEDIT ("__LINKEDIT");
-
- if (section_sp)
- {
- // __LINKEDIT sections from files in the shared cache
- // can overlap so check to see what the segment name is
- // and pass "false" so we don't warn of overlapping
- // "Section" objects, and "true" for all other sections.
- const bool warn_multiple = section_sp->GetName() != g_section_name_LINKEDIT;
-
- changed = m_process->GetTarget().SetSectionLoadAddress (section_sp, new_section_load_addr, warn_multiple);
- }
- else
- {
- Host::SystemLog (Host::eSystemLogWarning,
- "warning: unable to find and load segment named '%s' at 0x%" PRIx64 " in '%s' in macosx dynamic loader plug-in.\n",
- info.segments[i].name.AsCString("<invalid>"),
- (uint64_t)new_section_load_addr,
- image_object_file->GetFileSpec().GetPath().c_str());
- }
- }
- }
-
- // If the loaded the file (it changed) and we have segments that
- // are not readable or writeable, add them to the invalid memory
- // region cache for the process. This will typically only be
- // the __PAGEZERO segment in the main executable. We might be able
- // to apply this more generally to more sections that have no
- // protections in the future, but for now we are going to just
- // do __PAGEZERO.
- if (changed && !inaccessible_segment_indexes.empty())
- {
- for (uint32_t i=0; i<inaccessible_segment_indexes.size(); ++i)
- {
- const uint32_t seg_idx = inaccessible_segment_indexes[i];
- SectionSP section_sp(section_list->FindSectionByName(info.segments[seg_idx].name));
-
- if (section_sp)
- {
- static ConstString g_pagezero_section_name("__PAGEZERO");
- if (g_pagezero_section_name == section_sp->GetName())
- {
- // __PAGEZERO never slides...
- const lldb::addr_t vmaddr = info.segments[seg_idx].vmaddr;
- const lldb::addr_t vmsize = info.segments[seg_idx].vmsize;
- Process::LoadRange pagezero_range (vmaddr, vmsize);
- m_process->AddInvalidMemoryRegion(pagezero_range);
- }
- }
- }
- }
+bool DynamicLoaderDarwin::UpdateImageLoadAddress(Module *module,
+ ImageInfo &info) {
+ bool changed = false;
+ if (module) {
+ ObjectFile *image_object_file = module->GetObjectFile();
+ if (image_object_file) {
+ SectionList *section_list = image_object_file->GetSectionList();
+ if (section_list) {
+ std::vector<uint32_t> inaccessible_segment_indexes;
+ // We now know the slide amount, so go through all sections
+ // and update the load addresses with the correct values.
+ const size_t num_segments = info.segments.size();
+ for (size_t i = 0; i < num_segments; ++i) {
+ // Only load a segment if it has protections. Things like
+ // __PAGEZERO don't have any protections, and they shouldn't
+ // be slid
+ SectionSP section_sp(
+ section_list->FindSectionByName(info.segments[i].name));
+
+ if (info.segments[i].maxprot == 0) {
+ inaccessible_segment_indexes.push_back(i);
+ } else {
+ const addr_t new_section_load_addr =
+ info.segments[i].vmaddr + info.slide;
+ static ConstString g_section_name_LINKEDIT("__LINKEDIT");
+
+ if (section_sp) {
+ // __LINKEDIT sections from files in the shared cache
+ // can overlap so check to see what the segment name is
+ // and pass "false" so we don't warn of overlapping
+ // "Section" objects, and "true" for all other sections.
+ const bool warn_multiple =
+ section_sp->GetName() != g_section_name_LINKEDIT;
+
+ changed = m_process->GetTarget().SetSectionLoadAddress(
+ section_sp, new_section_load_addr, warn_multiple);
+ } else {
+ Host::SystemLog(
+ Host::eSystemLogWarning,
+ "warning: unable to find and load segment named '%s' at "
+ "0x%" PRIx64 " in '%s' in macosx dynamic loader plug-in.\n",
+ info.segments[i].name.AsCString("<invalid>"),
+ (uint64_t)new_section_load_addr,
+ image_object_file->GetFileSpec().GetPath().c_str());
}
+ }
}
+
+ // If the loaded the file (it changed) and we have segments that
+ // are not readable or writeable, add them to the invalid memory
+ // region cache for the process. This will typically only be
+ // the __PAGEZERO segment in the main executable. We might be able
+ // to apply this more generally to more sections that have no
+ // protections in the future, but for now we are going to just
+ // do __PAGEZERO.
+ if (changed && !inaccessible_segment_indexes.empty()) {
+ for (uint32_t i = 0; i < inaccessible_segment_indexes.size(); ++i) {
+ const uint32_t seg_idx = inaccessible_segment_indexes[i];
+ SectionSP section_sp(
+ section_list->FindSectionByName(info.segments[seg_idx].name));
+
+ if (section_sp) {
+ static ConstString g_pagezero_section_name("__PAGEZERO");
+ if (g_pagezero_section_name == section_sp->GetName()) {
+ // __PAGEZERO never slides...
+ const lldb::addr_t vmaddr = info.segments[seg_idx].vmaddr;
+ const lldb::addr_t vmsize = info.segments[seg_idx].vmsize;
+ Process::LoadRange pagezero_range(vmaddr, vmsize);
+ m_process->AddInvalidMemoryRegion(pagezero_range);
+ }
+ }
+ }
+ }
+ }
}
- // We might have an in memory image that was loaded as soon as it was created
- if (info.load_stop_id == m_process->GetStopID())
- changed = true;
- else if (changed)
- {
- // Update the stop ID when this library was updated
- info.load_stop_id = m_process->GetStopID();
- }
- return changed;
+ }
+ // We might have an in memory image that was loaded as soon as it was created
+ if (info.load_stop_id == m_process->GetStopID())
+ changed = true;
+ else if (changed) {
+ // Update the stop ID when this library was updated
+ info.load_stop_id = m_process->GetStopID();
+ }
+ return changed;
}
//----------------------------------------------------------------------
// Unload the segments in MODULE using the INFO that is passed in.
//----------------------------------------------------------------------
-bool
-DynamicLoaderDarwin::UnloadModuleSections (Module *module, ImageInfo& info)
-{
- bool changed = false;
- if (module)
- {
- ObjectFile *image_object_file = module->GetObjectFile();
- if (image_object_file)
- {
- SectionList *section_list = image_object_file->GetSectionList ();
- if (section_list)
- {
- const size_t num_segments = info.segments.size();
- for (size_t i=0; i<num_segments; ++i)
- {
- SectionSP section_sp(section_list->FindSectionByName(info.segments[i].name));
- if (section_sp)
- {
- const addr_t old_section_load_addr = info.segments[i].vmaddr + info.slide;
- if (m_process->GetTarget().SetSectionUnloaded (section_sp, old_section_load_addr))
- changed = true;
- }
- else
- {
- Host::SystemLog (Host::eSystemLogWarning,
- "warning: unable to find and unload segment named '%s' in '%s' in macosx dynamic loader plug-in.\n",
- info.segments[i].name.AsCString("<invalid>"),
- image_object_file->GetFileSpec().GetPath().c_str());
- }
- }
- }
+bool DynamicLoaderDarwin::UnloadModuleSections(Module *module,
+ ImageInfo &info) {
+ bool changed = false;
+ if (module) {
+ ObjectFile *image_object_file = module->GetObjectFile();
+ if (image_object_file) {
+ SectionList *section_list = image_object_file->GetSectionList();
+ if (section_list) {
+ const size_t num_segments = info.segments.size();
+ for (size_t i = 0; i < num_segments; ++i) {
+ SectionSP section_sp(
+ section_list->FindSectionByName(info.segments[i].name));
+ if (section_sp) {
+ const addr_t old_section_load_addr =
+ info.segments[i].vmaddr + info.slide;
+ if (m_process->GetTarget().SetSectionUnloaded(
+ section_sp, old_section_load_addr))
+ changed = true;
+ } else {
+ Host::SystemLog(Host::eSystemLogWarning,
+ "warning: unable to find and unload segment named "
+ "'%s' in '%s' in macosx dynamic loader plug-in.\n",
+ info.segments[i].name.AsCString("<invalid>"),
+ image_object_file->GetFileSpec().GetPath().c_str());
+ }
}
+ }
}
- return changed;
+ }
+ return changed;
}
-
-// Given a JSON dictionary (from debugserver, most likely) of binary images loaded in the inferior
+// Given a JSON dictionary (from debugserver, most likely) of binary images
+// loaded in the inferior
// process, add the images to the ImageInfo collection.
-bool
-DynamicLoaderDarwin::JSONImageInformationIntoImageInfo (StructuredData::ObjectSP image_details, ImageInfo::collection &image_infos)
-{
- StructuredData::ObjectSP images_sp = image_details->GetAsDictionary()->GetValueForKey("images");
- if (images_sp.get() == nullptr)
- return false;
-
- image_infos.resize (images_sp->GetAsArray()->GetSize());
-
- for (size_t i = 0; i < image_infos.size(); i++)
- {
- StructuredData::ObjectSP image_sp = images_sp->GetAsArray()->GetItemAtIndex(i);
- if (image_sp.get() == nullptr || image_sp->GetAsDictionary() == nullptr)
- return false;
- StructuredData::Dictionary *image = image_sp->GetAsDictionary();
- if (image->HasKey("load_address") == false
- || image->HasKey("pathname") == false
- || image->HasKey("mod_date") == false
- || image->HasKey("mach_header") == false
- || image->GetValueForKey("mach_header")->GetAsDictionary() == nullptr
- || image->HasKey("segments") == false
- || image->GetValueForKey("segments")->GetAsArray() == nullptr
- || image->HasKey("uuid") == false )
- {
- return false;
- }
- image_infos[i].address = image->GetValueForKey("load_address")->GetAsInteger()->GetValue();
- image_infos[i].mod_date = image->GetValueForKey("mod_date")->GetAsInteger()->GetValue();
- image_infos[i].file_spec.SetFile(image->GetValueForKey("pathname")->GetAsString()->GetValue().c_str(), false);
-
- StructuredData::Dictionary *mh = image->GetValueForKey("mach_header")->GetAsDictionary();
- image_infos[i].header.magic = mh->GetValueForKey("magic")->GetAsInteger()->GetValue();
- image_infos[i].header.cputype = mh->GetValueForKey("cputype")->GetAsInteger()->GetValue();
- image_infos[i].header.cpusubtype = mh->GetValueForKey("cpusubtype")->GetAsInteger()->GetValue();
- image_infos[i].header.filetype = mh->GetValueForKey("filetype")->GetAsInteger()->GetValue();
-
- if (image->HasKey("min_version_os_name"))
- {
- std::string os_name = image->GetValueForKey("min_version_os_name")->GetAsString()->GetValue();
- if (os_name == "macosx")
- image_infos[i].os_type = llvm::Triple::MacOSX;
- else if (os_name == "ios" || os_name == "iphoneos")
- image_infos[i].os_type = llvm::Triple::IOS;
- else if (os_name == "tvos")
- image_infos[i].os_type = llvm::Triple::TvOS;
- else if (os_name == "watchos")
- image_infos[i].os_type = llvm::Triple::WatchOS;
- }
- if (image->HasKey("min_version_os_sdk"))
- {
- image_infos[i].min_version_os_sdk = image->GetValueForKey("min_version_os_sdk")->GetAsString()->GetValue();
- }
+bool DynamicLoaderDarwin::JSONImageInformationIntoImageInfo(
+ StructuredData::ObjectSP image_details,
+ ImageInfo::collection &image_infos) {
+ StructuredData::ObjectSP images_sp =
+ image_details->GetAsDictionary()->GetValueForKey("images");
+ if (images_sp.get() == nullptr)
+ return false;
- // Fields that aren't used by DynamicLoaderDarwin so debugserver doesn't currently send them
- // in the reply.
+ image_infos.resize(images_sp->GetAsArray()->GetSize());
- if (mh->HasKey("flags"))
- image_infos[i].header.flags = mh->GetValueForKey("flags")->GetAsInteger()->GetValue();
- else
- image_infos[i].header.flags = 0;
-
- if (mh->HasKey("ncmds"))
- image_infos[i].header.ncmds = mh->GetValueForKey("ncmds")->GetAsInteger()->GetValue();
- else
- image_infos[i].header.ncmds = 0;
-
- if (mh->HasKey("sizeofcmds"))
- image_infos[i].header.sizeofcmds = mh->GetValueForKey("sizeofcmds")->GetAsInteger()->GetValue();
- else
- image_infos[i].header.sizeofcmds = 0;
-
- StructuredData::Array *segments = image->GetValueForKey("segments")->GetAsArray();
- uint32_t segcount = segments->GetSize();
- for (size_t j = 0; j < segcount; j++)
- {
- Segment segment;
- StructuredData::Dictionary *seg = segments->GetItemAtIndex(j)->GetAsDictionary();
- segment.name = ConstString(seg->GetValueForKey("name")->GetAsString()->GetValue().c_str());
- segment.vmaddr = seg->GetValueForKey("vmaddr")->GetAsInteger()->GetValue();
- segment.vmsize = seg->GetValueForKey("vmsize")->GetAsInteger()->GetValue();
- segment.fileoff = seg->GetValueForKey("fileoff")->GetAsInteger()->GetValue();
- segment.filesize = seg->GetValueForKey("filesize")->GetAsInteger()->GetValue();
- segment.maxprot = seg->GetValueForKey("maxprot")->GetAsInteger()->GetValue();
-
- // Fields that aren't used by DynamicLoaderDarwin so debugserver doesn't currently send them
- // in the reply.
-
- if (seg->HasKey("initprot"))
- segment.initprot = seg->GetValueForKey("initprot")->GetAsInteger()->GetValue();
- else
- segment.initprot = 0;
-
- if (seg->HasKey("flags"))
- segment.flags = seg->GetValueForKey("flags")->GetAsInteger()->GetValue();
- else
- segment.flags = 0;
-
- if (seg->HasKey("nsects"))
- segment.nsects = seg->GetValueForKey("nsects")->GetAsInteger()->GetValue();
- else
- segment.nsects = 0;
+ for (size_t i = 0; i < image_infos.size(); i++) {
+ StructuredData::ObjectSP image_sp =
+ images_sp->GetAsArray()->GetItemAtIndex(i);
+ if (image_sp.get() == nullptr || image_sp->GetAsDictionary() == nullptr)
+ return false;
+ StructuredData::Dictionary *image = image_sp->GetAsDictionary();
+ if (image->HasKey("load_address") == false ||
+ image->HasKey("pathname") == false ||
+ image->HasKey("mod_date") == false ||
+ image->HasKey("mach_header") == false ||
+ image->GetValueForKey("mach_header")->GetAsDictionary() == nullptr ||
+ image->HasKey("segments") == false ||
+ image->GetValueForKey("segments")->GetAsArray() == nullptr ||
+ image->HasKey("uuid") == false) {
+ return false;
+ }
+ image_infos[i].address =
+ image->GetValueForKey("load_address")->GetAsInteger()->GetValue();
+ image_infos[i].mod_date =
+ image->GetValueForKey("mod_date")->GetAsInteger()->GetValue();
+ image_infos[i].file_spec.SetFile(
+ image->GetValueForKey("pathname")->GetAsString()->GetValue().c_str(),
+ false);
+
+ StructuredData::Dictionary *mh =
+ image->GetValueForKey("mach_header")->GetAsDictionary();
+ image_infos[i].header.magic =
+ mh->GetValueForKey("magic")->GetAsInteger()->GetValue();
+ image_infos[i].header.cputype =
+ mh->GetValueForKey("cputype")->GetAsInteger()->GetValue();
+ image_infos[i].header.cpusubtype =
+ mh->GetValueForKey("cpusubtype")->GetAsInteger()->GetValue();
+ image_infos[i].header.filetype =
+ mh->GetValueForKey("filetype")->GetAsInteger()->GetValue();
+
+ if (image->HasKey("min_version_os_name")) {
+ std::string os_name = image->GetValueForKey("min_version_os_name")
+ ->GetAsString()
+ ->GetValue();
+ if (os_name == "macosx")
+ image_infos[i].os_type = llvm::Triple::MacOSX;
+ else if (os_name == "ios" || os_name == "iphoneos")
+ image_infos[i].os_type = llvm::Triple::IOS;
+ else if (os_name == "tvos")
+ image_infos[i].os_type = llvm::Triple::TvOS;
+ else if (os_name == "watchos")
+ image_infos[i].os_type = llvm::Triple::WatchOS;
+ }
+ if (image->HasKey("min_version_os_sdk")) {
+ image_infos[i].min_version_os_sdk =
+ image->GetValueForKey("min_version_os_sdk")
+ ->GetAsString()
+ ->GetValue();
+ }
+
+ // Fields that aren't used by DynamicLoaderDarwin so debugserver doesn't
+ // currently send them
+ // in the reply.
+
+ if (mh->HasKey("flags"))
+ image_infos[i].header.flags =
+ mh->GetValueForKey("flags")->GetAsInteger()->GetValue();
+ else
+ image_infos[i].header.flags = 0;
- image_infos[i].segments.push_back (segment);
- }
+ if (mh->HasKey("ncmds"))
+ image_infos[i].header.ncmds =
+ mh->GetValueForKey("ncmds")->GetAsInteger()->GetValue();
+ else
+ image_infos[i].header.ncmds = 0;
- image_infos[i].uuid.SetFromCString (image->GetValueForKey("uuid")->GetAsString()->GetValue().c_str());
+ if (mh->HasKey("sizeofcmds"))
+ image_infos[i].header.sizeofcmds =
+ mh->GetValueForKey("sizeofcmds")->GetAsInteger()->GetValue();
+ else
+ image_infos[i].header.sizeofcmds = 0;
- // All sections listed in the dyld image info structure will all
- // either be fixed up already, or they will all be off by a single
- // slide amount that is determined by finding the first segment
- // that is at file offset zero which also has bytes (a file size
- // that is greater than zero) in the object file.
-
- // Determine the slide amount (if any)
- const size_t num_sections = image_infos[i].segments.size();
- for (size_t k = 0; k < num_sections; ++k)
- {
- // Iterate through the object file sections to find the
- // first section that starts of file offset zero and that
- // has bytes in the file...
- if ((image_infos[i].segments[k].fileoff == 0 && image_infos[i].segments[k].filesize > 0)
- || (image_infos[i].segments[k].name == ConstString("__TEXT")))
- {
- image_infos[i].slide = image_infos[i].address - image_infos[i].segments[k].vmaddr;
- // We have found the slide amount, so we can exit
- // this for loop.
- break;
- }
- }
+ StructuredData::Array *segments =
+ image->GetValueForKey("segments")->GetAsArray();
+ uint32_t segcount = segments->GetSize();
+ for (size_t j = 0; j < segcount; j++) {
+ Segment segment;
+ StructuredData::Dictionary *seg =
+ segments->GetItemAtIndex(j)->GetAsDictionary();
+ segment.name = ConstString(
+ seg->GetValueForKey("name")->GetAsString()->GetValue().c_str());
+ segment.vmaddr =
+ seg->GetValueForKey("vmaddr")->GetAsInteger()->GetValue();
+ segment.vmsize =
+ seg->GetValueForKey("vmsize")->GetAsInteger()->GetValue();
+ segment.fileoff =
+ seg->GetValueForKey("fileoff")->GetAsInteger()->GetValue();
+ segment.filesize =
+ seg->GetValueForKey("filesize")->GetAsInteger()->GetValue();
+ segment.maxprot =
+ seg->GetValueForKey("maxprot")->GetAsInteger()->GetValue();
+
+ // Fields that aren't used by DynamicLoaderDarwin so debugserver doesn't
+ // currently send them
+ // in the reply.
+
+ if (seg->HasKey("initprot"))
+ segment.initprot =
+ seg->GetValueForKey("initprot")->GetAsInteger()->GetValue();
+ else
+ segment.initprot = 0;
+
+ if (seg->HasKey("flags"))
+ segment.flags =
+ seg->GetValueForKey("flags")->GetAsInteger()->GetValue();
+ else
+ segment.flags = 0;
+
+ if (seg->HasKey("nsects"))
+ segment.nsects =
+ seg->GetValueForKey("nsects")->GetAsInteger()->GetValue();
+ else
+ segment.nsects = 0;
+
+ image_infos[i].segments.push_back(segment);
+ }
+
+ image_infos[i].uuid.SetFromCString(
+ image->GetValueForKey("uuid")->GetAsString()->GetValue().c_str());
+
+ // All sections listed in the dyld image info structure will all
+ // either be fixed up already, or they will all be off by a single
+ // slide amount that is determined by finding the first segment
+ // that is at file offset zero which also has bytes (a file size
+ // that is greater than zero) in the object file.
+
+ // Determine the slide amount (if any)
+ const size_t num_sections = image_infos[i].segments.size();
+ for (size_t k = 0; k < num_sections; ++k) {
+ // Iterate through the object file sections to find the
+ // first section that starts of file offset zero and that
+ // has bytes in the file...
+ if ((image_infos[i].segments[k].fileoff == 0 &&
+ image_infos[i].segments[k].filesize > 0) ||
+ (image_infos[i].segments[k].name == ConstString("__TEXT"))) {
+ image_infos[i].slide =
+ image_infos[i].address - image_infos[i].segments[k].vmaddr;
+ // We have found the slide amount, so we can exit
+ // this for loop.
+ break;
+ }
}
+ }
- return true;
+ return true;
}
-void
-DynamicLoaderDarwin::UpdateSpecialBinariesFromNewImageInfos (ImageInfo::collection &image_infos)
-{
- uint32_t exe_idx = UINT32_MAX;
- uint32_t dyld_idx = UINT32_MAX;
- Target &target = m_process->GetTarget();
- Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_DYNAMIC_LOADER));
- ConstString g_dyld_sim_filename ("dyld_sim");
-
- ArchSpec target_arch = target.GetArchitecture();
- const size_t image_infos_size = image_infos.size();
- for (size_t i = 0; i < image_infos_size; i++)
- {
- if (image_infos[i].header.filetype == llvm::MachO::MH_DYLINKER)
- {
- // In a "simulator" process (an x86 process that is ios/tvos/watchos)
- // we will have two dyld modules -- a "dyld" that we want to keep track of,
- // and a "dyld_sim" which we don't need to keep track of here.
- // If the target is an x86 system and the OS of the dyld binary is
- // ios/tvos/watchos, then we are looking at dyld_sym.
-
- // debugserver has only recently (late 2016) started sending up the
- // os type for each binary it sees -- so if we don't have an os
- // type, use a filename check as our next best guess.
- if (image_infos[i].os_type == llvm::Triple::OSType::UnknownOS)
- {
- if (image_infos[i].file_spec.GetFilename() != g_dyld_sim_filename)
- {
- dyld_idx = i;
+void DynamicLoaderDarwin::UpdateSpecialBinariesFromNewImageInfos(
+ ImageInfo::collection &image_infos) {
+ uint32_t exe_idx = UINT32_MAX;
+ uint32_t dyld_idx = UINT32_MAX;
+ Target &target = m_process->GetTarget();
+ Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
+ ConstString g_dyld_sim_filename("dyld_sim");
+
+ ArchSpec target_arch = target.GetArchitecture();
+ const size_t image_infos_size = image_infos.size();
+ for (size_t i = 0; i < image_infos_size; i++) {
+ if (image_infos[i].header.filetype == llvm::MachO::MH_DYLINKER) {
+ // In a "simulator" process (an x86 process that is ios/tvos/watchos)
+ // we will have two dyld modules -- a "dyld" that we want to keep track
+ // of,
+ // and a "dyld_sim" which we don't need to keep track of here.
+ // If the target is an x86 system and the OS of the dyld binary is
+ // ios/tvos/watchos, then we are looking at dyld_sym.
+
+ // debugserver has only recently (late 2016) started sending up the
+ // os type for each binary it sees -- so if we don't have an os
+ // type, use a filename check as our next best guess.
+ if (image_infos[i].os_type == llvm::Triple::OSType::UnknownOS) {
+ if (image_infos[i].file_spec.GetFilename() != g_dyld_sim_filename) {
+ dyld_idx = i;
+ }
+ } else if (target_arch.GetTriple().getArch() == llvm::Triple::x86 ||
+ target_arch.GetTriple().getArch() == llvm::Triple::x86_64) {
+ if (image_infos[i].os_type != llvm::Triple::OSType::IOS &&
+ image_infos[i].os_type != llvm::Triple::TvOS &&
+ image_infos[i].os_type != llvm::Triple::WatchOS) {
+ dyld_idx = i;
+ }
+ }
+ } else if (image_infos[i].header.filetype == llvm::MachO::MH_EXECUTE) {
+ exe_idx = i;
+ }
+ }
+
+ if (exe_idx != UINT32_MAX) {
+ const bool can_create = true;
+ ModuleSP exe_module_sp(
+ FindTargetModuleForImageInfo(image_infos[exe_idx], can_create, NULL));
+ if (exe_module_sp) {
+ if (log)
+ log->Printf("Found executable module: %s",
+ exe_module_sp->GetFileSpec().GetPath().c_str());
+ target.GetImages().AppendIfNeeded(exe_module_sp);
+ UpdateImageLoadAddress(exe_module_sp.get(), image_infos[exe_idx]);
+ if (exe_module_sp.get() != target.GetExecutableModulePointer()) {
+ const bool get_dependent_images = false;
+ target.SetExecutableModule(exe_module_sp, get_dependent_images);
+ }
+ }
+ }
+
+ if (dyld_idx != UINT32_MAX) {
+ const bool can_create = true;
+ ModuleSP dyld_sp =
+ FindTargetModuleForImageInfo(image_infos[dyld_idx], can_create, NULL);
+ if (dyld_sp.get()) {
+ if (log)
+ log->Printf("Found dyld module: %s",
+ dyld_sp->GetFileSpec().GetPath().c_str());
+ target.GetImages().AppendIfNeeded(dyld_sp);
+ UpdateImageLoadAddress(dyld_sp.get(), image_infos[dyld_idx]);
+ SetDYLDModule(dyld_sp);
+ }
+ }
+}
+
+void DynamicLoaderDarwin::UpdateDYLDImageInfoFromNewImageInfo(
+ ImageInfo &image_info) {
+ if (image_info.header.filetype == llvm::MachO::MH_DYLINKER) {
+ const bool can_create = true;
+ ModuleSP dyld_sp =
+ FindTargetModuleForImageInfo(image_info, can_create, NULL);
+ if (dyld_sp.get()) {
+ Target &target = m_process->GetTarget();
+ target.GetImages().AppendIfNeeded(dyld_sp);
+ UpdateImageLoadAddress(dyld_sp.get(), image_info);
+ SetDYLDModule(dyld_sp);
+ }
+ }
+}
+
+void DynamicLoaderDarwin::SetDYLDModule(lldb::ModuleSP &dyld_module_sp) {
+ m_dyld_module_wp = dyld_module_sp;
+}
+
+ModuleSP DynamicLoaderDarwin::GetDYLDModule() {
+ ModuleSP dyld_sp(m_dyld_module_wp.lock());
+ return dyld_sp;
+}
+
+bool DynamicLoaderDarwin::AddModulesUsingImageInfos(
+ ImageInfo::collection &image_infos) {
+ std::lock_guard<std::recursive_mutex> guard(m_mutex);
+ // Now add these images to the main list.
+ ModuleList loaded_module_list;
+ Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
+ Target &target = m_process->GetTarget();
+ ModuleList &target_images = target.GetImages();
+
+ for (uint32_t idx = 0; idx < image_infos.size(); ++idx) {
+ if (log) {
+ log->Printf("Adding new image at address=0x%16.16" PRIx64 ".",
+ image_infos[idx].address);
+ image_infos[idx].PutToLog(log);
+ }
+
+ m_dyld_image_infos.push_back(image_infos[idx]);
+
+ ModuleSP image_module_sp(
+ FindTargetModuleForImageInfo(image_infos[idx], true, NULL));
+
+ if (image_module_sp) {
+ ObjectFile *objfile = image_module_sp->GetObjectFile();
+ if (objfile) {
+ SectionList *sections = objfile->GetSectionList();
+ if (sections) {
+ ConstString commpage_dbstr("__commpage");
+ Section *commpage_section =
+ sections->FindSectionByName(commpage_dbstr).get();
+ if (commpage_section) {
+ ModuleSpec module_spec(objfile->GetFileSpec(),
+ image_infos[idx].GetArchitecture());
+ module_spec.GetObjectName() = commpage_dbstr;
+ ModuleSP commpage_image_module_sp(
+ target_images.FindFirstModule(module_spec));
+ if (!commpage_image_module_sp) {
+ module_spec.SetObjectOffset(objfile->GetFileOffset() +
+ commpage_section->GetFileOffset());
+ module_spec.SetObjectSize(objfile->GetByteSize());
+ commpage_image_module_sp = target.GetSharedModule(module_spec);
+ if (!commpage_image_module_sp ||
+ commpage_image_module_sp->GetObjectFile() == NULL) {
+ commpage_image_module_sp = m_process->ReadModuleFromMemory(
+ image_infos[idx].file_spec, image_infos[idx].address);
+ // Always load a memory image right away in the target in case
+ // we end up trying to read the symbol table from memory... The
+ // __LINKEDIT will need to be mapped so we can figure out where
+ // the symbol table bits are...
+ bool changed = false;
+ UpdateImageLoadAddress(commpage_image_module_sp.get(),
+ image_infos[idx]);
+ target.GetImages().Append(commpage_image_module_sp);
+ if (changed) {
+ image_infos[idx].load_stop_id = m_process->GetStopID();
+ loaded_module_list.AppendIfNeeded(commpage_image_module_sp);
}
+ }
}
- else if (target_arch.GetTriple().getArch() == llvm::Triple::x86
- || target_arch.GetTriple().getArch() == llvm::Triple::x86_64)
- {
- if (image_infos[i].os_type != llvm::Triple::OSType::IOS
- && image_infos[i].os_type != llvm::Triple::TvOS
- && image_infos[i].os_type != llvm::Triple::WatchOS)
- {
- dyld_idx = i;
- }
- }
- }
- else if (image_infos[i].header.filetype == llvm::MachO::MH_EXECUTE)
- {
- exe_idx = i;
- }
- }
-
- if (exe_idx != UINT32_MAX)
- {
- const bool can_create = true;
- ModuleSP exe_module_sp (FindTargetModuleForImageInfo (image_infos[exe_idx], can_create, NULL));
- if (exe_module_sp)
- {
- if (log)
- log->Printf ("Found executable module: %s", exe_module_sp->GetFileSpec().GetPath().c_str());
- target.GetImages().AppendIfNeeded (exe_module_sp);
- UpdateImageLoadAddress (exe_module_sp.get(), image_infos[exe_idx]);
- if (exe_module_sp.get() != target.GetExecutableModulePointer())
- {
- const bool get_dependent_images = false;
- target.SetExecutableModule (exe_module_sp, get_dependent_images);
- }
+ }
}
- }
+ }
- if (dyld_idx != UINT32_MAX)
- {
- const bool can_create = true;
- ModuleSP dyld_sp = FindTargetModuleForImageInfo (image_infos[dyld_idx], can_create, NULL);
- if (dyld_sp.get())
- {
- if (log)
- log->Printf ("Found dyld module: %s", dyld_sp->GetFileSpec().GetPath().c_str());
- target.GetImages().AppendIfNeeded (dyld_sp);
- UpdateImageLoadAddress (dyld_sp.get(), image_infos[dyld_idx]);
- SetDYLDModule (dyld_sp);
- }
+ // UpdateImageLoadAddress will return true if any segments
+ // change load address. We need to check this so we don't
+ // mention that all loaded shared libraries are newly loaded
+ // each time we hit out dyld breakpoint since dyld will list all
+ // shared libraries each time.
+ if (UpdateImageLoadAddress(image_module_sp.get(), image_infos[idx])) {
+ target_images.AppendIfNeeded(image_module_sp);
+ loaded_module_list.AppendIfNeeded(image_module_sp);
+ }
}
-}
+ }
-void
-DynamicLoaderDarwin::UpdateDYLDImageInfoFromNewImageInfo (ImageInfo &image_info)
-{
- if (image_info.header.filetype == llvm::MachO::MH_DYLINKER)
- {
- const bool can_create = true;
- ModuleSP dyld_sp = FindTargetModuleForImageInfo (image_info, can_create, NULL);
- if (dyld_sp.get())
- {
- Target &target = m_process->GetTarget();
- target.GetImages().AppendIfNeeded (dyld_sp);
- UpdateImageLoadAddress (dyld_sp.get(), image_info);
- SetDYLDModule (dyld_sp);
- }
- }
-}
-
-void
-DynamicLoaderDarwin::SetDYLDModule (lldb::ModuleSP &dyld_module_sp)
-{
- m_dyld_module_wp = dyld_module_sp;
-}
-
-ModuleSP
-DynamicLoaderDarwin::GetDYLDModule ()
-{
- ModuleSP dyld_sp (m_dyld_module_wp.lock());
- return dyld_sp;
-}
-
-bool
-DynamicLoaderDarwin::AddModulesUsingImageInfos (ImageInfo::collection &image_infos)
-{
- std::lock_guard<std::recursive_mutex> guard(m_mutex);
- // Now add these images to the main list.
- ModuleList loaded_module_list;
- Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_DYNAMIC_LOADER));
- Target &target = m_process->GetTarget();
- ModuleList& target_images = target.GetImages();
-
- for (uint32_t idx = 0; idx < image_infos.size(); ++idx)
- {
- if (log)
- {
- log->Printf ("Adding new image at address=0x%16.16" PRIx64 ".", image_infos[idx].address);
- image_infos[idx].PutToLog (log);
- }
-
- m_dyld_image_infos.push_back(image_infos[idx]);
-
- ModuleSP image_module_sp (FindTargetModuleForImageInfo (image_infos[idx], true, NULL));
-
- if (image_module_sp)
- {
- ObjectFile *objfile = image_module_sp->GetObjectFile ();
- if (objfile)
- {
- SectionList *sections = objfile->GetSectionList();
- if (sections)
- {
- ConstString commpage_dbstr("__commpage");
- Section *commpage_section = sections->FindSectionByName(commpage_dbstr).get();
- if (commpage_section)
- {
- ModuleSpec module_spec (objfile->GetFileSpec(), image_infos[idx].GetArchitecture ());
- module_spec.GetObjectName() = commpage_dbstr;
- ModuleSP commpage_image_module_sp(target_images.FindFirstModule (module_spec));
- if (!commpage_image_module_sp)
- {
- module_spec.SetObjectOffset (objfile->GetFileOffset() + commpage_section->GetFileOffset());
- module_spec.SetObjectSize (objfile->GetByteSize());
- commpage_image_module_sp = target.GetSharedModule (module_spec);
- if (!commpage_image_module_sp || commpage_image_module_sp->GetObjectFile() == NULL)
- {
- commpage_image_module_sp = m_process->ReadModuleFromMemory (image_infos[idx].file_spec,
- image_infos[idx].address);
- // Always load a memory image right away in the target in case
- // we end up trying to read the symbol table from memory... The
- // __LINKEDIT will need to be mapped so we can figure out where
- // the symbol table bits are...
- bool changed = false;
- UpdateImageLoadAddress (commpage_image_module_sp.get(), image_infos[idx]);
- target.GetImages().Append(commpage_image_module_sp);
- if (changed)
- {
- image_infos[idx].load_stop_id = m_process->GetStopID();
- loaded_module_list.AppendIfNeeded (commpage_image_module_sp);
- }
- }
- }
- }
- }
- }
-
- // UpdateImageLoadAddress will return true if any segments
- // change load address. We need to check this so we don't
- // mention that all loaded shared libraries are newly loaded
- // each time we hit out dyld breakpoint since dyld will list all
- // shared libraries each time.
- if (UpdateImageLoadAddress (image_module_sp.get(), image_infos[idx]))
- {
- target_images.AppendIfNeeded(image_module_sp);
- loaded_module_list.AppendIfNeeded (image_module_sp);
- }
- }
- }
-
- if (loaded_module_list.GetSize() > 0)
- {
- if (log)
- loaded_module_list.LogUUIDAndPaths (log, "DynamicLoaderDarwin::ModulesDidLoad");
- m_process->GetTarget().ModulesDidLoad (loaded_module_list);
- }
- return true;
+ if (loaded_module_list.GetSize() > 0) {
+ if (log)
+ loaded_module_list.LogUUIDAndPaths(log,
+ "DynamicLoaderDarwin::ModulesDidLoad");
+ m_process->GetTarget().ModulesDidLoad(loaded_module_list);
+ }
+ return true;
}
-
//----------------------------------------------------------------------
// On Mac OS X libobjc (the Objective-C runtime) has several critical dispatch
// functions written in hand-written assembly, and also have hand-written unwind
-// information in the eh_frame section. Normally we prefer analyzing the
-// assembly instructions of a currently executing frame to unwind from that frame --
+// information in the eh_frame section. Normally we prefer analyzing the
+// assembly instructions of a currently executing frame to unwind from that
+// frame --
// but on hand-written functions this profiling can fail. We should use the
// eh_frame instructions for these functions all the time.
//
@@ -736,532 +701,474 @@ DynamicLoaderDarwin::AddModulesUsingImag
// of our normal default assumption that they are not.
//----------------------------------------------------------------------
-bool
-DynamicLoaderDarwin::AlwaysRelyOnEHUnwindInfo (SymbolContext &sym_ctx)
-{
- ModuleSP module_sp;
- if (sym_ctx.symbol)
- {
- module_sp = sym_ctx.symbol->GetAddressRef().GetModule();
- }
- if (module_sp.get() == NULL && sym_ctx.function)
- {
- module_sp = sym_ctx.function->GetAddressRange().GetBaseAddress().GetModule();
- }
- if (module_sp.get() == NULL)
- return false;
-
- ObjCLanguageRuntime *objc_runtime = m_process->GetObjCLanguageRuntime();
- if (objc_runtime != NULL && objc_runtime->IsModuleObjCLibrary (module_sp))
- {
- return true;
- }
-
+bool DynamicLoaderDarwin::AlwaysRelyOnEHUnwindInfo(SymbolContext &sym_ctx) {
+ ModuleSP module_sp;
+ if (sym_ctx.symbol) {
+ module_sp = sym_ctx.symbol->GetAddressRef().GetModule();
+ }
+ if (module_sp.get() == NULL && sym_ctx.function) {
+ module_sp =
+ sym_ctx.function->GetAddressRange().GetBaseAddress().GetModule();
+ }
+ if (module_sp.get() == NULL)
return false;
-}
+ ObjCLanguageRuntime *objc_runtime = m_process->GetObjCLanguageRuntime();
+ if (objc_runtime != NULL && objc_runtime->IsModuleObjCLibrary(module_sp)) {
+ return true;
+ }
+ return false;
+}
//----------------------------------------------------------------------
// Dump a Segment to the file handle provided.
//----------------------------------------------------------------------
-void
-DynamicLoaderDarwin::Segment::PutToLog (Log *log, lldb::addr_t slide) const
-{
- if (log)
- {
- if (slide == 0)
- log->Printf ("\t\t%16s [0x%16.16" PRIx64 " - 0x%16.16" PRIx64 ")",
- name.AsCString(""),
- vmaddr + slide,
- vmaddr + slide + vmsize);
- else
- log->Printf ("\t\t%16s [0x%16.16" PRIx64 " - 0x%16.16" PRIx64 ") slide = 0x%" PRIx64,
- name.AsCString(""),
- vmaddr + slide,
- vmaddr + slide + vmsize,
- slide);
- }
+void DynamicLoaderDarwin::Segment::PutToLog(Log *log,
+ lldb::addr_t slide) const {
+ if (log) {
+ if (slide == 0)
+ log->Printf("\t\t%16s [0x%16.16" PRIx64 " - 0x%16.16" PRIx64 ")",
+ name.AsCString(""), vmaddr + slide, vmaddr + slide + vmsize);
+ else
+ log->Printf("\t\t%16s [0x%16.16" PRIx64 " - 0x%16.16" PRIx64
+ ") slide = 0x%" PRIx64,
+ name.AsCString(""), vmaddr + slide, vmaddr + slide + vmsize,
+ slide);
+ }
}
const DynamicLoaderDarwin::Segment *
-DynamicLoaderDarwin::ImageInfo::FindSegment (const ConstString &name) const
-{
- const size_t num_segments = segments.size();
- for (size_t i=0; i<num_segments; ++i)
- {
- if (segments[i].name == name)
- return &segments[i];
- }
- return NULL;
+DynamicLoaderDarwin::ImageInfo::FindSegment(const ConstString &name) const {
+ const size_t num_segments = segments.size();
+ for (size_t i = 0; i < num_segments; ++i) {
+ if (segments[i].name == name)
+ return &segments[i];
+ }
+ return NULL;
}
-
//----------------------------------------------------------------------
// Dump an image info structure to the file handle provided.
//----------------------------------------------------------------------
-void
-DynamicLoaderDarwin::ImageInfo::PutToLog (Log *log) const
-{
- if (log == NULL)
- return;
- const uint8_t *u = (const uint8_t *)uuid.GetBytes();
-
- if (address == LLDB_INVALID_ADDRESS)
- {
- if (u)
- {
- log->Printf("\t modtime=0x%8.8" PRIx64 " uuid=%2.2X%2.2X%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X%2.2X%2.2X%2.2X%2.2X path='%s' (UNLOADED)",
- mod_date,
- u[ 0], u[ 1], u[ 2], u[ 3],
- u[ 4], u[ 5], u[ 6], u[ 7],
- u[ 8], u[ 9], u[10], u[11],
- u[12], u[13], u[14], u[15],
- file_spec.GetPath().c_str());
- }
- else
- log->Printf("\t modtime=0x%8.8" PRIx64 " path='%s' (UNLOADED)",
- mod_date,
- file_spec.GetPath().c_str());
- }
- else
- {
- if (u)
- {
- log->Printf("\taddress=0x%16.16" PRIx64 " modtime=0x%8.8" PRIx64 " uuid=%2.2X%2.2X%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X%2.2X%2.2X%2.2X%2.2X path='%s'",
- address,
- mod_date,
- u[ 0], u[ 1], u[ 2], u[ 3],
- u[ 4], u[ 5], u[ 6], u[ 7],
- u[ 8], u[ 9], u[10], u[11],
- u[12], u[13], u[14], u[15],
- file_spec.GetPath().c_str());
- }
- else
- {
- log->Printf("\taddress=0x%16.16" PRIx64 " modtime=0x%8.8" PRIx64 " path='%s'",
- address,
- mod_date,
- file_spec.GetPath().c_str());
-
- }
- for (uint32_t i=0; i<segments.size(); ++i)
- segments[i].PutToLog(log, slide);
- }
-}
-
-void
-DynamicLoaderDarwin::PrivateInitialize(Process *process)
-{
- DEBUG_PRINTF("DynamicLoaderDarwin::%s() process state = %s\n", __FUNCTION__, StateAsCString(m_process->GetState()));
- Clear(true);
- m_process = process;
- m_process->GetTarget().ClearAllLoadedSections();
+void DynamicLoaderDarwin::ImageInfo::PutToLog(Log *log) const {
+ if (log == NULL)
+ return;
+ const uint8_t *u = (const uint8_t *)uuid.GetBytes();
+
+ if (address == LLDB_INVALID_ADDRESS) {
+ if (u) {
+ log->Printf("\t modtime=0x%8.8" PRIx64
+ " uuid=%2.2X%2.2X%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-"
+ "%2.2X%2.2X%2.2X%2.2X%2.2X%2.2X path='%s' (UNLOADED)",
+ mod_date, u[0], u[1], u[2], u[3], u[4], u[5], u[6], u[7],
+ u[8], u[9], u[10], u[11], u[12], u[13], u[14], u[15],
+ file_spec.GetPath().c_str());
+ } else
+ log->Printf("\t modtime=0x%8.8" PRIx64
+ " path='%s' (UNLOADED)",
+ mod_date, file_spec.GetPath().c_str());
+ } else {
+ if (u) {
+ log->Printf("\taddress=0x%16.16" PRIx64 " modtime=0x%8.8" PRIx64
+ " uuid=%2.2X%2.2X%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-"
+ "%2.2X%2.2X%2.2X%2.2X%2.2X%2.2X path='%s'",
+ address, mod_date, u[0], u[1], u[2], u[3], u[4], u[5], u[6],
+ u[7], u[8], u[9], u[10], u[11], u[12], u[13], u[14], u[15],
+ file_spec.GetPath().c_str());
+ } else {
+ log->Printf("\taddress=0x%16.16" PRIx64 " modtime=0x%8.8" PRIx64
+ " path='%s'",
+ address, mod_date, file_spec.GetPath().c_str());
+ }
+ for (uint32_t i = 0; i < segments.size(); ++i)
+ segments[i].PutToLog(log, slide);
+ }
+}
+
+void DynamicLoaderDarwin::PrivateInitialize(Process *process) {
+ DEBUG_PRINTF("DynamicLoaderDarwin::%s() process state = %s\n", __FUNCTION__,
+ StateAsCString(m_process->GetState()));
+ Clear(true);
+ m_process = process;
+ m_process->GetTarget().ClearAllLoadedSections();
}
//----------------------------------------------------------------------
// Member function that gets called when the process state changes.
//----------------------------------------------------------------------
-void
-DynamicLoaderDarwin::PrivateProcessStateChanged (Process *process, StateType state)
-{
- DEBUG_PRINTF("DynamicLoaderDarwin::%s(%s)\n", __FUNCTION__, StateAsCString(state));
- switch (state)
- {
- case eStateConnected:
- case eStateAttaching:
- case eStateLaunching:
- case eStateInvalid:
- case eStateUnloaded:
- case eStateExited:
- case eStateDetached:
- Clear(false);
- break;
-
- case eStateStopped:
- // Keep trying find dyld and set our notification breakpoint each time
- // we stop until we succeed
- if (!DidSetNotificationBreakpoint () && m_process->IsAlive())
- {
- if (NeedToDoInitialImageFetch ())
- DoInitialImageFetch ();
-
- SetNotificationBreakpoint ();
- }
- break;
-
- case eStateRunning:
- case eStateStepping:
- case eStateCrashed:
- case eStateSuspended:
- break;
- }
+void DynamicLoaderDarwin::PrivateProcessStateChanged(Process *process,
+ StateType state) {
+ DEBUG_PRINTF("DynamicLoaderDarwin::%s(%s)\n", __FUNCTION__,
+ StateAsCString(state));
+ switch (state) {
+ case eStateConnected:
+ case eStateAttaching:
+ case eStateLaunching:
+ case eStateInvalid:
+ case eStateUnloaded:
+ case eStateExited:
+ case eStateDetached:
+ Clear(false);
+ break;
+
+ case eStateStopped:
+ // Keep trying find dyld and set our notification breakpoint each time
+ // we stop until we succeed
+ if (!DidSetNotificationBreakpoint() && m_process->IsAlive()) {
+ if (NeedToDoInitialImageFetch())
+ DoInitialImageFetch();
+
+ SetNotificationBreakpoint();
+ }
+ break;
+
+ case eStateRunning:
+ case eStateStepping:
+ case eStateCrashed:
+ case eStateSuspended:
+ break;
+ }
}
ThreadPlanSP
-DynamicLoaderDarwin::GetStepThroughTrampolinePlan (Thread &thread, bool stop_others)
-{
- ThreadPlanSP thread_plan_sp;
- StackFrame *current_frame = thread.GetStackFrameAtIndex(0).get();
- const SymbolContext ¤t_context = current_frame->GetSymbolContext(eSymbolContextSymbol);
- Symbol *current_symbol = current_context.symbol;
- Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
- TargetSP target_sp (thread.CalculateTarget());
-
- if (current_symbol != NULL)
- {
- std::vector<Address> addresses;
-
- if (current_symbol->IsTrampoline())
- {
- const ConstString &trampoline_name = current_symbol->GetMangled().GetName(current_symbol->GetLanguage(), Mangled::ePreferMangled);
-
- if (trampoline_name)
- {
- const ModuleList &images = target_sp->GetImages();
-
- SymbolContextList code_symbols;
- images.FindSymbolsWithNameAndType(trampoline_name, eSymbolTypeCode, code_symbols);
- size_t num_code_symbols = code_symbols.GetSize();
-
- if (num_code_symbols > 0)
- {
- for (uint32_t i = 0; i < num_code_symbols; i++)
- {
- SymbolContext context;
- AddressRange addr_range;
- if (code_symbols.GetContextAtIndex(i, context))
- {
- context.GetAddressRange (eSymbolContextEverything, 0, false, addr_range);
- addresses.push_back(addr_range.GetBaseAddress());
- if (log)
- {
- addr_t load_addr = addr_range.GetBaseAddress().GetLoadAddress(target_sp.get());
-
- log->Printf ("Found a trampoline target symbol at 0x%" PRIx64 ".", load_addr);
- }
- }
- }
- }
-
- SymbolContextList reexported_symbols;
- images.FindSymbolsWithNameAndType(trampoline_name, eSymbolTypeReExported, reexported_symbols);
- size_t num_reexported_symbols = reexported_symbols.GetSize();
- if (num_reexported_symbols > 0)
- {
- for (uint32_t i = 0; i < num_reexported_symbols; i++)
- {
- SymbolContext context;
- if (reexported_symbols.GetContextAtIndex(i, context))
- {
- if (context.symbol)
- {
- Symbol *actual_symbol = context.symbol->ResolveReExportedSymbol(*target_sp.get());
- if (actual_symbol)
- {
- const Address actual_symbol_addr = actual_symbol->GetAddress();
- if (actual_symbol_addr.IsValid())
- {
- addresses.push_back(actual_symbol_addr);
- if (log)
- {
- lldb::addr_t load_addr = actual_symbol_addr.GetLoadAddress(target_sp.get());
- log->Printf ("Found a re-exported symbol: %s at 0x%" PRIx64 ".",
- actual_symbol->GetName().GetCString(), load_addr);
- }
- }
- }
- }
- }
- }
- }
-
- SymbolContextList indirect_symbols;
- images.FindSymbolsWithNameAndType(trampoline_name, eSymbolTypeResolver, indirect_symbols);
- size_t num_indirect_symbols = indirect_symbols.GetSize();
- if (num_indirect_symbols > 0)
- {
- for (uint32_t i = 0; i < num_indirect_symbols; i++)
- {
- SymbolContext context;
- AddressRange addr_range;
- if (indirect_symbols.GetContextAtIndex(i, context))
- {
- context.GetAddressRange (eSymbolContextEverything, 0, false, addr_range);
- addresses.push_back(addr_range.GetBaseAddress());
- if (log)
- {
- addr_t load_addr = addr_range.GetBaseAddress().GetLoadAddress(target_sp.get());
-
- log->Printf ("Found an indirect target symbol at 0x%" PRIx64 ".", load_addr);
- }
- }
- }
- }
+DynamicLoaderDarwin::GetStepThroughTrampolinePlan(Thread &thread,
+ bool stop_others) {
+ ThreadPlanSP thread_plan_sp;
+ StackFrame *current_frame = thread.GetStackFrameAtIndex(0).get();
+ const SymbolContext ¤t_context =
+ current_frame->GetSymbolContext(eSymbolContextSymbol);
+ Symbol *current_symbol = current_context.symbol;
+ Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
+ TargetSP target_sp(thread.CalculateTarget());
+
+ if (current_symbol != NULL) {
+ std::vector<Address> addresses;
+
+ if (current_symbol->IsTrampoline()) {
+ const ConstString &trampoline_name = current_symbol->GetMangled().GetName(
+ current_symbol->GetLanguage(), Mangled::ePreferMangled);
+
+ if (trampoline_name) {
+ const ModuleList &images = target_sp->GetImages();
+
+ SymbolContextList code_symbols;
+ images.FindSymbolsWithNameAndType(trampoline_name, eSymbolTypeCode,
+ code_symbols);
+ size_t num_code_symbols = code_symbols.GetSize();
+
+ if (num_code_symbols > 0) {
+ for (uint32_t i = 0; i < num_code_symbols; i++) {
+ SymbolContext context;
+ AddressRange addr_range;
+ if (code_symbols.GetContextAtIndex(i, context)) {
+ context.GetAddressRange(eSymbolContextEverything, 0, false,
+ addr_range);
+ addresses.push_back(addr_range.GetBaseAddress());
+ if (log) {
+ addr_t load_addr =
+ addr_range.GetBaseAddress().GetLoadAddress(target_sp.get());
+
+ log->Printf("Found a trampoline target symbol at 0x%" PRIx64
+ ".",
+ load_addr);
+ }
}
+ }
}
- else if (current_symbol->GetType() == eSymbolTypeReExported)
- {
- // I am not sure we could ever end up stopped AT a re-exported symbol. But just in case:
-
- const Symbol *actual_symbol = current_symbol->ResolveReExportedSymbol(*(target_sp.get()));
- if (actual_symbol)
- {
- Address target_addr(actual_symbol->GetAddress());
- if (target_addr.IsValid())
- {
- if (log)
- log->Printf ("Found a re-exported symbol: %s pointing to: %s at 0x%" PRIx64 ".",
- current_symbol->GetName().GetCString(),
- actual_symbol->GetName().GetCString(),
- target_addr.GetLoadAddress(target_sp.get()));
- addresses.push_back (target_addr.GetLoadAddress(target_sp.get()));
-
- }
- }
- }
-
- if (addresses.size() > 0)
- {
- // First check whether any of the addresses point to Indirect symbols, and if they do, resolve them:
- std::vector<lldb::addr_t> load_addrs;
- for (Address address : addresses)
- {
- Symbol *symbol = address.CalculateSymbolContextSymbol();
- if (symbol && symbol->IsIndirect())
- {
- Error error;
- Address symbol_address = symbol->GetAddress();
- addr_t resolved_addr = thread.GetProcess()->ResolveIndirectFunction(&symbol_address, error);
- if (error.Success())
- {
- load_addrs.push_back(resolved_addr);
- if (log)
- log->Printf("ResolveIndirectFunction found resolved target for %s at 0x%" PRIx64 ".",
- symbol->GetName().GetCString(), resolved_addr);
+
+ SymbolContextList reexported_symbols;
+ images.FindSymbolsWithNameAndType(
+ trampoline_name, eSymbolTypeReExported, reexported_symbols);
+ size_t num_reexported_symbols = reexported_symbols.GetSize();
+ if (num_reexported_symbols > 0) {
+ for (uint32_t i = 0; i < num_reexported_symbols; i++) {
+ SymbolContext context;
+ if (reexported_symbols.GetContextAtIndex(i, context)) {
+ if (context.symbol) {
+ Symbol *actual_symbol =
+ context.symbol->ResolveReExportedSymbol(*target_sp.get());
+ if (actual_symbol) {
+ const Address actual_symbol_addr =
+ actual_symbol->GetAddress();
+ if (actual_symbol_addr.IsValid()) {
+ addresses.push_back(actual_symbol_addr);
+ if (log) {
+ lldb::addr_t load_addr =
+ actual_symbol_addr.GetLoadAddress(target_sp.get());
+ log->Printf(
+ "Found a re-exported symbol: %s at 0x%" PRIx64 ".",
+ actual_symbol->GetName().GetCString(), load_addr);
}
+ }
}
- else
- {
- load_addrs.push_back(address.GetLoadAddress(target_sp.get()));
- }
-
+ }
}
- thread_plan_sp.reset (new ThreadPlanRunToAddress (thread, load_addrs, stop_others));
+ }
}
- }
- else
- {
- if (log)
- log->Printf ("Could not find symbol for step through.");
- }
-
- return thread_plan_sp;
-}
-
-size_t
-DynamicLoaderDarwin::FindEquivalentSymbols (lldb_private::Symbol *original_symbol,
- lldb_private::ModuleList &images,
- lldb_private::SymbolContextList &equivalent_symbols)
-{
- const ConstString &trampoline_name = original_symbol->GetMangled().GetName(original_symbol->GetLanguage(), Mangled::ePreferMangled);
- if (!trampoline_name)
- return 0;
-
- size_t initial_size = equivalent_symbols.GetSize();
-
- static const char *resolver_name_regex = "(_gc|_non_gc|\\$[A-Za-z0-9\\$]+)$";
- std::string equivalent_regex_buf("^");
- equivalent_regex_buf.append (trampoline_name.GetCString());
- equivalent_regex_buf.append (resolver_name_regex);
-
- RegularExpression equivalent_name_regex (equivalent_regex_buf.c_str());
- const bool append = true;
- images.FindSymbolsMatchingRegExAndType (equivalent_name_regex, eSymbolTypeCode, equivalent_symbols, append);
-
- return equivalent_symbols.GetSize() - initial_size;
-}
-
-lldb::ModuleSP
-DynamicLoaderDarwin::GetPThreadLibraryModule()
-{
- ModuleSP module_sp = m_libpthread_module_wp.lock();
- if (!module_sp)
- {
- SymbolContextList sc_list;
- ModuleSpec module_spec;
- module_spec.GetFileSpec().GetFilename().SetCString("libsystem_pthread.dylib");
- ModuleList module_list;
- if (m_process->GetTarget().GetImages().FindModules(module_spec, module_list))
- {
- if (module_list.GetSize() == 1)
- {
- module_sp = module_list.GetModuleAtIndex(0);
- if (module_sp)
- m_libpthread_module_wp = module_sp;
+
+ SymbolContextList indirect_symbols;
+ images.FindSymbolsWithNameAndType(trampoline_name, eSymbolTypeResolver,
+ indirect_symbols);
+ size_t num_indirect_symbols = indirect_symbols.GetSize();
+ if (num_indirect_symbols > 0) {
+ for (uint32_t i = 0; i < num_indirect_symbols; i++) {
+ SymbolContext context;
+ AddressRange addr_range;
+ if (indirect_symbols.GetContextAtIndex(i, context)) {
+ context.GetAddressRange(eSymbolContextEverything, 0, false,
+ addr_range);
+ addresses.push_back(addr_range.GetBaseAddress());
+ if (log) {
+ addr_t load_addr =
+ addr_range.GetBaseAddress().GetLoadAddress(target_sp.get());
+
+ log->Printf("Found an indirect target symbol at 0x%" PRIx64 ".",
+ load_addr);
+ }
}
+ }
}
+ }
+ } else if (current_symbol->GetType() == eSymbolTypeReExported) {
+ // I am not sure we could ever end up stopped AT a re-exported symbol.
+ // But just in case:
+
+ const Symbol *actual_symbol =
+ current_symbol->ResolveReExportedSymbol(*(target_sp.get()));
+ if (actual_symbol) {
+ Address target_addr(actual_symbol->GetAddress());
+ if (target_addr.IsValid()) {
+ if (log)
+ log->Printf(
+ "Found a re-exported symbol: %s pointing to: %s at 0x%" PRIx64
+ ".",
+ current_symbol->GetName().GetCString(),
+ actual_symbol->GetName().GetCString(),
+ target_addr.GetLoadAddress(target_sp.get()));
+ addresses.push_back(target_addr.GetLoadAddress(target_sp.get()));
+ }
+ }
+ }
+
+ if (addresses.size() > 0) {
+ // First check whether any of the addresses point to Indirect symbols, and
+ // if they do, resolve them:
+ std::vector<lldb::addr_t> load_addrs;
+ for (Address address : addresses) {
+ Symbol *symbol = address.CalculateSymbolContextSymbol();
+ if (symbol && symbol->IsIndirect()) {
+ Error error;
+ Address symbol_address = symbol->GetAddress();
+ addr_t resolved_addr = thread.GetProcess()->ResolveIndirectFunction(
+ &symbol_address, error);
+ if (error.Success()) {
+ load_addrs.push_back(resolved_addr);
+ if (log)
+ log->Printf("ResolveIndirectFunction found resolved target for "
+ "%s at 0x%" PRIx64 ".",
+ symbol->GetName().GetCString(), resolved_addr);
+ }
+ } else {
+ load_addrs.push_back(address.GetLoadAddress(target_sp.get()));
+ }
+ }
+ thread_plan_sp.reset(
+ new ThreadPlanRunToAddress(thread, load_addrs, stop_others));
}
- return module_sp;
+ } else {
+ if (log)
+ log->Printf("Could not find symbol for step through.");
+ }
+
+ return thread_plan_sp;
}
-Address
-DynamicLoaderDarwin::GetPthreadSetSpecificAddress()
-{
- if (!m_pthread_getspecific_addr.IsValid())
- {
- ModuleSP module_sp = GetPThreadLibraryModule();
+size_t DynamicLoaderDarwin::FindEquivalentSymbols(
+ lldb_private::Symbol *original_symbol, lldb_private::ModuleList &images,
+ lldb_private::SymbolContextList &equivalent_symbols) {
+ const ConstString &trampoline_name = original_symbol->GetMangled().GetName(
+ original_symbol->GetLanguage(), Mangled::ePreferMangled);
+ if (!trampoline_name)
+ return 0;
+
+ size_t initial_size = equivalent_symbols.GetSize();
+
+ static const char *resolver_name_regex = "(_gc|_non_gc|\\$[A-Za-z0-9\\$]+)$";
+ std::string equivalent_regex_buf("^");
+ equivalent_regex_buf.append(trampoline_name.GetCString());
+ equivalent_regex_buf.append(resolver_name_regex);
+
+ RegularExpression equivalent_name_regex(equivalent_regex_buf.c_str());
+ const bool append = true;
+ images.FindSymbolsMatchingRegExAndType(equivalent_name_regex, eSymbolTypeCode,
+ equivalent_symbols, append);
+
+ return equivalent_symbols.GetSize() - initial_size;
+}
+
+lldb::ModuleSP DynamicLoaderDarwin::GetPThreadLibraryModule() {
+ ModuleSP module_sp = m_libpthread_module_wp.lock();
+ if (!module_sp) {
+ SymbolContextList sc_list;
+ ModuleSpec module_spec;
+ module_spec.GetFileSpec().GetFilename().SetCString(
+ "libsystem_pthread.dylib");
+ ModuleList module_list;
+ if (m_process->GetTarget().GetImages().FindModules(module_spec,
+ module_list)) {
+ if (module_list.GetSize() == 1) {
+ module_sp = module_list.GetModuleAtIndex(0);
if (module_sp)
- {
- lldb_private::SymbolContextList sc_list;
- module_sp->FindSymbolsWithNameAndType(ConstString("pthread_getspecific"), eSymbolTypeCode, sc_list);
- SymbolContext sc;
- if (sc_list.GetContextAtIndex(0, sc))
- {
- if (sc.symbol)
- m_pthread_getspecific_addr = sc.symbol->GetAddress();
- }
- }
+ m_libpthread_module_wp = module_sp;
+ }
}
- return m_pthread_getspecific_addr;
+ }
+ return module_sp;
+}
+
+Address DynamicLoaderDarwin::GetPthreadSetSpecificAddress() {
+ if (!m_pthread_getspecific_addr.IsValid()) {
+ ModuleSP module_sp = GetPThreadLibraryModule();
+ if (module_sp) {
+ lldb_private::SymbolContextList sc_list;
+ module_sp->FindSymbolsWithNameAndType(ConstString("pthread_getspecific"),
+ eSymbolTypeCode, sc_list);
+ SymbolContext sc;
+ if (sc_list.GetContextAtIndex(0, sc)) {
+ if (sc.symbol)
+ m_pthread_getspecific_addr = sc.symbol->GetAddress();
+ }
+ }
+ }
+ return m_pthread_getspecific_addr;
}
lldb::addr_t
-DynamicLoaderDarwin::GetThreadLocalData(const lldb::ModuleSP module_sp, const lldb::ThreadSP thread_sp,
- lldb::addr_t tls_file_addr)
-{
- if (!thread_sp || !module_sp)
- return LLDB_INVALID_ADDRESS;
-
- std::lock_guard<std::recursive_mutex> guard(m_mutex);
-
- const uint32_t addr_size = m_process->GetAddressByteSize();
- uint8_t buf[sizeof(lldb::addr_t) * 3];
-
- lldb_private::Address tls_addr;
- if (module_sp->ResolveFileAddress(tls_file_addr, tls_addr))
- {
- Error error;
- const size_t tsl_data_size = addr_size * 3;
- Target &target = m_process->GetTarget();
- if (target.ReadMemory(tls_addr, false, buf, tsl_data_size, error) == tsl_data_size)
- {
- const ByteOrder byte_order = m_process->GetByteOrder();
- DataExtractor data(buf, sizeof(buf), byte_order, addr_size);
- lldb::offset_t offset = addr_size; // Skip the first pointer
- const lldb::addr_t pthread_key = data.GetAddress(&offset);
- const lldb::addr_t tls_offset = data.GetAddress(&offset);
- if (pthread_key != 0)
- {
- // First check to see if we have already figured out the location
- // of TLS data for the pthread_key on a specific thread yet. If we
- // have we can re-use it since its location will not change unless
- // the process execs.
- const tid_t tid = thread_sp->GetID();
- auto tid_pos = m_tid_to_tls_map.find(tid);
- if (tid_pos != m_tid_to_tls_map.end())
- {
- auto tls_pos = tid_pos->second.find(pthread_key);
- if (tls_pos != tid_pos->second.end())
- {
- return tls_pos->second + tls_offset;
- }
- }
- StackFrameSP frame_sp = thread_sp->GetStackFrameAtIndex(0);
- if (frame_sp)
- {
- ClangASTContext *clang_ast_context = target.GetScratchClangASTContext();
-
- if (!clang_ast_context)
- return LLDB_INVALID_ADDRESS;
-
- CompilerType clang_void_ptr_type = clang_ast_context->GetBasicType(eBasicTypeVoid).GetPointerType();
- Address pthread_getspecific_addr = GetPthreadSetSpecificAddress();
- if (pthread_getspecific_addr.IsValid())
- {
- EvaluateExpressionOptions options;
-
- lldb::ThreadPlanSP thread_plan_sp(
- new ThreadPlanCallFunction(*thread_sp, pthread_getspecific_addr, clang_void_ptr_type,
- llvm::ArrayRef<lldb::addr_t>(pthread_key), options));
-
- DiagnosticManager execution_errors;
- ExecutionContext exe_ctx(thread_sp);
- lldb::ExpressionResults results =
- m_process->RunThreadPlan(exe_ctx, thread_plan_sp, options, execution_errors);
-
- if (results == lldb::eExpressionCompleted)
- {
- lldb::ValueObjectSP result_valobj_sp = thread_plan_sp->GetReturnValueObject();
- if (result_valobj_sp)
- {
- const lldb::addr_t pthread_key_data = result_valobj_sp->GetValueAsUnsigned(0);
- if (pthread_key_data)
- {
- m_tid_to_tls_map[tid].insert(std::make_pair(pthread_key, pthread_key_data));
- return pthread_key_data + tls_offset;
- }
- }
- }
- }
+DynamicLoaderDarwin::GetThreadLocalData(const lldb::ModuleSP module_sp,
+ const lldb::ThreadSP thread_sp,
+ lldb::addr_t tls_file_addr) {
+ if (!thread_sp || !module_sp)
+ return LLDB_INVALID_ADDRESS;
+
+ std::lock_guard<std::recursive_mutex> guard(m_mutex);
+
+ const uint32_t addr_size = m_process->GetAddressByteSize();
+ uint8_t buf[sizeof(lldb::addr_t) * 3];
+
+ lldb_private::Address tls_addr;
+ if (module_sp->ResolveFileAddress(tls_file_addr, tls_addr)) {
+ Error error;
+ const size_t tsl_data_size = addr_size * 3;
+ Target &target = m_process->GetTarget();
+ if (target.ReadMemory(tls_addr, false, buf, tsl_data_size, error) ==
+ tsl_data_size) {
+ const ByteOrder byte_order = m_process->GetByteOrder();
+ DataExtractor data(buf, sizeof(buf), byte_order, addr_size);
+ lldb::offset_t offset = addr_size; // Skip the first pointer
+ const lldb::addr_t pthread_key = data.GetAddress(&offset);
+ const lldb::addr_t tls_offset = data.GetAddress(&offset);
+ if (pthread_key != 0) {
+ // First check to see if we have already figured out the location
+ // of TLS data for the pthread_key on a specific thread yet. If we
+ // have we can re-use it since its location will not change unless
+ // the process execs.
+ const tid_t tid = thread_sp->GetID();
+ auto tid_pos = m_tid_to_tls_map.find(tid);
+ if (tid_pos != m_tid_to_tls_map.end()) {
+ auto tls_pos = tid_pos->second.find(pthread_key);
+ if (tls_pos != tid_pos->second.end()) {
+ return tls_pos->second + tls_offset;
+ }
+ }
+ StackFrameSP frame_sp = thread_sp->GetStackFrameAtIndex(0);
+ if (frame_sp) {
+ ClangASTContext *clang_ast_context =
+ target.GetScratchClangASTContext();
+
+ if (!clang_ast_context)
+ return LLDB_INVALID_ADDRESS;
+
+ CompilerType clang_void_ptr_type =
+ clang_ast_context->GetBasicType(eBasicTypeVoid).GetPointerType();
+ Address pthread_getspecific_addr = GetPthreadSetSpecificAddress();
+ if (pthread_getspecific_addr.IsValid()) {
+ EvaluateExpressionOptions options;
+
+ lldb::ThreadPlanSP thread_plan_sp(new ThreadPlanCallFunction(
+ *thread_sp, pthread_getspecific_addr, clang_void_ptr_type,
+ llvm::ArrayRef<lldb::addr_t>(pthread_key), options));
+
+ DiagnosticManager execution_errors;
+ ExecutionContext exe_ctx(thread_sp);
+ lldb::ExpressionResults results = m_process->RunThreadPlan(
+ exe_ctx, thread_plan_sp, options, execution_errors);
+
+ if (results == lldb::eExpressionCompleted) {
+ lldb::ValueObjectSP result_valobj_sp =
+ thread_plan_sp->GetReturnValueObject();
+ if (result_valobj_sp) {
+ const lldb::addr_t pthread_key_data =
+ result_valobj_sp->GetValueAsUnsigned(0);
+ if (pthread_key_data) {
+ m_tid_to_tls_map[tid].insert(
+ std::make_pair(pthread_key, pthread_key_data));
+ return pthread_key_data + tls_offset;
}
+ }
}
+ }
}
+ }
}
- return LLDB_INVALID_ADDRESS;
+ }
+ return LLDB_INVALID_ADDRESS;
}
-bool
-DynamicLoaderDarwin::UseDYLDSPI (Process *process)
-{
- Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_DYNAMIC_LOADER));
- uint32_t major, minor, update;
-
- bool use_new_spi_interface = false;
-
- if (process->GetHostOSVersion (major, minor, update))
- {
- const llvm::Triple::OSType os_type = process->GetTarget().GetArchitecture().GetTriple().getOS();
-
- // macOS 10.12 and newer
- if (os_type == llvm::Triple::MacOSX
- && (major >= 10 || (major == 10 && minor >= 12)))
- {
- use_new_spi_interface = true;
- }
+bool DynamicLoaderDarwin::UseDYLDSPI(Process *process) {
+ Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
+ uint32_t major, minor, update;
- // iOS 10 and newer
- if (os_type == llvm::Triple::IOS && major >= 10)
- {
- use_new_spi_interface = true;
- }
+ bool use_new_spi_interface = false;
- // tvOS 10 and newer
- if (os_type == llvm::Triple::TvOS && major >= 10)
- {
- use_new_spi_interface = true;
- }
+ if (process->GetHostOSVersion(major, minor, update)) {
+ const llvm::Triple::OSType os_type =
+ process->GetTarget().GetArchitecture().GetTriple().getOS();
- // watchOS 3 and newer
- if (os_type == llvm::Triple::WatchOS && major >= 3)
- {
- use_new_spi_interface = true;
- }
+ // macOS 10.12 and newer
+ if (os_type == llvm::Triple::MacOSX &&
+ (major >= 10 || (major == 10 && minor >= 12))) {
+ use_new_spi_interface = true;
}
+ // iOS 10 and newer
+ if (os_type == llvm::Triple::IOS && major >= 10) {
+ use_new_spi_interface = true;
+ }
- // FIXME: Temporarily force the use of the old DynamicLoader plugin until all
- // the different use cases have been tested & the updated SPIs are available
- // everywhere.
- use_new_spi_interface = false;
-
- if (log)
- {
- if (use_new_spi_interface)
- log->Printf ("DynamicLoaderDarwin::UseDYLDSPI: Use new DynamicLoader plugin");
- else
- log->Printf ("DynamicLoaderDarwin::UseDYLDSPI: Use old DynamicLoader plugin");
+ // tvOS 10 and newer
+ if (os_type == llvm::Triple::TvOS && major >= 10) {
+ use_new_spi_interface = true;
+ }
+ // watchOS 3 and newer
+ if (os_type == llvm::Triple::WatchOS && major >= 3) {
+ use_new_spi_interface = true;
}
- return use_new_spi_interface;
+ }
+
+ // FIXME: Temporarily force the use of the old DynamicLoader plugin until all
+ // the different use cases have been tested & the updated SPIs are available
+ // everywhere.
+ use_new_spi_interface = false;
+
+ if (log) {
+ if (use_new_spi_interface)
+ log->Printf(
+ "DynamicLoaderDarwin::UseDYLDSPI: Use new DynamicLoader plugin");
+ else
+ log->Printf(
+ "DynamicLoaderDarwin::UseDYLDSPI: Use old DynamicLoader plugin");
+ }
+ return use_new_spi_interface;
}
Modified: lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.h (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.h Tue Sep 6 15:57:50 2016
@@ -18,10 +18,10 @@
// Other libraries and framework includes
// Project includes
-#include "lldb/Target/DynamicLoader.h"
-#include "lldb/Host/FileSpec.h"
#include "lldb/Core/StructuredData.h"
#include "lldb/Core/UUID.h"
+#include "lldb/Host/FileSpec.h"
+#include "lldb/Target/DynamicLoader.h"
#include "lldb/Target/Process.h"
#include "lldb/Utility/SafeMachO.h"
@@ -29,277 +29,215 @@
namespace lldb_private {
-class DynamicLoaderDarwin : public lldb_private::DynamicLoader
-{
+class DynamicLoaderDarwin : public lldb_private::DynamicLoader {
public:
- DynamicLoaderDarwin(lldb_private::Process *process);
+ DynamicLoaderDarwin(lldb_private::Process *process);
+
+ virtual ~DynamicLoaderDarwin() override;
- virtual ~DynamicLoaderDarwin() override;
+ //------------------------------------------------------------------
+ /// Called after attaching a process.
+ ///
+ /// Allow DynamicLoader plug-ins to execute some code after
+ /// attaching to a process.
+ //------------------------------------------------------------------
+ void DidAttach() override;
- //------------------------------------------------------------------
- /// Called after attaching a process.
- ///
- /// Allow DynamicLoader plug-ins to execute some code after
- /// attaching to a process.
- //------------------------------------------------------------------
- void
- DidAttach() override;
-
- void
- DidLaunch() override;
-
- lldb::ThreadPlanSP
- GetStepThroughTrampolinePlan(lldb_private::Thread &thread,
- bool stop_others) override;
-
- size_t
- FindEquivalentSymbols(lldb_private::Symbol *original_symbol,
- lldb_private::ModuleList &module_list,
- lldb_private::SymbolContextList &equivalent_symbols) override;
-
- lldb::addr_t
- GetThreadLocalData(const lldb::ModuleSP module, const lldb::ThreadSP thread, lldb::addr_t tls_file_addr) override;
+ void DidLaunch() override;
- bool
- AlwaysRelyOnEHUnwindInfo(lldb_private::SymbolContext &sym_ctx) override;
+ lldb::ThreadPlanSP GetStepThroughTrampolinePlan(lldb_private::Thread &thread,
+ bool stop_others) override;
- virtual void
- DoInitialImageFetch () = 0;
+ size_t FindEquivalentSymbols(
+ lldb_private::Symbol *original_symbol,
+ lldb_private::ModuleList &module_list,
+ lldb_private::SymbolContextList &equivalent_symbols) override;
- virtual bool
- NeedToDoInitialImageFetch () = 0;
+ lldb::addr_t GetThreadLocalData(const lldb::ModuleSP module,
+ const lldb::ThreadSP thread,
+ lldb::addr_t tls_file_addr) override;
+
+ bool AlwaysRelyOnEHUnwindInfo(lldb_private::SymbolContext &sym_ctx) override;
+
+ virtual void DoInitialImageFetch() = 0;
+
+ virtual bool NeedToDoInitialImageFetch() = 0;
protected:
- void
- PrivateInitialize (lldb_private::Process *process);
+ void PrivateInitialize(lldb_private::Process *process);
+
+ void PrivateProcessStateChanged(lldb_private::Process *process,
+ lldb::StateType state);
+
+ void Clear(bool clear_process);
- void
- PrivateProcessStateChanged (lldb_private::Process *process,
- lldb::StateType state);
-
- void
- Clear (bool clear_process);
-
- // Clear method for classes derived from this one
- virtual void
- DoClear () = 0;
-
- void
- SetDYLDModule (lldb::ModuleSP &dyld_module_sp);
-
- lldb::ModuleSP
- GetDYLDModule ();
-
- class Segment
- {
- public:
- Segment() :
- name(),
- vmaddr(LLDB_INVALID_ADDRESS),
- vmsize(0),
- fileoff(0),
- filesize(0),
- maxprot(0),
- initprot(0),
- nsects(0),
- flags(0)
- {
- }
-
- lldb_private::ConstString name;
- lldb::addr_t vmaddr;
- lldb::addr_t vmsize;
- lldb::addr_t fileoff;
- lldb::addr_t filesize;
- uint32_t maxprot;
- uint32_t initprot;
- uint32_t nsects;
- uint32_t flags;
-
- bool
- operator==(const Segment& rhs) const
- {
- return name == rhs.name && vmaddr == rhs.vmaddr && vmsize == rhs.vmsize;
- }
-
- void
- PutToLog (lldb_private::Log *log,
- lldb::addr_t slide) const;
-
- };
-
- struct ImageInfo
- {
- lldb::addr_t address; // Address of mach header for this dylib
- lldb::addr_t slide; // The amount to slide all segments by if there is a global slide.
- lldb::addr_t mod_date; // Modification date for this dylib
- lldb_private::FileSpec file_spec; // Resolved path for this dylib
- lldb_private::UUID uuid; // UUID for this dylib if it has one, else all zeros
- llvm::MachO::mach_header header; // The mach header for this image
- std::vector<Segment> segments; // All segment vmaddr and vmsize pairs for this executable (from memory of inferior)
- uint32_t load_stop_id; // The process stop ID that the sections for this image were loaded
- llvm::Triple::OSType os_type; // LC_VERSION_MIN_... load command os type
- std::string min_version_os_sdk; // LC_VERSION_MIN_... sdk value
-
- ImageInfo() :
- address(LLDB_INVALID_ADDRESS),
- slide(0),
- mod_date(0),
- file_spec(),
- uuid(),
- header(),
- segments(),
- load_stop_id(0),
- os_type (llvm::Triple::OSType::UnknownOS),
- min_version_os_sdk()
- {
- }
-
- void
- Clear(bool load_cmd_data_only)
- {
- if (!load_cmd_data_only)
- {
- address = LLDB_INVALID_ADDRESS;
- slide = 0;
- mod_date = 0;
- file_spec.Clear();
- ::memset (&header, 0, sizeof(header));
- }
- uuid.Clear();
- segments.clear();
- load_stop_id = 0;
- os_type = llvm::Triple::OSType::UnknownOS;
- min_version_os_sdk.clear();
- }
-
- bool
- operator == (const ImageInfo& rhs) const
- {
- return address == rhs.address
- && slide == rhs.slide
- && mod_date == rhs.mod_date
- && file_spec == rhs.file_spec
- && uuid == rhs.uuid
- && memcmp(&header, &rhs.header, sizeof(header)) == 0
- && segments == rhs.segments
- && os_type == rhs.os_type;
- }
-
- bool
- UUIDValid() const
- {
- return uuid.IsValid();
- }
-
- uint32_t
- GetAddressByteSize ()
- {
- if (header.cputype)
- {
- if (header.cputype & llvm::MachO::CPU_ARCH_ABI64)
- return 8;
- else
- return 4;
- }
- return 0;
- }
-
- lldb_private::ArchSpec
- GetArchitecture () const
- {
- return lldb_private::ArchSpec (lldb_private::eArchTypeMachO, header.cputype, header.cpusubtype);
- }
-
- const Segment *
- FindSegment (const lldb_private::ConstString &name) const;
-
- void
- PutToLog (lldb_private::Log *log) const;
-
- typedef std::vector<ImageInfo> collection;
- typedef collection::iterator iterator;
- typedef collection::const_iterator const_iterator;
- };
-
- bool
- UpdateImageLoadAddress(lldb_private::Module *module, ImageInfo& info);
-
- bool
- UnloadModuleSections (lldb_private::Module *module, ImageInfo& info);
-
- lldb::ModuleSP
- FindTargetModuleForImageInfo (ImageInfo &image_info,
- bool can_create,
- bool *did_create_ptr);
-
- void
- UnloadImages (const std::vector<lldb::addr_t> &solib_addresses);
-
- void
- UnloadAllImages ();
-
- virtual bool
- SetNotificationBreakpoint () = 0;
-
- virtual void
- ClearNotificationBreakpoint () = 0;
-
- virtual bool
- DidSetNotificationBreakpoint () = 0;
-
- typedef std::map<uint64_t, lldb::addr_t> PthreadKeyToTLSMap;
- typedef std::map<lldb::user_id_t, PthreadKeyToTLSMap> ThreadIDToTLSMap;
-
- std::recursive_mutex &
- GetMutex () const
- {
- return m_mutex;
+ // Clear method for classes derived from this one
+ virtual void DoClear() = 0;
+
+ void SetDYLDModule(lldb::ModuleSP &dyld_module_sp);
+
+ lldb::ModuleSP GetDYLDModule();
+
+ class Segment {
+ public:
+ Segment()
+ : name(), vmaddr(LLDB_INVALID_ADDRESS), vmsize(0), fileoff(0),
+ filesize(0), maxprot(0), initprot(0), nsects(0), flags(0) {}
+
+ lldb_private::ConstString name;
+ lldb::addr_t vmaddr;
+ lldb::addr_t vmsize;
+ lldb::addr_t fileoff;
+ lldb::addr_t filesize;
+ uint32_t maxprot;
+ uint32_t initprot;
+ uint32_t nsects;
+ uint32_t flags;
+
+ bool operator==(const Segment &rhs) const {
+ return name == rhs.name && vmaddr == rhs.vmaddr && vmsize == rhs.vmsize;
+ }
+
+ void PutToLog(lldb_private::Log *log, lldb::addr_t slide) const;
+ };
+
+ struct ImageInfo {
+ lldb::addr_t address; // Address of mach header for this dylib
+ lldb::addr_t slide; // The amount to slide all segments by if there is a
+ // global slide.
+ lldb::addr_t mod_date; // Modification date for this dylib
+ lldb_private::FileSpec file_spec; // Resolved path for this dylib
+ lldb_private::UUID
+ uuid; // UUID for this dylib if it has one, else all zeros
+ llvm::MachO::mach_header header; // The mach header for this image
+ std::vector<Segment> segments; // All segment vmaddr and vmsize pairs for
+ // this executable (from memory of inferior)
+ uint32_t load_stop_id; // The process stop ID that the sections for this
+ // image were loaded
+ llvm::Triple::OSType os_type; // LC_VERSION_MIN_... load command os type
+ std::string min_version_os_sdk; // LC_VERSION_MIN_... sdk value
+
+ ImageInfo()
+ : address(LLDB_INVALID_ADDRESS), slide(0), mod_date(0), file_spec(),
+ uuid(), header(), segments(), load_stop_id(0),
+ os_type(llvm::Triple::OSType::UnknownOS), min_version_os_sdk() {}
+
+ void Clear(bool load_cmd_data_only) {
+ if (!load_cmd_data_only) {
+ address = LLDB_INVALID_ADDRESS;
+ slide = 0;
+ mod_date = 0;
+ file_spec.Clear();
+ ::memset(&header, 0, sizeof(header));
+ }
+ uuid.Clear();
+ segments.clear();
+ load_stop_id = 0;
+ os_type = llvm::Triple::OSType::UnknownOS;
+ min_version_os_sdk.clear();
+ }
+
+ bool operator==(const ImageInfo &rhs) const {
+ return address == rhs.address && slide == rhs.slide &&
+ mod_date == rhs.mod_date && file_spec == rhs.file_spec &&
+ uuid == rhs.uuid &&
+ memcmp(&header, &rhs.header, sizeof(header)) == 0 &&
+ segments == rhs.segments && os_type == rhs.os_type;
}
- lldb::ModuleSP
- GetPThreadLibraryModule();
+ bool UUIDValid() const { return uuid.IsValid(); }
+
+ uint32_t GetAddressByteSize() {
+ if (header.cputype) {
+ if (header.cputype & llvm::MachO::CPU_ARCH_ABI64)
+ return 8;
+ else
+ return 4;
+ }
+ return 0;
+ }
+
+ lldb_private::ArchSpec GetArchitecture() const {
+ return lldb_private::ArchSpec(lldb_private::eArchTypeMachO,
+ header.cputype, header.cpusubtype);
+ }
+
+ const Segment *FindSegment(const lldb_private::ConstString &name) const;
+
+ void PutToLog(lldb_private::Log *log) const;
+
+ typedef std::vector<ImageInfo> collection;
+ typedef collection::iterator iterator;
+ typedef collection::const_iterator const_iterator;
+ };
+
+ bool UpdateImageLoadAddress(lldb_private::Module *module, ImageInfo &info);
+
+ bool UnloadModuleSections(lldb_private::Module *module, ImageInfo &info);
+
+ lldb::ModuleSP FindTargetModuleForImageInfo(ImageInfo &image_info,
+ bool can_create,
+ bool *did_create_ptr);
+
+ void UnloadImages(const std::vector<lldb::addr_t> &solib_addresses);
+
+ void UnloadAllImages();
+
+ virtual bool SetNotificationBreakpoint() = 0;
+
+ virtual void ClearNotificationBreakpoint() = 0;
+
+ virtual bool DidSetNotificationBreakpoint() = 0;
+
+ typedef std::map<uint64_t, lldb::addr_t> PthreadKeyToTLSMap;
+ typedef std::map<lldb::user_id_t, PthreadKeyToTLSMap> ThreadIDToTLSMap;
+
+ std::recursive_mutex &GetMutex() const { return m_mutex; }
+
+ lldb::ModuleSP GetPThreadLibraryModule();
+
+ lldb_private::Address GetPthreadSetSpecificAddress();
+
+ bool JSONImageInformationIntoImageInfo(
+ lldb_private::StructuredData::ObjectSP image_details,
+ ImageInfo::collection &image_infos);
+
+ // If image_infos contains / may contain dyld or executable image, call this
+ // method
+ // to keep our internal record keeping of the special binaries up-to-date.
+ void
+ UpdateSpecialBinariesFromNewImageInfos(ImageInfo::collection &image_infos);
+
+ // if image_info is a dyld binary, call this method
+ void UpdateDYLDImageInfoFromNewImageInfo(ImageInfo &image_info);
+
+ // If image_infos contains / may contain executable image, call this method
+ // to keep our internal record keeping of the special dyld binary up-to-date.
+ void AddExecutableModuleIfInImageInfos(ImageInfo::collection &image_infos);
- lldb_private::Address
- GetPthreadSetSpecificAddress();
+ bool AddModulesUsingImageInfos(ImageInfo::collection &image_infos);
- bool
- JSONImageInformationIntoImageInfo (lldb_private::StructuredData::ObjectSP image_details, ImageInfo::collection &image_infos);
+ // Whether we should use the new dyld SPI to get shared library information,
+ // or read
+ // it directly out of the dyld_all_image_infos. Whether we use the (newer)
+ // DynamicLoaderMacOS
+ // plugin or the (older) DynamicLoaderMacOSX plugin.
+ static bool UseDYLDSPI(lldb_private::Process *process);
- // If image_infos contains / may contain dyld or executable image, call this method
- // to keep our internal record keeping of the special binaries up-to-date.
- void
- UpdateSpecialBinariesFromNewImageInfos (ImageInfo::collection &image_infos);
-
- // if image_info is a dyld binary, call this method
- void
- UpdateDYLDImageInfoFromNewImageInfo (ImageInfo &image_info);
-
- // If image_infos contains / may contain executable image, call this method
- // to keep our internal record keeping of the special dyld binary up-to-date.
- void
- AddExecutableModuleIfInImageInfos (ImageInfo::collection &image_infos);
-
- bool
- AddModulesUsingImageInfos (ImageInfo::collection &image_infos);
-
- // Whether we should use the new dyld SPI to get shared library information, or read
- // it directly out of the dyld_all_image_infos. Whether we use the (newer) DynamicLoaderMacOS
- // plugin or the (older) DynamicLoaderMacOSX plugin.
- static bool
- UseDYLDSPI (lldb_private::Process *process);
-
- lldb::ModuleWP m_dyld_module_wp; // the dyld whose file type (mac, ios, etc) matches the process
- lldb::ModuleWP m_libpthread_module_wp;
- lldb_private::Address m_pthread_getspecific_addr;
- ThreadIDToTLSMap m_tid_to_tls_map;
- ImageInfo::collection m_dyld_image_infos; // Current shared libraries information
- uint32_t m_dyld_image_infos_stop_id; // The process stop ID that "m_dyld_image_infos" is valid for
- ImageInfo m_dyld;
- mutable std::recursive_mutex m_mutex;
+ lldb::ModuleWP m_dyld_module_wp; // the dyld whose file type (mac, ios, etc)
+ // matches the process
+ lldb::ModuleWP m_libpthread_module_wp;
+ lldb_private::Address m_pthread_getspecific_addr;
+ ThreadIDToTLSMap m_tid_to_tls_map;
+ ImageInfo::collection
+ m_dyld_image_infos; // Current shared libraries information
+ uint32_t m_dyld_image_infos_stop_id; // The process stop ID that
+ // "m_dyld_image_infos" is valid for
+ ImageInfo m_dyld;
+ mutable std::recursive_mutex m_mutex;
private:
- DISALLOW_COPY_AND_ASSIGN (DynamicLoaderDarwin);
+ DISALLOW_COPY_AND_ASSIGN(DynamicLoaderDarwin);
};
} // namespace lldb_private
Modified: lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp Tue Sep 6 15:57:50 2016
@@ -15,158 +15,131 @@
#include "lldb/Core/Section.h"
#include "lldb/Core/State.h"
#include "lldb/Symbol/ClangASTContext.h"
-#include "lldb/Symbol/SymbolVendor.h"
#include "lldb/Symbol/ObjectFile.h"
+#include "lldb/Symbol/SymbolVendor.h"
#include "lldb/Target/ABI.h"
+#include "lldb/Target/StackFrame.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/Thread.h"
-#include "lldb/Target/StackFrame.h"
-#include "DynamicLoaderMacOS.h"
#include "DynamicLoaderDarwin.h"
+#include "DynamicLoaderMacOS.h"
using namespace lldb;
using namespace lldb_private;
-
//----------------------------------------------------------------------
// Create an instance of this class. This function is filled into
// the plugin info class that gets handed out by the plugin factory and
// allows the lldb to instantiate an instance of this class.
//----------------------------------------------------------------------
-DynamicLoader *
-DynamicLoaderMacOS::CreateInstance (Process* process, bool force)
-{
- bool create = force;
- if (!create)
- {
- create = true;
- Module* exe_module = process->GetTarget().GetExecutableModulePointer();
- if (exe_module)
- {
- ObjectFile *object_file = exe_module->GetObjectFile();
- if (object_file)
- {
- create = (object_file->GetStrata() == ObjectFile::eStrataUser);
- }
- }
-
- if (create)
- {
- const llvm::Triple &triple_ref = process->GetTarget().GetArchitecture().GetTriple();
- switch (triple_ref.getOS())
- {
- case llvm::Triple::Darwin:
- case llvm::Triple::MacOSX:
- case llvm::Triple::IOS:
- case llvm::Triple::TvOS:
- case llvm::Triple::WatchOS:
- create = triple_ref.getVendor() == llvm::Triple::Apple;
- break;
- default:
- create = false;
- break;
- }
- }
- }
-
- if (UseDYLDSPI (process) == false)
- {
+DynamicLoader *DynamicLoaderMacOS::CreateInstance(Process *process,
+ bool force) {
+ bool create = force;
+ if (!create) {
+ create = true;
+ Module *exe_module = process->GetTarget().GetExecutableModulePointer();
+ if (exe_module) {
+ ObjectFile *object_file = exe_module->GetObjectFile();
+ if (object_file) {
+ create = (object_file->GetStrata() == ObjectFile::eStrataUser);
+ }
+ }
+
+ if (create) {
+ const llvm::Triple &triple_ref =
+ process->GetTarget().GetArchitecture().GetTriple();
+ switch (triple_ref.getOS()) {
+ case llvm::Triple::Darwin:
+ case llvm::Triple::MacOSX:
+ case llvm::Triple::IOS:
+ case llvm::Triple::TvOS:
+ case llvm::Triple::WatchOS:
+ create = triple_ref.getVendor() == llvm::Triple::Apple;
+ break;
+ default:
create = false;
+ break;
+ }
}
-
- if (create)
- return new DynamicLoaderMacOS (process);
- return NULL;
+ }
+
+ if (UseDYLDSPI(process) == false) {
+ create = false;
+ }
+
+ if (create)
+ return new DynamicLoaderMacOS(process);
+ return NULL;
}
//----------------------------------------------------------------------
// Constructor
//----------------------------------------------------------------------
-DynamicLoaderMacOS::DynamicLoaderMacOS (Process* process) :
- DynamicLoaderDarwin(process),
- m_image_infos_stop_id (UINT32_MAX),
- m_break_id(LLDB_INVALID_BREAK_ID),
- m_mutex()
-{
-}
+DynamicLoaderMacOS::DynamicLoaderMacOS(Process *process)
+ : DynamicLoaderDarwin(process), m_image_infos_stop_id(UINT32_MAX),
+ m_break_id(LLDB_INVALID_BREAK_ID), m_mutex() {}
//----------------------------------------------------------------------
// Destructor
//----------------------------------------------------------------------
-DynamicLoaderMacOS::~DynamicLoaderMacOS()
-{
- if (LLDB_BREAK_ID_IS_VALID(m_break_id))
- m_process->GetTarget().RemoveBreakpointByID (m_break_id);
-}
-
-bool
-DynamicLoaderMacOS::ProcessDidExec ()
-{
- std::lock_guard<std::recursive_mutex> baseclass_guard(GetMutex());
- bool did_exec = false;
- if (m_process)
- {
- // If we are stopped after an exec, we will have only one thread...
- if (m_process->GetThreadList().GetSize() == 1)
- {
- // See if we are stopped at '_dyld_start'
- ThreadSP thread_sp (m_process->GetThreadList().GetThreadAtIndex(0));
- if (thread_sp)
- {
- lldb::StackFrameSP frame_sp (thread_sp->GetStackFrameAtIndex(0));
- if (frame_sp)
- {
- const Symbol *symbol = frame_sp->GetSymbolContext(eSymbolContextSymbol).symbol;
- if (symbol)
- {
- if (symbol->GetName() == ConstString("_dyld_start"))
- did_exec = true;
- }
- }
- }
-
- }
- }
-
- if (did_exec)
- {
- m_libpthread_module_wp.reset();
- m_pthread_getspecific_addr.Clear();
- }
- return did_exec;
+DynamicLoaderMacOS::~DynamicLoaderMacOS() {
+ if (LLDB_BREAK_ID_IS_VALID(m_break_id))
+ m_process->GetTarget().RemoveBreakpointByID(m_break_id);
+}
+
+bool DynamicLoaderMacOS::ProcessDidExec() {
+ std::lock_guard<std::recursive_mutex> baseclass_guard(GetMutex());
+ bool did_exec = false;
+ if (m_process) {
+ // If we are stopped after an exec, we will have only one thread...
+ if (m_process->GetThreadList().GetSize() == 1) {
+ // See if we are stopped at '_dyld_start'
+ ThreadSP thread_sp(m_process->GetThreadList().GetThreadAtIndex(0));
+ if (thread_sp) {
+ lldb::StackFrameSP frame_sp(thread_sp->GetStackFrameAtIndex(0));
+ if (frame_sp) {
+ const Symbol *symbol =
+ frame_sp->GetSymbolContext(eSymbolContextSymbol).symbol;
+ if (symbol) {
+ if (symbol->GetName() == ConstString("_dyld_start"))
+ did_exec = true;
+ }
+ }
+ }
+ }
+ }
+
+ if (did_exec) {
+ m_libpthread_module_wp.reset();
+ m_pthread_getspecific_addr.Clear();
+ }
+ return did_exec;
}
//----------------------------------------------------------------------
// Clear out the state of this class.
//----------------------------------------------------------------------
-void
-DynamicLoaderMacOS::DoClear ()
-{
- std::lock_guard<std::recursive_mutex> guard(m_mutex);
+void DynamicLoaderMacOS::DoClear() {
+ std::lock_guard<std::recursive_mutex> guard(m_mutex);
- if (LLDB_BREAK_ID_IS_VALID(m_break_id))
- m_process->GetTarget().RemoveBreakpointByID (m_break_id);
+ if (LLDB_BREAK_ID_IS_VALID(m_break_id))
+ m_process->GetTarget().RemoveBreakpointByID(m_break_id);
- m_break_id = LLDB_INVALID_BREAK_ID;
+ m_break_id = LLDB_INVALID_BREAK_ID;
}
//----------------------------------------------------------------------
// Check if we have found DYLD yet
//----------------------------------------------------------------------
-bool
-DynamicLoaderMacOS::DidSetNotificationBreakpoint()
-{
- return LLDB_BREAK_ID_IS_VALID (m_break_id);
+bool DynamicLoaderMacOS::DidSetNotificationBreakpoint() {
+ return LLDB_BREAK_ID_IS_VALID(m_break_id);
}
-void
-DynamicLoaderMacOS::ClearNotificationBreakpoint ()
-{
- if (LLDB_BREAK_ID_IS_VALID (m_break_id))
- {
- m_process->GetTarget().RemoveBreakpointByID (m_break_id);
- }
+void DynamicLoaderMacOS::ClearNotificationBreakpoint() {
+ if (LLDB_BREAK_ID_IS_VALID(m_break_id)) {
+ m_process->GetTarget().RemoveBreakpointByID(m_break_id);
+ }
}
//----------------------------------------------------------------------
@@ -175,407 +148,376 @@ DynamicLoaderMacOS::ClearNotificationBre
// to get the DYLD info (available on SnowLeopard only). If that fails,
// then check in the default addresses.
//----------------------------------------------------------------------
-void
-DynamicLoaderMacOS::DoInitialImageFetch()
-{
- Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_DYNAMIC_LOADER));
-
- StructuredData::ObjectSP all_image_info_json_sp (m_process->GetLoadedDynamicLibrariesInfos ());
- ImageInfo::collection image_infos;
- if (all_image_info_json_sp.get()
- && all_image_info_json_sp->GetAsDictionary()
- && all_image_info_json_sp->GetAsDictionary()->HasKey("images")
- && all_image_info_json_sp->GetAsDictionary()->GetValueForKey("images")->GetAsArray())
- {
- if (JSONImageInformationIntoImageInfo (all_image_info_json_sp, image_infos))
- {
- if (log)
- log->Printf ("Initial module fetch: Adding %" PRId64 " modules.\n", (uint64_t) image_infos.size());
+void DynamicLoaderMacOS::DoInitialImageFetch() {
+ Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
- UpdateSpecialBinariesFromNewImageInfos (image_infos);
- AddModulesUsingImageInfos (image_infos);
- }
+ StructuredData::ObjectSP all_image_info_json_sp(
+ m_process->GetLoadedDynamicLibrariesInfos());
+ ImageInfo::collection image_infos;
+ if (all_image_info_json_sp.get() &&
+ all_image_info_json_sp->GetAsDictionary() &&
+ all_image_info_json_sp->GetAsDictionary()->HasKey("images") &&
+ all_image_info_json_sp->GetAsDictionary()
+ ->GetValueForKey("images")
+ ->GetAsArray()) {
+ if (JSONImageInformationIntoImageInfo(all_image_info_json_sp,
+ image_infos)) {
+ if (log)
+ log->Printf("Initial module fetch: Adding %" PRId64 " modules.\n",
+ (uint64_t)image_infos.size());
+
+ UpdateSpecialBinariesFromNewImageInfos(image_infos);
+ AddModulesUsingImageInfos(image_infos);
}
-
- m_dyld_image_infos_stop_id = m_process->GetStopID();
-}
+ }
-bool
-DynamicLoaderMacOS::NeedToDoInitialImageFetch ()
-{
- return true;
+ m_dyld_image_infos_stop_id = m_process->GetStopID();
}
+bool DynamicLoaderMacOS::NeedToDoInitialImageFetch() { return true; }
+
//----------------------------------------------------------------------
// Static callback function that gets called when our DYLD notification
// breakpoint gets hit. We update all of our image infos and then
// let our super class DynamicLoader class decide if we should stop
// or not (based on global preference).
//----------------------------------------------------------------------
-bool
-DynamicLoaderMacOS::NotifyBreakpointHit (void *baton,
- StoppointCallbackContext *context,
- lldb::user_id_t break_id,
- lldb::user_id_t break_loc_id)
-{
- // Let the event know that the images have changed
- // DYLD passes three arguments to the notification breakpoint.
- // Arg1: enum dyld_notify_mode mode - 0 = adding, 1 = removing, 2 = remove all
- // Arg2: unsigned long icount - Number of shared libraries added/removed
- // Arg3: uint64_t mach_headers[] - Array of load addresses of binaries added/removed
-
- DynamicLoaderMacOS* dyld_instance = (DynamicLoaderMacOS*) baton;
-
- ExecutionContext exe_ctx (context->exe_ctx_ref);
- Process *process = exe_ctx.GetProcessPtr();
-
- // This is a sanity check just in case this dyld_instance is an old dyld plugin's breakpoint still lying around.
- if (process != dyld_instance->m_process)
- return false;
-
- if (dyld_instance->m_image_infos_stop_id != UINT32_MAX
- && process->GetStopID() < dyld_instance->m_image_infos_stop_id)
- {
- return false;
- }
-
- const lldb::ABISP &abi = process->GetABI();
- if (abi)
- {
- // Build up the value array to store the three arguments given above, then get the values from the ABI:
-
- ClangASTContext *clang_ast_context = process->GetTarget().GetScratchClangASTContext();
- ValueList argument_values;
-
- Value mode_value; // enum dyld_notify_mode { dyld_notify_adding=0, dyld_notify_removing=1, dyld_notify_remove_all=2 };
- Value count_value; // unsigned long count
- Value headers_value; // uint64_t machHeaders[] (aka void*)
-
- CompilerType clang_void_ptr_type = clang_ast_context->GetBasicType(eBasicTypeVoid).GetPointerType();
- CompilerType clang_uint32_type = clang_ast_context->GetBuiltinTypeForEncodingAndBitSize(lldb::eEncodingUint, 32);
- CompilerType clang_uint64_type = clang_ast_context->GetBuiltinTypeForEncodingAndBitSize(lldb::eEncodingUint, 32);
-
- mode_value.SetValueType (Value::eValueTypeScalar);
- mode_value.SetCompilerType (clang_uint32_type);
-
- if (process->GetTarget().GetArchitecture().GetAddressByteSize() == 4)
- {
- count_value.SetValueType (Value::eValueTypeScalar);
- count_value.SetCompilerType (clang_uint32_type);
- }
- else
- {
- count_value.SetValueType (Value::eValueTypeScalar);
- count_value.SetCompilerType (clang_uint64_type);
- }
+bool DynamicLoaderMacOS::NotifyBreakpointHit(void *baton,
+ StoppointCallbackContext *context,
+ lldb::user_id_t break_id,
+ lldb::user_id_t break_loc_id) {
+ // Let the event know that the images have changed
+ // DYLD passes three arguments to the notification breakpoint.
+ // Arg1: enum dyld_notify_mode mode - 0 = adding, 1 = removing, 2 = remove all
+ // Arg2: unsigned long icount - Number of shared libraries
+ // added/removed
+ // Arg3: uint64_t mach_headers[] - Array of load addresses of binaries
+ // added/removed
+
+ DynamicLoaderMacOS *dyld_instance = (DynamicLoaderMacOS *)baton;
+
+ ExecutionContext exe_ctx(context->exe_ctx_ref);
+ Process *process = exe_ctx.GetProcessPtr();
+
+ // This is a sanity check just in case this dyld_instance is an old dyld
+ // plugin's breakpoint still lying around.
+ if (process != dyld_instance->m_process)
+ return false;
- headers_value.SetValueType (Value::eValueTypeScalar);
- headers_value.SetCompilerType (clang_void_ptr_type);
+ if (dyld_instance->m_image_infos_stop_id != UINT32_MAX &&
+ process->GetStopID() < dyld_instance->m_image_infos_stop_id) {
+ return false;
+ }
- argument_values.PushValue (mode_value);
- argument_values.PushValue (count_value);
- argument_values.PushValue (headers_value);
-
- if (abi->GetArgumentValues (exe_ctx.GetThreadRef(), argument_values))
- {
- uint32_t dyld_mode = argument_values.GetValueAtIndex(0)->GetScalar().UInt (-1);
- if (dyld_mode != static_cast<uint32_t>(-1))
- {
- // Okay the mode was right, now get the number of elements, and the array of new elements...
- uint32_t image_infos_count = argument_values.GetValueAtIndex(1)->GetScalar().UInt (-1);
- if (image_infos_count != static_cast<uint32_t>(-1))
- {
- addr_t header_array = argument_values.GetValueAtIndex(2)->GetScalar().ULongLong(-1);
- if (header_array != static_cast<uint64_t>(-1))
- {
- std::vector<addr_t> image_load_addresses;
- for (uint64_t i = 0; i < image_infos_count ; i++)
- {
- Error error;
- addr_t addr = process->ReadUnsignedIntegerFromMemory (header_array + (8 * i), 8, LLDB_INVALID_ADDRESS, error);
- if (addr != LLDB_INVALID_ADDRESS)
- {
- image_load_addresses.push_back (addr);
- }
- }
- if (dyld_mode == 0)
- {
- // dyld_notify_adding
- dyld_instance->AddBinaries (image_load_addresses);
- }
- else if (dyld_mode == 1)
- {
- // dyld_notify_removing
- dyld_instance->UnloadImages (image_load_addresses);
- }
- else if (dyld_mode == 2)
- {
- // dyld_notify_remove_all
- dyld_instance->UnloadAllImages ();
- }
- }
- }
+ const lldb::ABISP &abi = process->GetABI();
+ if (abi) {
+ // Build up the value array to store the three arguments given above, then
+ // get the values from the ABI:
+
+ ClangASTContext *clang_ast_context =
+ process->GetTarget().GetScratchClangASTContext();
+ ValueList argument_values;
+
+ Value mode_value; // enum dyld_notify_mode { dyld_notify_adding=0,
+ // dyld_notify_removing=1, dyld_notify_remove_all=2 };
+ Value count_value; // unsigned long count
+ Value headers_value; // uint64_t machHeaders[] (aka void*)
+
+ CompilerType clang_void_ptr_type =
+ clang_ast_context->GetBasicType(eBasicTypeVoid).GetPointerType();
+ CompilerType clang_uint32_type =
+ clang_ast_context->GetBuiltinTypeForEncodingAndBitSize(
+ lldb::eEncodingUint, 32);
+ CompilerType clang_uint64_type =
+ clang_ast_context->GetBuiltinTypeForEncodingAndBitSize(
+ lldb::eEncodingUint, 32);
+
+ mode_value.SetValueType(Value::eValueTypeScalar);
+ mode_value.SetCompilerType(clang_uint32_type);
+
+ if (process->GetTarget().GetArchitecture().GetAddressByteSize() == 4) {
+ count_value.SetValueType(Value::eValueTypeScalar);
+ count_value.SetCompilerType(clang_uint32_type);
+ } else {
+ count_value.SetValueType(Value::eValueTypeScalar);
+ count_value.SetCompilerType(clang_uint64_type);
+ }
+
+ headers_value.SetValueType(Value::eValueTypeScalar);
+ headers_value.SetCompilerType(clang_void_ptr_type);
+
+ argument_values.PushValue(mode_value);
+ argument_values.PushValue(count_value);
+ argument_values.PushValue(headers_value);
+
+ if (abi->GetArgumentValues(exe_ctx.GetThreadRef(), argument_values)) {
+ uint32_t dyld_mode =
+ argument_values.GetValueAtIndex(0)->GetScalar().UInt(-1);
+ if (dyld_mode != static_cast<uint32_t>(-1)) {
+ // Okay the mode was right, now get the number of elements, and the
+ // array of new elements...
+ uint32_t image_infos_count =
+ argument_values.GetValueAtIndex(1)->GetScalar().UInt(-1);
+ if (image_infos_count != static_cast<uint32_t>(-1)) {
+ addr_t header_array =
+ argument_values.GetValueAtIndex(2)->GetScalar().ULongLong(-1);
+ if (header_array != static_cast<uint64_t>(-1)) {
+ std::vector<addr_t> image_load_addresses;
+ for (uint64_t i = 0; i < image_infos_count; i++) {
+ Error error;
+ addr_t addr = process->ReadUnsignedIntegerFromMemory(
+ header_array + (8 * i), 8, LLDB_INVALID_ADDRESS, error);
+ if (addr != LLDB_INVALID_ADDRESS) {
+ image_load_addresses.push_back(addr);
+ }
}
+ if (dyld_mode == 0) {
+ // dyld_notify_adding
+ dyld_instance->AddBinaries(image_load_addresses);
+ } else if (dyld_mode == 1) {
+ // dyld_notify_removing
+ dyld_instance->UnloadImages(image_load_addresses);
+ } else if (dyld_mode == 2) {
+ // dyld_notify_remove_all
+ dyld_instance->UnloadAllImages();
+ }
+ }
}
+ }
}
- else
- {
- process->GetTarget().GetDebugger().GetAsyncErrorStream()->Printf("No ABI plugin located for triple %s -- shared libraries will not be registered!\n", process->GetTarget().GetArchitecture().GetTriple().getTriple().c_str());
- }
-
- // Return true to stop the target, false to just let the target run
- return dyld_instance->GetStopWhenImagesChange();
-}
-
-void
-DynamicLoaderMacOS::AddBinaries (const std::vector<lldb::addr_t> &load_addresses)
-{
- Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_DYNAMIC_LOADER));
- ImageInfo::collection image_infos;
-
- if (log)
- log->Printf ("Adding %" PRId64 " modules.", (uint64_t) load_addresses.size());
- StructuredData::ObjectSP binaries_info_sp = m_process->GetLoadedDynamicLibrariesInfos (load_addresses);
- if (binaries_info_sp.get()
- && binaries_info_sp->GetAsDictionary()
- && binaries_info_sp->GetAsDictionary()->HasKey("images")
- && binaries_info_sp->GetAsDictionary()->GetValueForKey("images")->GetAsArray()
- && binaries_info_sp->GetAsDictionary()->GetValueForKey("images")->GetAsArray()->GetSize() == load_addresses.size())
- {
- if (JSONImageInformationIntoImageInfo (binaries_info_sp, image_infos))
- {
- UpdateSpecialBinariesFromNewImageInfos (image_infos);
- AddModulesUsingImageInfos (image_infos);
- }
- m_dyld_image_infos_stop_id = m_process->GetStopID();
+ } else {
+ process->GetTarget().GetDebugger().GetAsyncErrorStream()->Printf(
+ "No ABI plugin located for triple %s -- shared libraries will not be "
+ "registered!\n",
+ process->GetTarget().GetArchitecture().GetTriple().getTriple().c_str());
+ }
+
+ // Return true to stop the target, false to just let the target run
+ return dyld_instance->GetStopWhenImagesChange();
+}
+
+void DynamicLoaderMacOS::AddBinaries(
+ const std::vector<lldb::addr_t> &load_addresses) {
+ Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
+ ImageInfo::collection image_infos;
+
+ if (log)
+ log->Printf("Adding %" PRId64 " modules.", (uint64_t)load_addresses.size());
+ StructuredData::ObjectSP binaries_info_sp =
+ m_process->GetLoadedDynamicLibrariesInfos(load_addresses);
+ if (binaries_info_sp.get() && binaries_info_sp->GetAsDictionary() &&
+ binaries_info_sp->GetAsDictionary()->HasKey("images") &&
+ binaries_info_sp->GetAsDictionary()
+ ->GetValueForKey("images")
+ ->GetAsArray() &&
+ binaries_info_sp->GetAsDictionary()
+ ->GetValueForKey("images")
+ ->GetAsArray()
+ ->GetSize() == load_addresses.size()) {
+ if (JSONImageInformationIntoImageInfo(binaries_info_sp, image_infos)) {
+ UpdateSpecialBinariesFromNewImageInfos(image_infos);
+ AddModulesUsingImageInfos(image_infos);
}
+ m_dyld_image_infos_stop_id = m_process->GetStopID();
+ }
}
-
// Dump the _dyld_all_image_infos members and all current image infos
// that we have parsed to the file handle provided.
//----------------------------------------------------------------------
-void
-DynamicLoaderMacOS::PutToLog(Log *log) const
-{
- if (log == NULL)
- return;
-}
-
-bool
-DynamicLoaderMacOS::SetNotificationBreakpoint ()
-{
- if (m_break_id == LLDB_INVALID_BREAK_ID)
- {
- ConstString g_symbol_name ("_dyld_debugger_notification");
- const Symbol *symbol = nullptr;
- ModuleSP dyld_sp (GetDYLDModule());
- if (dyld_sp)
- {
- symbol = dyld_sp->FindFirstSymbolWithNameAndType (g_symbol_name, eSymbolTypeCode);
- }
- if (symbol && (symbol->ValueIsAddress() || symbol->GetAddressRef().IsValid()))
- {
- addr_t symbol_address = symbol->GetAddressRef().GetOpcodeLoadAddress(&m_process->GetTarget());
- if (symbol_address != LLDB_INVALID_ADDRESS)
- {
- bool internal = true;
- bool hardware = false;
- Breakpoint *breakpoint = m_process->GetTarget().CreateBreakpoint(symbol_address, internal, hardware).get();
- breakpoint->SetCallback (DynamicLoaderMacOS::NotifyBreakpointHit, this, true);
- breakpoint->SetBreakpointKind ("shared-library-event");
- m_break_id = breakpoint->GetID();
- }
- }
+void DynamicLoaderMacOS::PutToLog(Log *log) const {
+ if (log == NULL)
+ return;
+}
+
+bool DynamicLoaderMacOS::SetNotificationBreakpoint() {
+ if (m_break_id == LLDB_INVALID_BREAK_ID) {
+ ConstString g_symbol_name("_dyld_debugger_notification");
+ const Symbol *symbol = nullptr;
+ ModuleSP dyld_sp(GetDYLDModule());
+ if (dyld_sp) {
+ symbol = dyld_sp->FindFirstSymbolWithNameAndType(g_symbol_name,
+ eSymbolTypeCode);
+ }
+ if (symbol &&
+ (symbol->ValueIsAddress() || symbol->GetAddressRef().IsValid())) {
+ addr_t symbol_address =
+ symbol->GetAddressRef().GetOpcodeLoadAddress(&m_process->GetTarget());
+ if (symbol_address != LLDB_INVALID_ADDRESS) {
+ bool internal = true;
+ bool hardware = false;
+ Breakpoint *breakpoint =
+ m_process->GetTarget()
+ .CreateBreakpoint(symbol_address, internal, hardware)
+ .get();
+ breakpoint->SetCallback(DynamicLoaderMacOS::NotifyBreakpointHit, this,
+ true);
+ breakpoint->SetBreakpointKind("shared-library-event");
+ m_break_id = breakpoint->GetID();
+ }
}
- return m_break_id != LLDB_INVALID_BREAK_ID;
+ }
+ return m_break_id != LLDB_INVALID_BREAK_ID;
}
-
addr_t
-DynamicLoaderMacOS::GetDyldLockVariableAddressFromModule (Module *module)
-{
- SymbolContext sc;
- SymbolVendor *sym_vendor = module->GetSymbolVendor ();
- Target &target = m_process->GetTarget ();
- if (sym_vendor)
- {
- Symtab *symtab = sym_vendor->GetSymtab();
- if (symtab)
- {
- std::vector<uint32_t> match_indexes;
- ConstString g_symbol_name ("_dyld_global_lock_held");
- uint32_t num_matches = 0;
- num_matches = symtab->AppendSymbolIndexesWithName (g_symbol_name, match_indexes);
- if (num_matches == 1)
- {
- Symbol *symbol = symtab->SymbolAtIndex (match_indexes[0]);
- if (symbol && (symbol->ValueIsAddress() || symbol->GetAddressRef().IsValid()))
- {
- return symbol->GetAddressRef().GetOpcodeLoadAddress(&target);
- }
- }
+DynamicLoaderMacOS::GetDyldLockVariableAddressFromModule(Module *module) {
+ SymbolContext sc;
+ SymbolVendor *sym_vendor = module->GetSymbolVendor();
+ Target &target = m_process->GetTarget();
+ if (sym_vendor) {
+ Symtab *symtab = sym_vendor->GetSymtab();
+ if (symtab) {
+ std::vector<uint32_t> match_indexes;
+ ConstString g_symbol_name("_dyld_global_lock_held");
+ uint32_t num_matches = 0;
+ num_matches =
+ symtab->AppendSymbolIndexesWithName(g_symbol_name, match_indexes);
+ if (num_matches == 1) {
+ Symbol *symbol = symtab->SymbolAtIndex(match_indexes[0]);
+ if (symbol &&
+ (symbol->ValueIsAddress() || symbol->GetAddressRef().IsValid())) {
+ return symbol->GetAddressRef().GetOpcodeLoadAddress(&target);
}
+ }
}
- return LLDB_INVALID_ADDRESS;
+ }
+ return LLDB_INVALID_ADDRESS;
}
// Look for this symbol:
//
-// int __attribute__((visibility("hidden"))) _dyld_global_lock_held = 0;
+// int __attribute__((visibility("hidden"))) _dyld_global_lock_held =
+// 0;
//
// in libdyld.dylib.
-Error
-DynamicLoaderMacOS::CanLoadImage ()
-{
- Error error;
- addr_t symbol_address = LLDB_INVALID_ADDRESS;
- Target &target = m_process->GetTarget ();
- const ModuleList &target_modules = target.GetImages();
- std::lock_guard<std::recursive_mutex> guard(target_modules.GetMutex());
- const size_t num_modules = target_modules.GetSize();
- ConstString g_libdyld_name ("libdyld.dylib");
-
- // Find any modules named "libdyld.dylib" and look for the symbol there first
- for (size_t i = 0; i < num_modules; i++)
- {
- Module *module_pointer = target_modules.GetModulePointerAtIndexUnlocked (i);
- if (module_pointer)
- {
- if (module_pointer->GetFileSpec().GetFilename() == g_libdyld_name)
- {
- symbol_address = GetDyldLockVariableAddressFromModule (module_pointer);
- if (symbol_address != LLDB_INVALID_ADDRESS)
- break;
- }
- }
- }
-
- // Search through all modules looking for the symbol in them
- if (symbol_address == LLDB_INVALID_ADDRESS)
- {
- for (size_t i = 0; i < num_modules; i++)
- {
- Module *module_pointer = target_modules.GetModulePointerAtIndexUnlocked (i);
- if (module_pointer)
- {
- addr_t symbol_address = GetDyldLockVariableAddressFromModule (module_pointer);
- if (symbol_address != LLDB_INVALID_ADDRESS)
- break;
- }
- }
- }
-
- // Default assumption is that it is OK to load images.
- // Only say that we cannot load images if we find the symbol in libdyld and it indicates that
- // we cannot.
-
- if (symbol_address != LLDB_INVALID_ADDRESS)
- {
- {
- int lock_held = m_process->ReadUnsignedIntegerFromMemory (symbol_address, 4, 0, error);
- if (lock_held != 0)
- {
- error.SetErrorToGenericError();
- }
- }
- }
- else
- {
- // If we were unable to find _dyld_global_lock_held in any modules, or it is not loaded into
- // memory yet, we may be at process startup (sitting at _dyld_start) - so we should not allow
- // dlopen calls.
+Error DynamicLoaderMacOS::CanLoadImage() {
+ Error error;
+ addr_t symbol_address = LLDB_INVALID_ADDRESS;
+ Target &target = m_process->GetTarget();
+ const ModuleList &target_modules = target.GetImages();
+ std::lock_guard<std::recursive_mutex> guard(target_modules.GetMutex());
+ const size_t num_modules = target_modules.GetSize();
+ ConstString g_libdyld_name("libdyld.dylib");
+
+ // Find any modules named "libdyld.dylib" and look for the symbol there first
+ for (size_t i = 0; i < num_modules; i++) {
+ Module *module_pointer = target_modules.GetModulePointerAtIndexUnlocked(i);
+ if (module_pointer) {
+ if (module_pointer->GetFileSpec().GetFilename() == g_libdyld_name) {
+ symbol_address = GetDyldLockVariableAddressFromModule(module_pointer);
+ if (symbol_address != LLDB_INVALID_ADDRESS)
+ break;
+ }
+ }
+ }
+
+ // Search through all modules looking for the symbol in them
+ if (symbol_address == LLDB_INVALID_ADDRESS) {
+ for (size_t i = 0; i < num_modules; i++) {
+ Module *module_pointer =
+ target_modules.GetModulePointerAtIndexUnlocked(i);
+ if (module_pointer) {
+ addr_t symbol_address =
+ GetDyldLockVariableAddressFromModule(module_pointer);
+ if (symbol_address != LLDB_INVALID_ADDRESS)
+ break;
+ }
+ }
+ }
+
+ // Default assumption is that it is OK to load images.
+ // Only say that we cannot load images if we find the symbol in libdyld and it
+ // indicates that
+ // we cannot.
+
+ if (symbol_address != LLDB_INVALID_ADDRESS) {
+ {
+ int lock_held =
+ m_process->ReadUnsignedIntegerFromMemory(symbol_address, 4, 0, error);
+ if (lock_held != 0) {
error.SetErrorToGenericError();
+ }
}
- return error;
-}
-
-bool
-DynamicLoaderMacOS::GetSharedCacheInformation (lldb::addr_t &base_address,
- UUID &uuid,
- LazyBool &using_shared_cache,
- LazyBool &private_shared_cache)
-{
- base_address = LLDB_INVALID_ADDRESS;
- uuid.Clear();
- using_shared_cache = eLazyBoolCalculate;
- private_shared_cache = eLazyBoolCalculate;
-
- if (m_process)
- {
- StructuredData::ObjectSP info = m_process->GetSharedCacheInfo();
- StructuredData::Dictionary *info_dict = nullptr;
- if (info.get() && info->GetAsDictionary())
- {
- info_dict = info->GetAsDictionary();
- }
-
- // {"shared_cache_base_address":140735683125248,"shared_cache_uuid":"DDB8D70C-C9A2-3561-B2C8-BE48A4F33F96","no_shared_cache":false,"shared_cache_private_cache":false}
-
- if (info_dict
- && info_dict->HasKey("shared_cache_uuid")
- && info_dict->HasKey("no_shared_cache")
- && info_dict->HasKey("shared_cache_base_address"))
- {
- base_address = info_dict->GetValueForKey("shared_cache_base_address")->GetIntegerValue(LLDB_INVALID_ADDRESS);
- std::string uuid_str = info_dict->GetValueForKey("shared_cache_uuid")->GetStringValue().c_str();
- if (!uuid_str.empty())
- uuid.SetFromCString (uuid_str.c_str());
- if (info_dict->GetValueForKey("no_shared_cache")->GetBooleanValue() == false)
- using_shared_cache = eLazyBoolYes;
- else
- using_shared_cache = eLazyBoolNo;
- if (info_dict->GetValueForKey("shared_cache_private_cache")->GetBooleanValue())
- private_shared_cache = eLazyBoolYes;
- else
- private_shared_cache = eLazyBoolNo;
-
- return true;
- }
- }
- return false;
-}
-
-void
-DynamicLoaderMacOS::Initialize()
-{
- PluginManager::RegisterPlugin (GetPluginNameStatic(),
- GetPluginDescriptionStatic(),
- CreateInstance);
-}
-
-void
-DynamicLoaderMacOS::Terminate()
-{
- PluginManager::UnregisterPlugin (CreateInstance);
-}
-
-
-lldb_private::ConstString
-DynamicLoaderMacOS::GetPluginNameStatic()
-{
- static ConstString g_name("macos-dyld");
- return g_name;
-}
-
-const char *
-DynamicLoaderMacOS::GetPluginDescriptionStatic()
-{
- return "Dynamic loader plug-in that watches for shared library loads/unloads in MacOSX user processes.";
+ } else {
+ // If we were unable to find _dyld_global_lock_held in any modules, or it is
+ // not loaded into
+ // memory yet, we may be at process startup (sitting at _dyld_start) - so we
+ // should not allow
+ // dlopen calls.
+ error.SetErrorToGenericError();
+ }
+ return error;
+}
+
+bool DynamicLoaderMacOS::GetSharedCacheInformation(
+ lldb::addr_t &base_address, UUID &uuid, LazyBool &using_shared_cache,
+ LazyBool &private_shared_cache) {
+ base_address = LLDB_INVALID_ADDRESS;
+ uuid.Clear();
+ using_shared_cache = eLazyBoolCalculate;
+ private_shared_cache = eLazyBoolCalculate;
+
+ if (m_process) {
+ StructuredData::ObjectSP info = m_process->GetSharedCacheInfo();
+ StructuredData::Dictionary *info_dict = nullptr;
+ if (info.get() && info->GetAsDictionary()) {
+ info_dict = info->GetAsDictionary();
+ }
+
+ // {"shared_cache_base_address":140735683125248,"shared_cache_uuid":"DDB8D70C-C9A2-3561-B2C8-BE48A4F33F96","no_shared_cache":false,"shared_cache_private_cache":false}
+
+ if (info_dict && info_dict->HasKey("shared_cache_uuid") &&
+ info_dict->HasKey("no_shared_cache") &&
+ info_dict->HasKey("shared_cache_base_address")) {
+ base_address = info_dict->GetValueForKey("shared_cache_base_address")
+ ->GetIntegerValue(LLDB_INVALID_ADDRESS);
+ std::string uuid_str = info_dict->GetValueForKey("shared_cache_uuid")
+ ->GetStringValue()
+ .c_str();
+ if (!uuid_str.empty())
+ uuid.SetFromCString(uuid_str.c_str());
+ if (info_dict->GetValueForKey("no_shared_cache")->GetBooleanValue() ==
+ false)
+ using_shared_cache = eLazyBoolYes;
+ else
+ using_shared_cache = eLazyBoolNo;
+ if (info_dict->GetValueForKey("shared_cache_private_cache")
+ ->GetBooleanValue())
+ private_shared_cache = eLazyBoolYes;
+ else
+ private_shared_cache = eLazyBoolNo;
+
+ return true;
+ }
+ }
+ return false;
+}
+
+void DynamicLoaderMacOS::Initialize() {
+ PluginManager::RegisterPlugin(GetPluginNameStatic(),
+ GetPluginDescriptionStatic(), CreateInstance);
+}
+
+void DynamicLoaderMacOS::Terminate() {
+ PluginManager::UnregisterPlugin(CreateInstance);
+}
+
+lldb_private::ConstString DynamicLoaderMacOS::GetPluginNameStatic() {
+ static ConstString g_name("macos-dyld");
+ return g_name;
+}
+
+const char *DynamicLoaderMacOS::GetPluginDescriptionStatic() {
+ return "Dynamic loader plug-in that watches for shared library loads/unloads "
+ "in MacOSX user processes.";
}
-
//------------------------------------------------------------------
// PluginInterface protocol
//------------------------------------------------------------------
-lldb_private::ConstString
-DynamicLoaderMacOS::GetPluginName()
-{
- return GetPluginNameStatic();
+lldb_private::ConstString DynamicLoaderMacOS::GetPluginName() {
+ return GetPluginNameStatic();
}
-uint32_t
-DynamicLoaderMacOS::GetPluginVersion()
-{
- return 1;
-}
+uint32_t DynamicLoaderMacOS::GetPluginVersion() { return 1; }
Modified: lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.h (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.h Tue Sep 6 15:57:50 2016
@@ -7,7 +7,8 @@
//
//===----------------------------------------------------------------------===//
-// This is the DynamicLoader plugin for Darwin (macOS / iPhoneOS / tvOS / watchOS)
+// This is the DynamicLoader plugin for Darwin (macOS / iPhoneOS / tvOS /
+// watchOS)
// platforms late 2016 and newer, where lldb will call dyld SPI functions to get
// information about shared libraries, information about the shared cache, and
// the _dyld_debugger_notification function we put a breakpoint on give us an
@@ -19,117 +20,98 @@
// C Includes
// C++ Includes
-#include <vector>
#include <mutex>
+#include <vector>
// Other libraries and framework includes
// Project includes
-#include "lldb/Target/DynamicLoader.h"
-#include "lldb/Host/FileSpec.h"
#include "lldb/Core/StructuredData.h"
#include "lldb/Core/UUID.h"
+#include "lldb/Host/FileSpec.h"
+#include "lldb/Target/DynamicLoader.h"
#include "lldb/Target/Process.h"
#include "lldb/Utility/SafeMachO.h"
#include "DynamicLoaderDarwin.h"
-class DynamicLoaderMacOS : public lldb_private::DynamicLoaderDarwin
-{
+class DynamicLoaderMacOS : public lldb_private::DynamicLoaderDarwin {
public:
- DynamicLoaderMacOS(lldb_private::Process *process);
+ DynamicLoaderMacOS(lldb_private::Process *process);
+
+ virtual ~DynamicLoaderMacOS() override;
+
+ //------------------------------------------------------------------
+ // Static Functions
+ //------------------------------------------------------------------
+ static void Initialize();
+
+ static void Terminate();
+
+ static lldb_private::ConstString GetPluginNameStatic();
+
+ static const char *GetPluginDescriptionStatic();
+
+ static lldb_private::DynamicLoader *
+ CreateInstance(lldb_private::Process *process, bool force);
+
+ //------------------------------------------------------------------
+ /// Called after attaching a process.
+ ///
+ /// Allow DynamicLoader plug-ins to execute some code after
+ /// attaching to a process.
+ //------------------------------------------------------------------
+ bool ProcessDidExec() override;
+
+ lldb_private::Error CanLoadImage() override;
- virtual ~DynamicLoaderMacOS() override;
+ bool GetSharedCacheInformation(
+ lldb::addr_t &base_address, lldb_private::UUID &uuid,
+ lldb_private::LazyBool &using_shared_cache,
+ lldb_private::LazyBool &private_shared_cache) override;
- //------------------------------------------------------------------
- // Static Functions
- //------------------------------------------------------------------
- static void
- Initialize();
-
- static void
- Terminate();
-
- static lldb_private::ConstString
- GetPluginNameStatic();
-
- static const char *
- GetPluginDescriptionStatic();
-
- static lldb_private::DynamicLoader *
- CreateInstance (lldb_private::Process *process, bool force);
-
- //------------------------------------------------------------------
- /// Called after attaching a process.
- ///
- /// Allow DynamicLoader plug-ins to execute some code after
- /// attaching to a process.
- //------------------------------------------------------------------
- bool
- ProcessDidExec() override;
-
- lldb_private::Error
- CanLoadImage() override;
-
- bool
- GetSharedCacheInformation (lldb::addr_t &base_address,
- lldb_private::UUID &uuid,
- lldb_private::LazyBool &using_shared_cache,
- lldb_private::LazyBool &private_shared_cache) override;
-
- //------------------------------------------------------------------
- // PluginInterface protocol
- //------------------------------------------------------------------
- lldb_private::ConstString
- GetPluginName() override;
+ //------------------------------------------------------------------
+ // PluginInterface protocol
+ //------------------------------------------------------------------
+ lldb_private::ConstString GetPluginName() override;
- uint32_t
- GetPluginVersion() override;
+ uint32_t GetPluginVersion() override;
protected:
- void
- PutToLog(lldb_private::Log *log) const;
+ void PutToLog(lldb_private::Log *log) const;
- void
- DoInitialImageFetch () override;
+ void DoInitialImageFetch() override;
- bool
- NeedToDoInitialImageFetch () override;
+ bool NeedToDoInitialImageFetch() override;
- bool
- DidSetNotificationBreakpoint () override;
+ bool DidSetNotificationBreakpoint() override;
- void
- AddBinaries (const std::vector<lldb::addr_t> &load_addresses);
+ void AddBinaries(const std::vector<lldb::addr_t> &load_addresses);
- void
- DoClear () override;
+ void DoClear() override;
- static bool
- NotifyBreakpointHit (void *baton,
- lldb_private::StoppointCallbackContext *context,
- lldb::user_id_t break_id,
- lldb::user_id_t break_loc_id);
+ static bool
+ NotifyBreakpointHit(void *baton,
+ lldb_private::StoppointCallbackContext *context,
+ lldb::user_id_t break_id, lldb::user_id_t break_loc_id);
- bool
- SetNotificationBreakpoint () override;
+ bool SetNotificationBreakpoint() override;
- void
- ClearNotificationBreakpoint () override;
+ void ClearNotificationBreakpoint() override;
- void
- UpdateImageInfosHeaderAndLoadCommands(ImageInfo::collection &image_infos,
- uint32_t infos_count,
- bool update_executable);
+ void UpdateImageInfosHeaderAndLoadCommands(ImageInfo::collection &image_infos,
+ uint32_t infos_count,
+ bool update_executable);
- lldb::addr_t
- GetDyldLockVariableAddressFromModule (lldb_private::Module *module);
+ lldb::addr_t
+ GetDyldLockVariableAddressFromModule(lldb_private::Module *module);
- uint32_t m_image_infos_stop_id; // The Stop ID the last time we loaded/unloaded images
- lldb::user_id_t m_break_id;
- mutable std::recursive_mutex m_mutex;
+ uint32_t m_image_infos_stop_id; // The Stop ID the last time we
+ // loaded/unloaded images
+ lldb::user_id_t m_break_id;
+ mutable std::recursive_mutex m_mutex;
private:
- DISALLOW_COPY_AND_ASSIGN (DynamicLoaderMacOS);
+ DISALLOW_COPY_AND_ASSIGN(DynamicLoaderMacOS);
};
#endif // liblldb_DynamicLoaderMacOS_h_
More information about the lldb-commits
mailing list