diff options
author | Kate Stone <katherine.stone@apple.com> | 2016-09-06 20:57:50 +0000 |
---|---|---|
committer | Kate Stone <katherine.stone@apple.com> | 2016-09-06 20:57:50 +0000 |
commit | b9c1b51e45b845debb76d8658edabca70ca56079 (patch) | |
tree | dfcb5a13ef2b014202340f47036da383eaee74aa /lldb/source/Utility | |
parent | d5aa73376966339caad04013510626ec2e42c760 (diff) | |
download | llvm-b9c1b51e45b845debb76d8658edabca70ca56079.zip llvm-b9c1b51e45b845debb76d8658edabca70ca56079.tar.gz llvm-b9c1b51e45b845debb76d8658edabca70ca56079.tar.bz2 |
*** This commit represents a complete reformatting of the LLDB source code
*** to conform to clang-format’s LLVM style. This kind of mass change has
*** two obvious implications:
Firstly, merging this particular commit into a downstream fork may be a huge
effort. Alternatively, it may be worth merging all changes up to this commit,
performing the same reformatting operation locally, and then discarding the
merge for this particular commit. The commands used to accomplish this
reformatting were as follows (with current working directory as the root of
the repository):
find . \( -iname "*.c" -or -iname "*.cpp" -or -iname "*.h" -or -iname "*.mm" \) -exec clang-format -i {} +
find . -iname "*.py" -exec autopep8 --in-place --aggressive --aggressive {} + ;
The version of clang-format used was 3.9.0, and autopep8 was 1.2.4.
Secondly, “blame” style tools will generally point to this commit instead of
a meaningful prior commit. There are alternatives available that will attempt
to look through this change and find the appropriate prior commit. YMMV.
llvm-svn: 280751
Diffstat (limited to 'lldb/source/Utility')
29 files changed, 4468 insertions, 4578 deletions
diff --git a/lldb/source/Utility/ARM64_DWARF_Registers.cpp b/lldb/source/Utility/ARM64_DWARF_Registers.cpp index d9b3863..bb63256 100644 --- a/lldb/source/Utility/ARM64_DWARF_Registers.cpp +++ b/lldb/source/Utility/ARM64_DWARF_Registers.cpp @@ -15,134 +15,198 @@ using namespace lldb; using namespace lldb_private; using namespace arm64_dwarf; -const char * -arm64_dwarf::GetRegisterName (unsigned reg_num, bool altnernate_name) -{ - if (altnernate_name) - { - switch (reg_num) - { - case fp: return "x29"; - case lr: return "x30"; - case sp: return "x31"; - default: - break; - } - return nullptr; - } - - switch (reg_num) - { - case x0: return "x0"; - case x1: return "x1"; - case x2: return "x2"; - case x3: return "x3"; - case x4: return "x4"; - case x5: return "x5"; - case x6: return "x6"; - case x7: return "x7"; - case x8: return "x8"; - case x9: return "x9"; - case x10: return "x10"; - case x11: return "x11"; - case x12: return "x12"; - case x13: return "x13"; - case x14: return "x14"; - case x15: return "x15"; - case x16: return "x16"; - case x17: return "x17"; - case x18: return "x18"; - case x19: return "x19"; - case x20: return "x20"; - case x21: return "x21"; - case x22: return "x22"; - case x23: return "x23"; - case x24: return "x24"; - case x25: return "x25"; - case x26: return "x26"; - case x27: return "x27"; - case x28: return "x28"; - case fp: return "fp"; - case lr: return "lr"; - case sp: return "sp"; - case pc: return "pc"; - case cpsr: return "cpsr"; - case v0: return "v0"; - case v1: return "v1"; - case v2: return "v2"; - case v3: return "v3"; - case v4: return "v4"; - case v5: return "v5"; - case v6: return "v6"; - case v7: return "v7"; - case v8: return "v8"; - case v9: return "v9"; - case v10: return "v10"; - case v11: return "v11"; - case v12: return "v12"; - case v13: return "v13"; - case v14: return "v14"; - case v15: return "v15"; - case v16: return "v16"; - case v17: return "v17"; - case v18: return "v18"; - case v19: return "v19"; - case v20: return "v20"; - case v21: return "v21"; - case v22: return "v22"; - case v23: return "v23"; - case v24: return "v24"; - case v25: return "v25"; - case v26: return "v26"; - case v27: return "v27"; - case v28: return "v28"; - case v29: return "v29"; - case v30: return "v30"; - case v31: return "v31"; +const char *arm64_dwarf::GetRegisterName(unsigned reg_num, + bool altnernate_name) { + if (altnernate_name) { + switch (reg_num) { + case fp: + return "x29"; + case lr: + return "x30"; + case sp: + return "x31"; + default: + break; } return nullptr; + } + + switch (reg_num) { + case x0: + return "x0"; + case x1: + return "x1"; + case x2: + return "x2"; + case x3: + return "x3"; + case x4: + return "x4"; + case x5: + return "x5"; + case x6: + return "x6"; + case x7: + return "x7"; + case x8: + return "x8"; + case x9: + return "x9"; + case x10: + return "x10"; + case x11: + return "x11"; + case x12: + return "x12"; + case x13: + return "x13"; + case x14: + return "x14"; + case x15: + return "x15"; + case x16: + return "x16"; + case x17: + return "x17"; + case x18: + return "x18"; + case x19: + return "x19"; + case x20: + return "x20"; + case x21: + return "x21"; + case x22: + return "x22"; + case x23: + return "x23"; + case x24: + return "x24"; + case x25: + return "x25"; + case x26: + return "x26"; + case x27: + return "x27"; + case x28: + return "x28"; + case fp: + return "fp"; + case lr: + return "lr"; + case sp: + return "sp"; + case pc: + return "pc"; + case cpsr: + return "cpsr"; + case v0: + return "v0"; + case v1: + return "v1"; + case v2: + return "v2"; + case v3: + return "v3"; + case v4: + return "v4"; + case v5: + return "v5"; + case v6: + return "v6"; + case v7: + return "v7"; + case v8: + return "v8"; + case v9: + return "v9"; + case v10: + return "v10"; + case v11: + return "v11"; + case v12: + return "v12"; + case v13: + return "v13"; + case v14: + return "v14"; + case v15: + return "v15"; + case v16: + return "v16"; + case v17: + return "v17"; + case v18: + return "v18"; + case v19: + return "v19"; + case v20: + return "v20"; + case v21: + return "v21"; + case v22: + return "v22"; + case v23: + return "v23"; + case v24: + return "v24"; + case v25: + return "v25"; + case v26: + return "v26"; + case v27: + return "v27"; + case v28: + return "v28"; + case v29: + return "v29"; + case v30: + return "v30"; + case v31: + return "v31"; + } + return nullptr; } -bool -arm64_dwarf::GetRegisterInfo (unsigned reg_num, RegisterInfo ®_info) -{ - ::memset (®_info, 0, sizeof(RegisterInfo)); - ::memset (reg_info.kinds, LLDB_INVALID_REGNUM, sizeof(reg_info.kinds)); - - if (reg_num >= x0 && reg_num <= pc) - { - reg_info.byte_size = 8; - reg_info.format = eFormatHex; - reg_info.encoding = eEncodingUint; - } - else if (reg_num >= v0 && reg_num <= v31) - { - reg_info.byte_size = 16; - reg_info.format = eFormatVectorOfFloat32; - reg_info.encoding = eEncodingVector; - } - else if (reg_num == cpsr) - { - reg_info.byte_size = 4; - reg_info.format = eFormatHex; - reg_info.encoding = eEncodingUint; - } - else - { - return false; - } - - reg_info.name = arm64_dwarf::GetRegisterName (reg_num, false); - reg_info.alt_name = arm64_dwarf::GetRegisterName (reg_num, true); - reg_info.kinds[eRegisterKindDWARF] = reg_num; +bool arm64_dwarf::GetRegisterInfo(unsigned reg_num, RegisterInfo ®_info) { + ::memset(®_info, 0, sizeof(RegisterInfo)); + ::memset(reg_info.kinds, LLDB_INVALID_REGNUM, sizeof(reg_info.kinds)); - switch (reg_num) - { - case fp: reg_info.kinds[eRegisterKindGeneric] = LLDB_REGNUM_GENERIC_FP; break; - case lr: reg_info.kinds[eRegisterKindGeneric] = LLDB_REGNUM_GENERIC_RA; break; - case sp: reg_info.kinds[eRegisterKindGeneric] = LLDB_REGNUM_GENERIC_SP; break; - case pc: reg_info.kinds[eRegisterKindGeneric] = LLDB_REGNUM_GENERIC_PC; break; - default: break; - } - return true; + if (reg_num >= x0 && reg_num <= pc) { + reg_info.byte_size = 8; + reg_info.format = eFormatHex; + reg_info.encoding = eEncodingUint; + } else if (reg_num >= v0 && reg_num <= v31) { + reg_info.byte_size = 16; + reg_info.format = eFormatVectorOfFloat32; + reg_info.encoding = eEncodingVector; + } else if (reg_num == cpsr) { + reg_info.byte_size = 4; + reg_info.format = eFormatHex; + reg_info.encoding = eEncodingUint; + } else { + return false; + } + + reg_info.name = arm64_dwarf::GetRegisterName(reg_num, false); + reg_info.alt_name = arm64_dwarf::GetRegisterName(reg_num, true); + reg_info.kinds[eRegisterKindDWARF] = reg_num; + + switch (reg_num) { + case fp: + reg_info.kinds[eRegisterKindGeneric] = LLDB_REGNUM_GENERIC_FP; + break; + case lr: + reg_info.kinds[eRegisterKindGeneric] = LLDB_REGNUM_GENERIC_RA; + break; + case sp: + reg_info.kinds[eRegisterKindGeneric] = LLDB_REGNUM_GENERIC_SP; + break; + case pc: + reg_info.kinds[eRegisterKindGeneric] = LLDB_REGNUM_GENERIC_PC; + break; + default: + break; + } + return true; } diff --git a/lldb/source/Utility/ARM64_DWARF_Registers.h b/lldb/source/Utility/ARM64_DWARF_Registers.h index 832f25d..be0ea2a 100644 --- a/lldb/source/Utility/ARM64_DWARF_Registers.h +++ b/lldb/source/Utility/ARM64_DWARF_Registers.h @@ -13,90 +13,88 @@ #include "lldb/lldb-private.h" namespace arm64_dwarf { - -enum -{ - x0 = 0, - x1, - x2, - x3, - x4, - x5, - x6, - x7, - x8, - x9, - x10, - x11, - x12, - x13, - x14, - x15, - x16, - x17, - x18, - x19, - x20, - x21, - x22, - x23, - x24, - x25, - x26, - x27, - x28, - x29 = 29, fp = x29, - x30 = 30, lr = x30, - x31 = 31, sp = x31, - pc = 32, - cpsr = 33, - // 34-63 reserved - // V0-V31 (128 bit vector registers) - v0 = 64, - v1, - v2, - v3, - v4, - v5, - v6, - v7, - v8, - v9, - v10, - v11, - v12, - v13, - v14, - v15, - v16, - v17, - v18, - v19, - v20, - v21, - v22, - v23, - v24, - v25, - v26, - v27, - v28, - v29, - v30, - v31 +enum { + x0 = 0, + x1, + x2, + x3, + x4, + x5, + x6, + x7, + x8, + x9, + x10, + x11, + x12, + x13, + x14, + x15, + x16, + x17, + x18, + x19, + x20, + x21, + x22, + x23, + x24, + x25, + x26, + x27, + x28, + x29 = 29, + fp = x29, + x30 = 30, + lr = x30, + x31 = 31, + sp = x31, + pc = 32, + cpsr = 33, + // 34-63 reserved - // 96-127 reserved + // V0-V31 (128 bit vector registers) + v0 = 64, + v1, + v2, + v3, + v4, + v5, + v6, + v7, + v8, + v9, + v10, + v11, + v12, + v13, + v14, + v15, + v16, + v17, + v18, + v19, + v20, + v21, + v22, + v23, + v24, + v25, + v26, + v27, + v28, + v29, + v30, + v31 + + // 96-127 reserved }; -const char * -GetRegisterName (unsigned reg_num, bool altnernate_name); - -bool -GetRegisterInfo (unsigned reg_num, - lldb_private::RegisterInfo ®_info); +const char *GetRegisterName(unsigned reg_num, bool altnernate_name); -} // namespace arm64_dwarf +bool GetRegisterInfo(unsigned reg_num, lldb_private::RegisterInfo ®_info); -#endif // utility_ARM64_DWARF_Registers_h_ +} // namespace arm64_dwarf +#endif // utility_ARM64_DWARF_Registers_h_ diff --git a/lldb/source/Utility/ARM64_ehframe_Registers.h b/lldb/source/Utility/ARM64_ehframe_Registers.h index 0a5c68c..7f49314 100644 --- a/lldb/source/Utility/ARM64_ehframe_Registers.h +++ b/lldb/source/Utility/ARM64_ehframe_Registers.h @@ -1,4 +1,5 @@ -//===-- ARM64_ehframe_Registers.h -------------------------------------*- C++ -*-===// +//===-- ARM64_ehframe_Registers.h -------------------------------------*- C++ +//-*-===// // // The LLVM Compiler Infrastructure // @@ -14,82 +15,78 @@ // Should be the same as DWARF register numbers. namespace arm64_ehframe { - -enum -{ - x0 = 0, - x1, - x2, - x3, - x4, - x5, - x6, - x7, - x8, - x9, - x10, - x11, - x12, - x13, - x14, - x15, - x16, - x17, - x18, - x19, - x20, - x21, - x22, - x23, - x24, - x25, - x26, - x27, - x28, - fp, // aka x29 - lr, // aka x30 - sp, // aka x31 aka wzr - pc, // value is 32 - cpsr -}; -enum -{ - v0 = 64, - v1, - v2, - v3, - v4, - v5, - v6, - v7, - v8, - v9, - v10, - v11, - v12, - v13, - v14, - v15, - v16, - v17, - v18, - v19, - v20, - v21, - v22, - v23, - v24, - v25, - v26, - v27, - v28, - v29, - v30, - v31 // 95 +enum { + x0 = 0, + x1, + x2, + x3, + x4, + x5, + x6, + x7, + x8, + x9, + x10, + x11, + x12, + x13, + x14, + x15, + x16, + x17, + x18, + x19, + x20, + x21, + x22, + x23, + x24, + x25, + x26, + x27, + x28, + fp, // aka x29 + lr, // aka x30 + sp, // aka x31 aka wzr + pc, // value is 32 + cpsr }; +enum { + v0 = 64, + v1, + v2, + v3, + v4, + v5, + v6, + v7, + v8, + v9, + v10, + v11, + v12, + v13, + v14, + v15, + v16, + v17, + v18, + v19, + v20, + v21, + v22, + v23, + v24, + v25, + v26, + v27, + v28, + v29, + v30, + v31 // 95 +}; } #endif // utility_ARM64_ehframe_Registers_h_ - diff --git a/lldb/source/Utility/ARM_DWARF_Registers.cpp b/lldb/source/Utility/ARM_DWARF_Registers.cpp index 64472ba..45d43a4 100644 --- a/lldb/source/Utility/ARM_DWARF_Registers.cpp +++ b/lldb/source/Utility/ARM_DWARF_Registers.cpp @@ -15,421 +15,911 @@ using namespace lldb; using namespace lldb_private; -const char * -GetARMDWARFRegisterName (unsigned reg_num) -{ - switch (reg_num) - { - case dwarf_r0: return "r0"; - case dwarf_r1: return "r1"; - case dwarf_r2: return "r2"; - case dwarf_r3: return "r3"; - case dwarf_r4: return "r4"; - case dwarf_r5: return "r5"; - case dwarf_r6: return "r6"; - case dwarf_r7: return "r7"; - case dwarf_r8: return "r8"; - case dwarf_r9: return "r9"; - case dwarf_r10: return "r10"; - case dwarf_r11: return "r11"; - case dwarf_r12: return "r12"; - case dwarf_sp: return "sp"; - case dwarf_lr: return "lr"; - case dwarf_pc: return "pc"; - case dwarf_cpsr:return "cpsr"; - - case dwarf_s0: return "s0"; - case dwarf_s1: return "s1"; - case dwarf_s2: return "s2"; - case dwarf_s3: return "s3"; - case dwarf_s4: return "s4"; - case dwarf_s5: return "s5"; - case dwarf_s6: return "s6"; - case dwarf_s7: return "s7"; - case dwarf_s8: return "s8"; - case dwarf_s9: return "s9"; - case dwarf_s10: return "s10"; - case dwarf_s11: return "s11"; - case dwarf_s12: return "s12"; - case dwarf_s13: return "s13"; - case dwarf_s14: return "s14"; - case dwarf_s15: return "s15"; - case dwarf_s16: return "s16"; - case dwarf_s17: return "s17"; - case dwarf_s18: return "s18"; - case dwarf_s19: return "s19"; - case dwarf_s20: return "s20"; - case dwarf_s21: return "s21"; - case dwarf_s22: return "s22"; - case dwarf_s23: return "s23"; - case dwarf_s24: return "s24"; - case dwarf_s25: return "s25"; - case dwarf_s26: return "s26"; - case dwarf_s27: return "s27"; - case dwarf_s28: return "s28"; - case dwarf_s29: return "s29"; - case dwarf_s30: return "s30"; - case dwarf_s31: return "s31"; - - // FPA Registers 0-7 - case dwarf_f0: return "f0"; - case dwarf_f1: return "f1"; - case dwarf_f2: return "f2"; - case dwarf_f3: return "f3"; - case dwarf_f4: return "f4"; - case dwarf_f5: return "f5"; - case dwarf_f6: return "f6"; - case dwarf_f7: return "f7"; - - // Intel wireless MMX general purpose registers 0 - 7 - // XScale accumulator register 0 - 7 (they do overlap with wCGR0 - wCGR7) - case dwarf_wCGR0: return "wCGR0/ACC0"; - case dwarf_wCGR1: return "wCGR1/ACC1"; - case dwarf_wCGR2: return "wCGR2/ACC2"; - case dwarf_wCGR3: return "wCGR3/ACC3"; - case dwarf_wCGR4: return "wCGR4/ACC4"; - case dwarf_wCGR5: return "wCGR5/ACC5"; - case dwarf_wCGR6: return "wCGR6/ACC6"; - case dwarf_wCGR7: return "wCGR7/ACC7"; - - // Intel wireless MMX data registers 0 - 15 - case dwarf_wR0: return "wR0"; - case dwarf_wR1: return "wR1"; - case dwarf_wR2: return "wR2"; - case dwarf_wR3: return "wR3"; - case dwarf_wR4: return "wR4"; - case dwarf_wR5: return "wR5"; - case dwarf_wR6: return "wR6"; - case dwarf_wR7: return "wR7"; - case dwarf_wR8: return "wR8"; - case dwarf_wR9: return "wR9"; - case dwarf_wR10: return "wR10"; - case dwarf_wR11: return "wR11"; - case dwarf_wR12: return "wR12"; - case dwarf_wR13: return "wR13"; - case dwarf_wR14: return "wR14"; - case dwarf_wR15: return "wR15"; - - case dwarf_spsr: return "spsr"; - case dwarf_spsr_fiq: return "spsr_fiq"; - case dwarf_spsr_irq: return "spsr_irq"; - case dwarf_spsr_abt: return "spsr_abt"; - case dwarf_spsr_und: return "spsr_und"; - case dwarf_spsr_svc: return "spsr_svc"; - - case dwarf_r8_usr: return "r8_usr"; - case dwarf_r9_usr: return "r9_usr"; - case dwarf_r10_usr: return "r10_usr"; - case dwarf_r11_usr: return "r11_usr"; - case dwarf_r12_usr: return "r12_usr"; - case dwarf_r13_usr: return "r13_usr"; - case dwarf_r14_usr: return "r14_usr"; - case dwarf_r8_fiq: return "r8_fiq"; - case dwarf_r9_fiq: return "r9_fiq"; - case dwarf_r10_fiq: return "r10_fiq"; - case dwarf_r11_fiq: return "r11_fiq"; - case dwarf_r12_fiq: return "r12_fiq"; - case dwarf_r13_fiq: return "r13_fiq"; - case dwarf_r14_fiq: return "r14_fiq"; - case dwarf_r13_irq: return "r13_irq"; - case dwarf_r14_irq: return "r14_irq"; - case dwarf_r13_abt: return "r13_abt"; - case dwarf_r14_abt: return "r14_abt"; - case dwarf_r13_und: return "r13_und"; - case dwarf_r14_und: return "r14_und"; - case dwarf_r13_svc: return "r13_svc"; - case dwarf_r14_svc: return "r14_svc"; - - // Intel wireless MMX control register in co-processor 0 - 7 - case dwarf_wC0: return "wC0"; - case dwarf_wC1: return "wC1"; - case dwarf_wC2: return "wC2"; - case dwarf_wC3: return "wC3"; - case dwarf_wC4: return "wC4"; - case dwarf_wC5: return "wC5"; - case dwarf_wC6: return "wC6"; - case dwarf_wC7: return "wC7"; - - // VFP-v3/Neon - case dwarf_d0: return "d0"; - case dwarf_d1: return "d1"; - case dwarf_d2: return "d2"; - case dwarf_d3: return "d3"; - case dwarf_d4: return "d4"; - case dwarf_d5: return "d5"; - case dwarf_d6: return "d6"; - case dwarf_d7: return "d7"; - case dwarf_d8: return "d8"; - case dwarf_d9: return "d9"; - case dwarf_d10: return "d10"; - case dwarf_d11: return "d11"; - case dwarf_d12: return "d12"; - case dwarf_d13: return "d13"; - case dwarf_d14: return "d14"; - case dwarf_d15: return "d15"; - case dwarf_d16: return "d16"; - case dwarf_d17: return "d17"; - case dwarf_d18: return "d18"; - case dwarf_d19: return "d19"; - case dwarf_d20: return "d20"; - case dwarf_d21: return "d21"; - case dwarf_d22: return "d22"; - case dwarf_d23: return "d23"; - case dwarf_d24: return "d24"; - case dwarf_d25: return "d25"; - case dwarf_d26: return "d26"; - case dwarf_d27: return "d27"; - case dwarf_d28: return "d28"; - case dwarf_d29: return "d29"; - case dwarf_d30: return "d30"; - case dwarf_d31: return "d31"; +const char *GetARMDWARFRegisterName(unsigned reg_num) { + switch (reg_num) { + case dwarf_r0: + return "r0"; + case dwarf_r1: + return "r1"; + case dwarf_r2: + return "r2"; + case dwarf_r3: + return "r3"; + case dwarf_r4: + return "r4"; + case dwarf_r5: + return "r5"; + case dwarf_r6: + return "r6"; + case dwarf_r7: + return "r7"; + case dwarf_r8: + return "r8"; + case dwarf_r9: + return "r9"; + case dwarf_r10: + return "r10"; + case dwarf_r11: + return "r11"; + case dwarf_r12: + return "r12"; + case dwarf_sp: + return "sp"; + case dwarf_lr: + return "lr"; + case dwarf_pc: + return "pc"; + case dwarf_cpsr: + return "cpsr"; - // NEON 128-bit vector registers (overlays the d registers) - case dwarf_q0: return "q0"; - case dwarf_q1: return "q1"; - case dwarf_q2: return "q2"; - case dwarf_q3: return "q3"; - case dwarf_q4: return "q4"; - case dwarf_q5: return "q5"; - case dwarf_q6: return "q6"; - case dwarf_q7: return "q7"; - case dwarf_q8: return "q8"; - case dwarf_q9: return "q9"; - case dwarf_q10: return "q10"; - case dwarf_q11: return "q11"; - case dwarf_q12: return "q12"; - case dwarf_q13: return "q13"; - case dwarf_q14: return "q14"; - case dwarf_q15: return "q15"; - } - return nullptr; + case dwarf_s0: + return "s0"; + case dwarf_s1: + return "s1"; + case dwarf_s2: + return "s2"; + case dwarf_s3: + return "s3"; + case dwarf_s4: + return "s4"; + case dwarf_s5: + return "s5"; + case dwarf_s6: + return "s6"; + case dwarf_s7: + return "s7"; + case dwarf_s8: + return "s8"; + case dwarf_s9: + return "s9"; + case dwarf_s10: + return "s10"; + case dwarf_s11: + return "s11"; + case dwarf_s12: + return "s12"; + case dwarf_s13: + return "s13"; + case dwarf_s14: + return "s14"; + case dwarf_s15: + return "s15"; + case dwarf_s16: + return "s16"; + case dwarf_s17: + return "s17"; + case dwarf_s18: + return "s18"; + case dwarf_s19: + return "s19"; + case dwarf_s20: + return "s20"; + case dwarf_s21: + return "s21"; + case dwarf_s22: + return "s22"; + case dwarf_s23: + return "s23"; + case dwarf_s24: + return "s24"; + case dwarf_s25: + return "s25"; + case dwarf_s26: + return "s26"; + case dwarf_s27: + return "s27"; + case dwarf_s28: + return "s28"; + case dwarf_s29: + return "s29"; + case dwarf_s30: + return "s30"; + case dwarf_s31: + return "s31"; + + // FPA Registers 0-7 + case dwarf_f0: + return "f0"; + case dwarf_f1: + return "f1"; + case dwarf_f2: + return "f2"; + case dwarf_f3: + return "f3"; + case dwarf_f4: + return "f4"; + case dwarf_f5: + return "f5"; + case dwarf_f6: + return "f6"; + case dwarf_f7: + return "f7"; + + // Intel wireless MMX general purpose registers 0 - 7 + // XScale accumulator register 0 - 7 (they do overlap with wCGR0 - wCGR7) + case dwarf_wCGR0: + return "wCGR0/ACC0"; + case dwarf_wCGR1: + return "wCGR1/ACC1"; + case dwarf_wCGR2: + return "wCGR2/ACC2"; + case dwarf_wCGR3: + return "wCGR3/ACC3"; + case dwarf_wCGR4: + return "wCGR4/ACC4"; + case dwarf_wCGR5: + return "wCGR5/ACC5"; + case dwarf_wCGR6: + return "wCGR6/ACC6"; + case dwarf_wCGR7: + return "wCGR7/ACC7"; + + // Intel wireless MMX data registers 0 - 15 + case dwarf_wR0: + return "wR0"; + case dwarf_wR1: + return "wR1"; + case dwarf_wR2: + return "wR2"; + case dwarf_wR3: + return "wR3"; + case dwarf_wR4: + return "wR4"; + case dwarf_wR5: + return "wR5"; + case dwarf_wR6: + return "wR6"; + case dwarf_wR7: + return "wR7"; + case dwarf_wR8: + return "wR8"; + case dwarf_wR9: + return "wR9"; + case dwarf_wR10: + return "wR10"; + case dwarf_wR11: + return "wR11"; + case dwarf_wR12: + return "wR12"; + case dwarf_wR13: + return "wR13"; + case dwarf_wR14: + return "wR14"; + case dwarf_wR15: + return "wR15"; + + case dwarf_spsr: + return "spsr"; + case dwarf_spsr_fiq: + return "spsr_fiq"; + case dwarf_spsr_irq: + return "spsr_irq"; + case dwarf_spsr_abt: + return "spsr_abt"; + case dwarf_spsr_und: + return "spsr_und"; + case dwarf_spsr_svc: + return "spsr_svc"; + + case dwarf_r8_usr: + return "r8_usr"; + case dwarf_r9_usr: + return "r9_usr"; + case dwarf_r10_usr: + return "r10_usr"; + case dwarf_r11_usr: + return "r11_usr"; + case dwarf_r12_usr: + return "r12_usr"; + case dwarf_r13_usr: + return "r13_usr"; + case dwarf_r14_usr: + return "r14_usr"; + case dwarf_r8_fiq: + return "r8_fiq"; + case dwarf_r9_fiq: + return "r9_fiq"; + case dwarf_r10_fiq: + return "r10_fiq"; + case dwarf_r11_fiq: + return "r11_fiq"; + case dwarf_r12_fiq: + return "r12_fiq"; + case dwarf_r13_fiq: + return "r13_fiq"; + case dwarf_r14_fiq: + return "r14_fiq"; + case dwarf_r13_irq: + return "r13_irq"; + case dwarf_r14_irq: + return "r14_irq"; + case dwarf_r13_abt: + return "r13_abt"; + case dwarf_r14_abt: + return "r14_abt"; + case dwarf_r13_und: + return "r13_und"; + case dwarf_r14_und: + return "r14_und"; + case dwarf_r13_svc: + return "r13_svc"; + case dwarf_r14_svc: + return "r14_svc"; + + // Intel wireless MMX control register in co-processor 0 - 7 + case dwarf_wC0: + return "wC0"; + case dwarf_wC1: + return "wC1"; + case dwarf_wC2: + return "wC2"; + case dwarf_wC3: + return "wC3"; + case dwarf_wC4: + return "wC4"; + case dwarf_wC5: + return "wC5"; + case dwarf_wC6: + return "wC6"; + case dwarf_wC7: + return "wC7"; + + // VFP-v3/Neon + case dwarf_d0: + return "d0"; + case dwarf_d1: + return "d1"; + case dwarf_d2: + return "d2"; + case dwarf_d3: + return "d3"; + case dwarf_d4: + return "d4"; + case dwarf_d5: + return "d5"; + case dwarf_d6: + return "d6"; + case dwarf_d7: + return "d7"; + case dwarf_d8: + return "d8"; + case dwarf_d9: + return "d9"; + case dwarf_d10: + return "d10"; + case dwarf_d11: + return "d11"; + case dwarf_d12: + return "d12"; + case dwarf_d13: + return "d13"; + case dwarf_d14: + return "d14"; + case dwarf_d15: + return "d15"; + case dwarf_d16: + return "d16"; + case dwarf_d17: + return "d17"; + case dwarf_d18: + return "d18"; + case dwarf_d19: + return "d19"; + case dwarf_d20: + return "d20"; + case dwarf_d21: + return "d21"; + case dwarf_d22: + return "d22"; + case dwarf_d23: + return "d23"; + case dwarf_d24: + return "d24"; + case dwarf_d25: + return "d25"; + case dwarf_d26: + return "d26"; + case dwarf_d27: + return "d27"; + case dwarf_d28: + return "d28"; + case dwarf_d29: + return "d29"; + case dwarf_d30: + return "d30"; + case dwarf_d31: + return "d31"; + + // NEON 128-bit vector registers (overlays the d registers) + case dwarf_q0: + return "q0"; + case dwarf_q1: + return "q1"; + case dwarf_q2: + return "q2"; + case dwarf_q3: + return "q3"; + case dwarf_q4: + return "q4"; + case dwarf_q5: + return "q5"; + case dwarf_q6: + return "q6"; + case dwarf_q7: + return "q7"; + case dwarf_q8: + return "q8"; + case dwarf_q9: + return "q9"; + case dwarf_q10: + return "q10"; + case dwarf_q11: + return "q11"; + case dwarf_q12: + return "q12"; + case dwarf_q13: + return "q13"; + case dwarf_q14: + return "q14"; + case dwarf_q15: + return "q15"; + } + return nullptr; } -bool -GetARMDWARFRegisterInfo (unsigned reg_num, RegisterInfo ®_info) -{ - ::memset (®_info, 0, sizeof(RegisterInfo)); - ::memset (reg_info.kinds, LLDB_INVALID_REGNUM, sizeof(reg_info.kinds)); +bool GetARMDWARFRegisterInfo(unsigned reg_num, RegisterInfo ®_info) { + ::memset(®_info, 0, sizeof(RegisterInfo)); + ::memset(reg_info.kinds, LLDB_INVALID_REGNUM, sizeof(reg_info.kinds)); + + if (reg_num >= dwarf_q0 && reg_num <= dwarf_q15) { + reg_info.byte_size = 16; + reg_info.format = eFormatVectorOfUInt8; + reg_info.encoding = eEncodingVector; + } + + if (reg_num >= dwarf_d0 && reg_num <= dwarf_d31) { + reg_info.byte_size = 8; + reg_info.format = eFormatFloat; + reg_info.encoding = eEncodingIEEE754; + } else if (reg_num >= dwarf_s0 && reg_num <= dwarf_s31) { + reg_info.byte_size = 4; + reg_info.format = eFormatFloat; + reg_info.encoding = eEncodingIEEE754; + } else if (reg_num >= dwarf_f0 && reg_num <= dwarf_f7) { + reg_info.byte_size = 12; + reg_info.format = eFormatFloat; + reg_info.encoding = eEncodingIEEE754; + } else { + reg_info.byte_size = 4; + reg_info.format = eFormatHex; + reg_info.encoding = eEncodingUint; + } + + reg_info.kinds[eRegisterKindDWARF] = reg_num; + + switch (reg_num) { + case dwarf_r0: + reg_info.name = "r0"; + break; + case dwarf_r1: + reg_info.name = "r1"; + break; + case dwarf_r2: + reg_info.name = "r2"; + break; + case dwarf_r3: + reg_info.name = "r3"; + break; + case dwarf_r4: + reg_info.name = "r4"; + break; + case dwarf_r5: + reg_info.name = "r5"; + break; + case dwarf_r6: + reg_info.name = "r6"; + break; + case dwarf_r7: + reg_info.name = "r7"; + reg_info.kinds[eRegisterKindGeneric] = LLDB_REGNUM_GENERIC_FP; + break; + case dwarf_r8: + reg_info.name = "r8"; + break; + case dwarf_r9: + reg_info.name = "r9"; + break; + case dwarf_r10: + reg_info.name = "r10"; + break; + case dwarf_r11: + reg_info.name = "r11"; + break; + case dwarf_r12: + reg_info.name = "r12"; + break; + case dwarf_sp: + reg_info.name = "sp"; + reg_info.alt_name = "r13"; + reg_info.kinds[eRegisterKindGeneric] = LLDB_REGNUM_GENERIC_SP; + break; + case dwarf_lr: + reg_info.name = "lr"; + reg_info.alt_name = "r14"; + reg_info.kinds[eRegisterKindGeneric] = LLDB_REGNUM_GENERIC_RA; + break; + case dwarf_pc: + reg_info.name = "pc"; + reg_info.alt_name = "r15"; + reg_info.kinds[eRegisterKindGeneric] = LLDB_REGNUM_GENERIC_PC; + break; + case dwarf_cpsr: + reg_info.name = "cpsr"; + reg_info.kinds[eRegisterKindGeneric] = LLDB_REGNUM_GENERIC_FLAGS; + break; + + case dwarf_s0: + reg_info.name = "s0"; + break; + case dwarf_s1: + reg_info.name = "s1"; + break; + case dwarf_s2: + reg_info.name = "s2"; + break; + case dwarf_s3: + reg_info.name = "s3"; + break; + case dwarf_s4: + reg_info.name = "s4"; + break; + case dwarf_s5: + reg_info.name = "s5"; + break; + case dwarf_s6: + reg_info.name = "s6"; + break; + case dwarf_s7: + reg_info.name = "s7"; + break; + case dwarf_s8: + reg_info.name = "s8"; + break; + case dwarf_s9: + reg_info.name = "s9"; + break; + case dwarf_s10: + reg_info.name = "s10"; + break; + case dwarf_s11: + reg_info.name = "s11"; + break; + case dwarf_s12: + reg_info.name = "s12"; + break; + case dwarf_s13: + reg_info.name = "s13"; + break; + case dwarf_s14: + reg_info.name = "s14"; + break; + case dwarf_s15: + reg_info.name = "s15"; + break; + case dwarf_s16: + reg_info.name = "s16"; + break; + case dwarf_s17: + reg_info.name = "s17"; + break; + case dwarf_s18: + reg_info.name = "s18"; + break; + case dwarf_s19: + reg_info.name = "s19"; + break; + case dwarf_s20: + reg_info.name = "s20"; + break; + case dwarf_s21: + reg_info.name = "s21"; + break; + case dwarf_s22: + reg_info.name = "s22"; + break; + case dwarf_s23: + reg_info.name = "s23"; + break; + case dwarf_s24: + reg_info.name = "s24"; + break; + case dwarf_s25: + reg_info.name = "s25"; + break; + case dwarf_s26: + reg_info.name = "s26"; + break; + case dwarf_s27: + reg_info.name = "s27"; + break; + case dwarf_s28: + reg_info.name = "s28"; + break; + case dwarf_s29: + reg_info.name = "s29"; + break; + case dwarf_s30: + reg_info.name = "s30"; + break; + case dwarf_s31: + reg_info.name = "s31"; + break; + + // FPA Registers 0-7 + case dwarf_f0: + reg_info.name = "f0"; + break; + case dwarf_f1: + reg_info.name = "f1"; + break; + case dwarf_f2: + reg_info.name = "f2"; + break; + case dwarf_f3: + reg_info.name = "f3"; + break; + case dwarf_f4: + reg_info.name = "f4"; + break; + case dwarf_f5: + reg_info.name = "f5"; + break; + case dwarf_f6: + reg_info.name = "f6"; + break; + case dwarf_f7: + reg_info.name = "f7"; + break; + + // Intel wireless MMX general purpose registers 0 - 7 + // XScale accumulator register 0 - 7 (they do overlap with wCGR0 - wCGR7) + case dwarf_wCGR0: + reg_info.name = "wCGR0/ACC0"; + break; + case dwarf_wCGR1: + reg_info.name = "wCGR1/ACC1"; + break; + case dwarf_wCGR2: + reg_info.name = "wCGR2/ACC2"; + break; + case dwarf_wCGR3: + reg_info.name = "wCGR3/ACC3"; + break; + case dwarf_wCGR4: + reg_info.name = "wCGR4/ACC4"; + break; + case dwarf_wCGR5: + reg_info.name = "wCGR5/ACC5"; + break; + case dwarf_wCGR6: + reg_info.name = "wCGR6/ACC6"; + break; + case dwarf_wCGR7: + reg_info.name = "wCGR7/ACC7"; + break; + + // Intel wireless MMX data registers 0 - 15 + case dwarf_wR0: + reg_info.name = "wR0"; + break; + case dwarf_wR1: + reg_info.name = "wR1"; + break; + case dwarf_wR2: + reg_info.name = "wR2"; + break; + case dwarf_wR3: + reg_info.name = "wR3"; + break; + case dwarf_wR4: + reg_info.name = "wR4"; + break; + case dwarf_wR5: + reg_info.name = "wR5"; + break; + case dwarf_wR6: + reg_info.name = "wR6"; + break; + case dwarf_wR7: + reg_info.name = "wR7"; + break; + case dwarf_wR8: + reg_info.name = "wR8"; + break; + case dwarf_wR9: + reg_info.name = "wR9"; + break; + case dwarf_wR10: + reg_info.name = "wR10"; + break; + case dwarf_wR11: + reg_info.name = "wR11"; + break; + case dwarf_wR12: + reg_info.name = "wR12"; + break; + case dwarf_wR13: + reg_info.name = "wR13"; + break; + case dwarf_wR14: + reg_info.name = "wR14"; + break; + case dwarf_wR15: + reg_info.name = "wR15"; + break; + + case dwarf_spsr: + reg_info.name = "spsr"; + break; + case dwarf_spsr_fiq: + reg_info.name = "spsr_fiq"; + break; + case dwarf_spsr_irq: + reg_info.name = "spsr_irq"; + break; + case dwarf_spsr_abt: + reg_info.name = "spsr_abt"; + break; + case dwarf_spsr_und: + reg_info.name = "spsr_und"; + break; + case dwarf_spsr_svc: + reg_info.name = "spsr_svc"; + break; + + case dwarf_r8_usr: + reg_info.name = "r8_usr"; + break; + case dwarf_r9_usr: + reg_info.name = "r9_usr"; + break; + case dwarf_r10_usr: + reg_info.name = "r10_usr"; + break; + case dwarf_r11_usr: + reg_info.name = "r11_usr"; + break; + case dwarf_r12_usr: + reg_info.name = "r12_usr"; + break; + case dwarf_r13_usr: + reg_info.name = "r13_usr"; + break; + case dwarf_r14_usr: + reg_info.name = "r14_usr"; + break; + case dwarf_r8_fiq: + reg_info.name = "r8_fiq"; + break; + case dwarf_r9_fiq: + reg_info.name = "r9_fiq"; + break; + case dwarf_r10_fiq: + reg_info.name = "r10_fiq"; + break; + case dwarf_r11_fiq: + reg_info.name = "r11_fiq"; + break; + case dwarf_r12_fiq: + reg_info.name = "r12_fiq"; + break; + case dwarf_r13_fiq: + reg_info.name = "r13_fiq"; + break; + case dwarf_r14_fiq: + reg_info.name = "r14_fiq"; + break; + case dwarf_r13_irq: + reg_info.name = "r13_irq"; + break; + case dwarf_r14_irq: + reg_info.name = "r14_irq"; + break; + case dwarf_r13_abt: + reg_info.name = "r13_abt"; + break; + case dwarf_r14_abt: + reg_info.name = "r14_abt"; + break; + case dwarf_r13_und: + reg_info.name = "r13_und"; + break; + case dwarf_r14_und: + reg_info.name = "r14_und"; + break; + case dwarf_r13_svc: + reg_info.name = "r13_svc"; + break; + case dwarf_r14_svc: + reg_info.name = "r14_svc"; + break; - if (reg_num >= dwarf_q0 && reg_num <= dwarf_q15) - { - reg_info.byte_size = 16; - reg_info.format = eFormatVectorOfUInt8; - reg_info.encoding = eEncodingVector; - } - - if (reg_num >= dwarf_d0 && reg_num <= dwarf_d31) - { - reg_info.byte_size = 8; - reg_info.format = eFormatFloat; - reg_info.encoding = eEncodingIEEE754; - } - else if (reg_num >= dwarf_s0 && reg_num <= dwarf_s31) - { - reg_info.byte_size = 4; - reg_info.format = eFormatFloat; - reg_info.encoding = eEncodingIEEE754; - } - else if (reg_num >= dwarf_f0 && reg_num <= dwarf_f7) - { - reg_info.byte_size = 12; - reg_info.format = eFormatFloat; - reg_info.encoding = eEncodingIEEE754; - } - else - { - reg_info.byte_size = 4; - reg_info.format = eFormatHex; - reg_info.encoding = eEncodingUint; - } - - reg_info.kinds[eRegisterKindDWARF] = reg_num; + // Intel wireless MMX control register in co-processor 0 - 7 + case dwarf_wC0: + reg_info.name = "wC0"; + break; + case dwarf_wC1: + reg_info.name = "wC1"; + break; + case dwarf_wC2: + reg_info.name = "wC2"; + break; + case dwarf_wC3: + reg_info.name = "wC3"; + break; + case dwarf_wC4: + reg_info.name = "wC4"; + break; + case dwarf_wC5: + reg_info.name = "wC5"; + break; + case dwarf_wC6: + reg_info.name = "wC6"; + break; + case dwarf_wC7: + reg_info.name = "wC7"; + break; - switch (reg_num) - { - case dwarf_r0: reg_info.name = "r0"; break; - case dwarf_r1: reg_info.name = "r1"; break; - case dwarf_r2: reg_info.name = "r2"; break; - case dwarf_r3: reg_info.name = "r3"; break; - case dwarf_r4: reg_info.name = "r4"; break; - case dwarf_r5: reg_info.name = "r5"; break; - case dwarf_r6: reg_info.name = "r6"; break; - case dwarf_r7: reg_info.name = "r7"; reg_info.kinds[eRegisterKindGeneric] = LLDB_REGNUM_GENERIC_FP; break; - case dwarf_r8: reg_info.name = "r8"; break; - case dwarf_r9: reg_info.name = "r9"; break; - case dwarf_r10: reg_info.name = "r10"; break; - case dwarf_r11: reg_info.name = "r11"; break; - case dwarf_r12: reg_info.name = "r12"; break; - case dwarf_sp: reg_info.name = "sp"; reg_info.alt_name = "r13"; reg_info.kinds[eRegisterKindGeneric] = LLDB_REGNUM_GENERIC_SP; break; - case dwarf_lr: reg_info.name = "lr"; reg_info.alt_name = "r14"; reg_info.kinds[eRegisterKindGeneric] = LLDB_REGNUM_GENERIC_RA; break; - case dwarf_pc: reg_info.name = "pc"; reg_info.alt_name = "r15"; reg_info.kinds[eRegisterKindGeneric] = LLDB_REGNUM_GENERIC_PC; break; - case dwarf_cpsr:reg_info.name = "cpsr"; reg_info.kinds[eRegisterKindGeneric] = LLDB_REGNUM_GENERIC_FLAGS; break; - - case dwarf_s0: reg_info.name = "s0"; break; - case dwarf_s1: reg_info.name = "s1"; break; - case dwarf_s2: reg_info.name = "s2"; break; - case dwarf_s3: reg_info.name = "s3"; break; - case dwarf_s4: reg_info.name = "s4"; break; - case dwarf_s5: reg_info.name = "s5"; break; - case dwarf_s6: reg_info.name = "s6"; break; - case dwarf_s7: reg_info.name = "s7"; break; - case dwarf_s8: reg_info.name = "s8"; break; - case dwarf_s9: reg_info.name = "s9"; break; - case dwarf_s10: reg_info.name = "s10"; break; - case dwarf_s11: reg_info.name = "s11"; break; - case dwarf_s12: reg_info.name = "s12"; break; - case dwarf_s13: reg_info.name = "s13"; break; - case dwarf_s14: reg_info.name = "s14"; break; - case dwarf_s15: reg_info.name = "s15"; break; - case dwarf_s16: reg_info.name = "s16"; break; - case dwarf_s17: reg_info.name = "s17"; break; - case dwarf_s18: reg_info.name = "s18"; break; - case dwarf_s19: reg_info.name = "s19"; break; - case dwarf_s20: reg_info.name = "s20"; break; - case dwarf_s21: reg_info.name = "s21"; break; - case dwarf_s22: reg_info.name = "s22"; break; - case dwarf_s23: reg_info.name = "s23"; break; - case dwarf_s24: reg_info.name = "s24"; break; - case dwarf_s25: reg_info.name = "s25"; break; - case dwarf_s26: reg_info.name = "s26"; break; - case dwarf_s27: reg_info.name = "s27"; break; - case dwarf_s28: reg_info.name = "s28"; break; - case dwarf_s29: reg_info.name = "s29"; break; - case dwarf_s30: reg_info.name = "s30"; break; - case dwarf_s31: reg_info.name = "s31"; break; - - // FPA Registers 0-7 - case dwarf_f0: reg_info.name = "f0"; break; - case dwarf_f1: reg_info.name = "f1"; break; - case dwarf_f2: reg_info.name = "f2"; break; - case dwarf_f3: reg_info.name = "f3"; break; - case dwarf_f4: reg_info.name = "f4"; break; - case dwarf_f5: reg_info.name = "f5"; break; - case dwarf_f6: reg_info.name = "f6"; break; - case dwarf_f7: reg_info.name = "f7"; break; - - // Intel wireless MMX general purpose registers 0 - 7 - // XScale accumulator register 0 - 7 (they do overlap with wCGR0 - wCGR7) - case dwarf_wCGR0: reg_info.name = "wCGR0/ACC0"; break; - case dwarf_wCGR1: reg_info.name = "wCGR1/ACC1"; break; - case dwarf_wCGR2: reg_info.name = "wCGR2/ACC2"; break; - case dwarf_wCGR3: reg_info.name = "wCGR3/ACC3"; break; - case dwarf_wCGR4: reg_info.name = "wCGR4/ACC4"; break; - case dwarf_wCGR5: reg_info.name = "wCGR5/ACC5"; break; - case dwarf_wCGR6: reg_info.name = "wCGR6/ACC6"; break; - case dwarf_wCGR7: reg_info.name = "wCGR7/ACC7"; break; - - // Intel wireless MMX data registers 0 - 15 - case dwarf_wR0: reg_info.name = "wR0"; break; - case dwarf_wR1: reg_info.name = "wR1"; break; - case dwarf_wR2: reg_info.name = "wR2"; break; - case dwarf_wR3: reg_info.name = "wR3"; break; - case dwarf_wR4: reg_info.name = "wR4"; break; - case dwarf_wR5: reg_info.name = "wR5"; break; - case dwarf_wR6: reg_info.name = "wR6"; break; - case dwarf_wR7: reg_info.name = "wR7"; break; - case dwarf_wR8: reg_info.name = "wR8"; break; - case dwarf_wR9: reg_info.name = "wR9"; break; - case dwarf_wR10: reg_info.name = "wR10"; break; - case dwarf_wR11: reg_info.name = "wR11"; break; - case dwarf_wR12: reg_info.name = "wR12"; break; - case dwarf_wR13: reg_info.name = "wR13"; break; - case dwarf_wR14: reg_info.name = "wR14"; break; - case dwarf_wR15: reg_info.name = "wR15"; break; - - case dwarf_spsr: reg_info.name = "spsr"; break; - case dwarf_spsr_fiq: reg_info.name = "spsr_fiq"; break; - case dwarf_spsr_irq: reg_info.name = "spsr_irq"; break; - case dwarf_spsr_abt: reg_info.name = "spsr_abt"; break; - case dwarf_spsr_und: reg_info.name = "spsr_und"; break; - case dwarf_spsr_svc: reg_info.name = "spsr_svc"; break; - - case dwarf_r8_usr: reg_info.name = "r8_usr"; break; - case dwarf_r9_usr: reg_info.name = "r9_usr"; break; - case dwarf_r10_usr: reg_info.name = "r10_usr"; break; - case dwarf_r11_usr: reg_info.name = "r11_usr"; break; - case dwarf_r12_usr: reg_info.name = "r12_usr"; break; - case dwarf_r13_usr: reg_info.name = "r13_usr"; break; - case dwarf_r14_usr: reg_info.name = "r14_usr"; break; - case dwarf_r8_fiq: reg_info.name = "r8_fiq"; break; - case dwarf_r9_fiq: reg_info.name = "r9_fiq"; break; - case dwarf_r10_fiq: reg_info.name = "r10_fiq"; break; - case dwarf_r11_fiq: reg_info.name = "r11_fiq"; break; - case dwarf_r12_fiq: reg_info.name = "r12_fiq"; break; - case dwarf_r13_fiq: reg_info.name = "r13_fiq"; break; - case dwarf_r14_fiq: reg_info.name = "r14_fiq"; break; - case dwarf_r13_irq: reg_info.name = "r13_irq"; break; - case dwarf_r14_irq: reg_info.name = "r14_irq"; break; - case dwarf_r13_abt: reg_info.name = "r13_abt"; break; - case dwarf_r14_abt: reg_info.name = "r14_abt"; break; - case dwarf_r13_und: reg_info.name = "r13_und"; break; - case dwarf_r14_und: reg_info.name = "r14_und"; break; - case dwarf_r13_svc: reg_info.name = "r13_svc"; break; - case dwarf_r14_svc: reg_info.name = "r14_svc"; break; - - // Intel wireless MMX control register in co-processor 0 - 7 - case dwarf_wC0: reg_info.name = "wC0"; break; - case dwarf_wC1: reg_info.name = "wC1"; break; - case dwarf_wC2: reg_info.name = "wC2"; break; - case dwarf_wC3: reg_info.name = "wC3"; break; - case dwarf_wC4: reg_info.name = "wC4"; break; - case dwarf_wC5: reg_info.name = "wC5"; break; - case dwarf_wC6: reg_info.name = "wC6"; break; - case dwarf_wC7: reg_info.name = "wC7"; break; - - // VFP-v3/Neon - case dwarf_d0: reg_info.name = "d0"; break; - case dwarf_d1: reg_info.name = "d1"; break; - case dwarf_d2: reg_info.name = "d2"; break; - case dwarf_d3: reg_info.name = "d3"; break; - case dwarf_d4: reg_info.name = "d4"; break; - case dwarf_d5: reg_info.name = "d5"; break; - case dwarf_d6: reg_info.name = "d6"; break; - case dwarf_d7: reg_info.name = "d7"; break; - case dwarf_d8: reg_info.name = "d8"; break; - case dwarf_d9: reg_info.name = "d9"; break; - case dwarf_d10: reg_info.name = "d10"; break; - case dwarf_d11: reg_info.name = "d11"; break; - case dwarf_d12: reg_info.name = "d12"; break; - case dwarf_d13: reg_info.name = "d13"; break; - case dwarf_d14: reg_info.name = "d14"; break; - case dwarf_d15: reg_info.name = "d15"; break; - case dwarf_d16: reg_info.name = "d16"; break; - case dwarf_d17: reg_info.name = "d17"; break; - case dwarf_d18: reg_info.name = "d18"; break; - case dwarf_d19: reg_info.name = "d19"; break; - case dwarf_d20: reg_info.name = "d20"; break; - case dwarf_d21: reg_info.name = "d21"; break; - case dwarf_d22: reg_info.name = "d22"; break; - case dwarf_d23: reg_info.name = "d23"; break; - case dwarf_d24: reg_info.name = "d24"; break; - case dwarf_d25: reg_info.name = "d25"; break; - case dwarf_d26: reg_info.name = "d26"; break; - case dwarf_d27: reg_info.name = "d27"; break; - case dwarf_d28: reg_info.name = "d28"; break; - case dwarf_d29: reg_info.name = "d29"; break; - case dwarf_d30: reg_info.name = "d30"; break; - case dwarf_d31: reg_info.name = "d31"; break; + // VFP-v3/Neon + case dwarf_d0: + reg_info.name = "d0"; + break; + case dwarf_d1: + reg_info.name = "d1"; + break; + case dwarf_d2: + reg_info.name = "d2"; + break; + case dwarf_d3: + reg_info.name = "d3"; + break; + case dwarf_d4: + reg_info.name = "d4"; + break; + case dwarf_d5: + reg_info.name = "d5"; + break; + case dwarf_d6: + reg_info.name = "d6"; + break; + case dwarf_d7: + reg_info.name = "d7"; + break; + case dwarf_d8: + reg_info.name = "d8"; + break; + case dwarf_d9: + reg_info.name = "d9"; + break; + case dwarf_d10: + reg_info.name = "d10"; + break; + case dwarf_d11: + reg_info.name = "d11"; + break; + case dwarf_d12: + reg_info.name = "d12"; + break; + case dwarf_d13: + reg_info.name = "d13"; + break; + case dwarf_d14: + reg_info.name = "d14"; + break; + case dwarf_d15: + reg_info.name = "d15"; + break; + case dwarf_d16: + reg_info.name = "d16"; + break; + case dwarf_d17: + reg_info.name = "d17"; + break; + case dwarf_d18: + reg_info.name = "d18"; + break; + case dwarf_d19: + reg_info.name = "d19"; + break; + case dwarf_d20: + reg_info.name = "d20"; + break; + case dwarf_d21: + reg_info.name = "d21"; + break; + case dwarf_d22: + reg_info.name = "d22"; + break; + case dwarf_d23: + reg_info.name = "d23"; + break; + case dwarf_d24: + reg_info.name = "d24"; + break; + case dwarf_d25: + reg_info.name = "d25"; + break; + case dwarf_d26: + reg_info.name = "d26"; + break; + case dwarf_d27: + reg_info.name = "d27"; + break; + case dwarf_d28: + reg_info.name = "d28"; + break; + case dwarf_d29: + reg_info.name = "d29"; + break; + case dwarf_d30: + reg_info.name = "d30"; + break; + case dwarf_d31: + reg_info.name = "d31"; + break; - // NEON 128-bit vector registers (overlays the d registers) - case dwarf_q0: reg_info.name = "q0"; break; - case dwarf_q1: reg_info.name = "q1"; break; - case dwarf_q2: reg_info.name = "q2"; break; - case dwarf_q3: reg_info.name = "q3"; break; - case dwarf_q4: reg_info.name = "q4"; break; - case dwarf_q5: reg_info.name = "q5"; break; - case dwarf_q6: reg_info.name = "q6"; break; - case dwarf_q7: reg_info.name = "q7"; break; - case dwarf_q8: reg_info.name = "q8"; break; - case dwarf_q9: reg_info.name = "q9"; break; - case dwarf_q10: reg_info.name = "q10"; break; - case dwarf_q11: reg_info.name = "q11"; break; - case dwarf_q12: reg_info.name = "q12"; break; - case dwarf_q13: reg_info.name = "q13"; break; - case dwarf_q14: reg_info.name = "q14"; break; - case dwarf_q15: reg_info.name = "q15"; break; + // NEON 128-bit vector registers (overlays the d registers) + case dwarf_q0: + reg_info.name = "q0"; + break; + case dwarf_q1: + reg_info.name = "q1"; + break; + case dwarf_q2: + reg_info.name = "q2"; + break; + case dwarf_q3: + reg_info.name = "q3"; + break; + case dwarf_q4: + reg_info.name = "q4"; + break; + case dwarf_q5: + reg_info.name = "q5"; + break; + case dwarf_q6: + reg_info.name = "q6"; + break; + case dwarf_q7: + reg_info.name = "q7"; + break; + case dwarf_q8: + reg_info.name = "q8"; + break; + case dwarf_q9: + reg_info.name = "q9"; + break; + case dwarf_q10: + reg_info.name = "q10"; + break; + case dwarf_q11: + reg_info.name = "q11"; + break; + case dwarf_q12: + reg_info.name = "q12"; + break; + case dwarf_q13: + reg_info.name = "q13"; + break; + case dwarf_q14: + reg_info.name = "q14"; + break; + case dwarf_q15: + reg_info.name = "q15"; + break; - default: return false; - } - return true; + default: + return false; + } + return true; } diff --git a/lldb/source/Utility/ARM_DWARF_Registers.h b/lldb/source/Utility/ARM_DWARF_Registers.h index 6850d3e..9b226c1 100644 --- a/lldb/source/Utility/ARM_DWARF_Registers.h +++ b/lldb/source/Utility/ARM_DWARF_Registers.h @@ -12,206 +12,202 @@ #include "lldb/lldb-private.h" -enum -{ - 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_sp, - dwarf_lr, - dwarf_pc, - dwarf_cpsr, - - dwarf_s0 = 64, - dwarf_s1, - dwarf_s2, - dwarf_s3, - dwarf_s4, - dwarf_s5, - dwarf_s6, - dwarf_s7, - dwarf_s8, - dwarf_s9, - dwarf_s10, - dwarf_s11, - dwarf_s12, - dwarf_s13, - dwarf_s14, - dwarf_s15, - dwarf_s16, - dwarf_s17, - dwarf_s18, - dwarf_s19, - dwarf_s20, - dwarf_s21, - dwarf_s22, - dwarf_s23, - dwarf_s24, - dwarf_s25, - dwarf_s26, - dwarf_s27, - dwarf_s28, - dwarf_s29, - dwarf_s30, - dwarf_s31, - - // FPA Registers 0-7 - dwarf_f0 = 96, - dwarf_f1, - dwarf_f2, - dwarf_f3, - dwarf_f4, - dwarf_f5, - dwarf_f6, - dwarf_f7, - - // Intel wireless MMX general purpose registers 0 - 7 - dwarf_wCGR0 = 104, - dwarf_wCGR1, - dwarf_wCGR2, - dwarf_wCGR3, - dwarf_wCGR4, - dwarf_wCGR5, - dwarf_wCGR6, - dwarf_wCGR7, - - // XScale accumulator register 0 - 7 (they do overlap with wCGR0 - wCGR7) - dwarf_ACC0 = 104, - dwarf_ACC1, - dwarf_ACC2, - dwarf_ACC3, - dwarf_ACC4, - dwarf_ACC5, - dwarf_ACC6, - dwarf_ACC7, - - // Intel wireless MMX data registers 0 - 15 - dwarf_wR0 = 112, - dwarf_wR1, - dwarf_wR2, - dwarf_wR3, - dwarf_wR4, - dwarf_wR5, - dwarf_wR6, - dwarf_wR7, - dwarf_wR8, - dwarf_wR9, - dwarf_wR10, - dwarf_wR11, - dwarf_wR12, - dwarf_wR13, - dwarf_wR14, - dwarf_wR15, - - dwarf_spsr = 128, - dwarf_spsr_fiq, - dwarf_spsr_irq, - dwarf_spsr_abt, - dwarf_spsr_und, - dwarf_spsr_svc, - - dwarf_r8_usr = 144, - dwarf_r9_usr, - dwarf_r10_usr, - dwarf_r11_usr, - dwarf_r12_usr, - dwarf_r13_usr, - dwarf_r14_usr, - dwarf_r8_fiq, - dwarf_r9_fiq, - dwarf_r10_fiq, - dwarf_r11_fiq, - dwarf_r12_fiq, - dwarf_r13_fiq, - dwarf_r14_fiq, - dwarf_r13_irq, - dwarf_r14_irq, - dwarf_r13_abt, - dwarf_r14_abt, - dwarf_r13_und, - dwarf_r14_und, - dwarf_r13_svc, - dwarf_r14_svc, - - // Intel wireless MMX control register in co-processor 0 - 7 - dwarf_wC0 = 192, - dwarf_wC1, - dwarf_wC2, - dwarf_wC3, - dwarf_wC4, - dwarf_wC5, - dwarf_wC6, - dwarf_wC7, - - // VFP-v3/Neon - dwarf_d0 = 256, - dwarf_d1, - dwarf_d2, - dwarf_d3, - dwarf_d4, - dwarf_d5, - dwarf_d6, - dwarf_d7, - dwarf_d8, - dwarf_d9, - dwarf_d10, - dwarf_d11, - dwarf_d12, - dwarf_d13, - dwarf_d14, - dwarf_d15, - dwarf_d16, - dwarf_d17, - dwarf_d18, - dwarf_d19, - dwarf_d20, - dwarf_d21, - dwarf_d22, - dwarf_d23, - dwarf_d24, - dwarf_d25, - dwarf_d26, - dwarf_d27, - dwarf_d28, - dwarf_d29, - dwarf_d30, - dwarf_d31, - - // Neon quadword registers - dwarf_q0 = 288, - dwarf_q1, - dwarf_q2, - dwarf_q3, - dwarf_q4, - dwarf_q5, - dwarf_q6, - dwarf_q7, - dwarf_q8, - dwarf_q9, - dwarf_q10, - dwarf_q11, - dwarf_q12, - dwarf_q13, - dwarf_q14, - dwarf_q15 +enum { + 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_sp, + dwarf_lr, + dwarf_pc, + dwarf_cpsr, + + dwarf_s0 = 64, + dwarf_s1, + dwarf_s2, + dwarf_s3, + dwarf_s4, + dwarf_s5, + dwarf_s6, + dwarf_s7, + dwarf_s8, + dwarf_s9, + dwarf_s10, + dwarf_s11, + dwarf_s12, + dwarf_s13, + dwarf_s14, + dwarf_s15, + dwarf_s16, + dwarf_s17, + dwarf_s18, + dwarf_s19, + dwarf_s20, + dwarf_s21, + dwarf_s22, + dwarf_s23, + dwarf_s24, + dwarf_s25, + dwarf_s26, + dwarf_s27, + dwarf_s28, + dwarf_s29, + dwarf_s30, + dwarf_s31, + + // FPA Registers 0-7 + dwarf_f0 = 96, + dwarf_f1, + dwarf_f2, + dwarf_f3, + dwarf_f4, + dwarf_f5, + dwarf_f6, + dwarf_f7, + + // Intel wireless MMX general purpose registers 0 - 7 + dwarf_wCGR0 = 104, + dwarf_wCGR1, + dwarf_wCGR2, + dwarf_wCGR3, + dwarf_wCGR4, + dwarf_wCGR5, + dwarf_wCGR6, + dwarf_wCGR7, + + // XScale accumulator register 0 - 7 (they do overlap with wCGR0 - wCGR7) + dwarf_ACC0 = 104, + dwarf_ACC1, + dwarf_ACC2, + dwarf_ACC3, + dwarf_ACC4, + dwarf_ACC5, + dwarf_ACC6, + dwarf_ACC7, + + // Intel wireless MMX data registers 0 - 15 + dwarf_wR0 = 112, + dwarf_wR1, + dwarf_wR2, + dwarf_wR3, + dwarf_wR4, + dwarf_wR5, + dwarf_wR6, + dwarf_wR7, + dwarf_wR8, + dwarf_wR9, + dwarf_wR10, + dwarf_wR11, + dwarf_wR12, + dwarf_wR13, + dwarf_wR14, + dwarf_wR15, + + dwarf_spsr = 128, + dwarf_spsr_fiq, + dwarf_spsr_irq, + dwarf_spsr_abt, + dwarf_spsr_und, + dwarf_spsr_svc, + + dwarf_r8_usr = 144, + dwarf_r9_usr, + dwarf_r10_usr, + dwarf_r11_usr, + dwarf_r12_usr, + dwarf_r13_usr, + dwarf_r14_usr, + dwarf_r8_fiq, + dwarf_r9_fiq, + dwarf_r10_fiq, + dwarf_r11_fiq, + dwarf_r12_fiq, + dwarf_r13_fiq, + dwarf_r14_fiq, + dwarf_r13_irq, + dwarf_r14_irq, + dwarf_r13_abt, + dwarf_r14_abt, + dwarf_r13_und, + dwarf_r14_und, + dwarf_r13_svc, + dwarf_r14_svc, + + // Intel wireless MMX control register in co-processor 0 - 7 + dwarf_wC0 = 192, + dwarf_wC1, + dwarf_wC2, + dwarf_wC3, + dwarf_wC4, + dwarf_wC5, + dwarf_wC6, + dwarf_wC7, + + // VFP-v3/Neon + dwarf_d0 = 256, + dwarf_d1, + dwarf_d2, + dwarf_d3, + dwarf_d4, + dwarf_d5, + dwarf_d6, + dwarf_d7, + dwarf_d8, + dwarf_d9, + dwarf_d10, + dwarf_d11, + dwarf_d12, + dwarf_d13, + dwarf_d14, + dwarf_d15, + dwarf_d16, + dwarf_d17, + dwarf_d18, + dwarf_d19, + dwarf_d20, + dwarf_d21, + dwarf_d22, + dwarf_d23, + dwarf_d24, + dwarf_d25, + dwarf_d26, + dwarf_d27, + dwarf_d28, + dwarf_d29, + dwarf_d30, + dwarf_d31, + + // Neon quadword registers + dwarf_q0 = 288, + dwarf_q1, + dwarf_q2, + dwarf_q3, + dwarf_q4, + dwarf_q5, + dwarf_q6, + dwarf_q7, + dwarf_q8, + dwarf_q9, + dwarf_q10, + dwarf_q11, + dwarf_q12, + dwarf_q13, + dwarf_q14, + dwarf_q15 }; -const char * -GetARMDWARFRegisterName (unsigned reg_num); - -bool -GetARMDWARFRegisterInfo (unsigned reg_num, - lldb_private::RegisterInfo ®_info); +const char *GetARMDWARFRegisterName(unsigned reg_num); -#endif // utility_ARM_DWARF_Registers_h_ +bool GetARMDWARFRegisterInfo(unsigned reg_num, + lldb_private::RegisterInfo ®_info); +#endif // utility_ARM_DWARF_Registers_h_ diff --git a/lldb/source/Utility/ARM_ehframe_Registers.h b/lldb/source/Utility/ARM_ehframe_Registers.h index 7d4951d..2a42423 100644 --- a/lldb/source/Utility/ARM_ehframe_Registers.h +++ b/lldb/source/Utility/ARM_ehframe_Registers.h @@ -1,4 +1,5 @@ -//===-- ARM_ehframe_Registers.h -------------------------------------*- C++ -*-===// +//===-- ARM_ehframe_Registers.h -------------------------------------*- C++ +//-*-===// // // The LLVM Compiler Infrastructure // @@ -13,26 +14,24 @@ // The register numbers used in the eh_frame unwind information. // Should be the same as DWARF register numbers. -enum -{ - ehframe_r0 = 0, - ehframe_r1, - ehframe_r2, - ehframe_r3, - ehframe_r4, - ehframe_r5, - ehframe_r6, - ehframe_r7, - ehframe_r8, - ehframe_r9, - ehframe_r10, - ehframe_r11, - ehframe_r12, - ehframe_sp, - ehframe_lr, - ehframe_pc, - ehframe_cpsr +enum { + ehframe_r0 = 0, + ehframe_r1, + ehframe_r2, + ehframe_r3, + ehframe_r4, + ehframe_r5, + ehframe_r6, + ehframe_r7, + ehframe_r8, + ehframe_r9, + ehframe_r10, + ehframe_r11, + ehframe_r12, + ehframe_sp, + ehframe_lr, + ehframe_pc, + ehframe_cpsr }; #endif // utility_ARM_ehframe_Registers_h_ - diff --git a/lldb/source/Utility/ConvertEnum.cpp b/lldb/source/Utility/ConvertEnum.cpp index 9951563..bb0484e 100644 --- a/lldb/source/Utility/ConvertEnum.cpp +++ b/lldb/source/Utility/ConvertEnum.cpp @@ -11,114 +11,108 @@ using namespace lldb; using namespace lldb_private; -const char * -lldb_private::GetVoteAsCString(Vote vote) -{ - switch (vote) - { - case eVoteNo: - return "no"; - case eVoteNoOpinion: - return "no opinion"; - case eVoteYes: - return "yes"; - } - return "invalid"; +const char *lldb_private::GetVoteAsCString(Vote vote) { + switch (vote) { + case eVoteNo: + return "no"; + case eVoteNoOpinion: + return "no opinion"; + case eVoteYes: + return "yes"; + } + return "invalid"; } -const char * -lldb_private::GetSectionTypeAsCString(lldb::SectionType sect_type) -{ - switch (sect_type) - { - case eSectionTypeInvalid: - return "invalid"; - case eSectionTypeCode: - return "code"; - case eSectionTypeContainer: - return "container"; - case eSectionTypeData: - return "data"; - case eSectionTypeDataCString: - return "data-cstr"; - case eSectionTypeDataCStringPointers: - return "data-cstr-ptr"; - case eSectionTypeDataSymbolAddress: - return "data-symbol-addr"; - case eSectionTypeData4: - return "data-4-byte"; - case eSectionTypeData8: - return "data-8-byte"; - case eSectionTypeData16: - return "data-16-byte"; - case eSectionTypeDataPointers: - return "data-ptrs"; - case eSectionTypeDebug: - return "debug"; - case eSectionTypeZeroFill: - return "zero-fill"; - case eSectionTypeDataObjCMessageRefs: - return "objc-message-refs"; - case eSectionTypeDataObjCCFStrings: - return "objc-cfstrings"; - case eSectionTypeDWARFDebugAbbrev: - return "dwarf-abbrev"; - case eSectionTypeDWARFDebugAddr: - return "dwarf-addr"; - case eSectionTypeDWARFDebugAranges: - return "dwarf-aranges"; - case eSectionTypeDWARFDebugFrame: - return "dwarf-frame"; - case eSectionTypeDWARFDebugInfo: - return "dwarf-info"; - case eSectionTypeDWARFDebugLine: - return "dwarf-line"; - case eSectionTypeDWARFDebugLoc: - return "dwarf-loc"; - case eSectionTypeDWARFDebugMacInfo: - return "dwarf-macinfo"; - case eSectionTypeDWARFDebugMacro: - return "dwarf-macro"; - case eSectionTypeDWARFDebugPubNames: - return "dwarf-pubnames"; - case eSectionTypeDWARFDebugPubTypes: - return "dwarf-pubtypes"; - case eSectionTypeDWARFDebugRanges: - return "dwarf-ranges"; - case eSectionTypeDWARFDebugStr: - return "dwarf-str"; - case eSectionTypeDWARFDebugStrOffsets: - return "dwarf-str-offsets"; - case eSectionTypeELFSymbolTable: - return "elf-symbol-table"; - case eSectionTypeELFDynamicSymbols: - return "elf-dynamic-symbols"; - case eSectionTypeELFRelocationEntries: - return "elf-relocation-entries"; - case eSectionTypeELFDynamicLinkInfo: - return "elf-dynamic-link-info"; - case eSectionTypeDWARFAppleNames: - return "apple-names"; - case eSectionTypeDWARFAppleTypes: - return "apple-types"; - case eSectionTypeDWARFAppleNamespaces: - return "apple-namespaces"; - case eSectionTypeDWARFAppleObjC: - return "apple-objc"; - case eSectionTypeEHFrame: - return "eh-frame"; - case eSectionTypeARMexidx: - return "ARM.exidx"; - case eSectionTypeARMextab: - return "ARM.extab"; - case eSectionTypeCompactUnwind: - return "compact-unwind"; - case eSectionTypeGoSymtab: - return "go-symtab"; - case eSectionTypeAbsoluteAddress: - return "absolute"; - case eSectionTypeOther: - return "regular"; - } - return "unknown"; +const char *lldb_private::GetSectionTypeAsCString(lldb::SectionType sect_type) { + switch (sect_type) { + case eSectionTypeInvalid: + return "invalid"; + case eSectionTypeCode: + return "code"; + case eSectionTypeContainer: + return "container"; + case eSectionTypeData: + return "data"; + case eSectionTypeDataCString: + return "data-cstr"; + case eSectionTypeDataCStringPointers: + return "data-cstr-ptr"; + case eSectionTypeDataSymbolAddress: + return "data-symbol-addr"; + case eSectionTypeData4: + return "data-4-byte"; + case eSectionTypeData8: + return "data-8-byte"; + case eSectionTypeData16: + return "data-16-byte"; + case eSectionTypeDataPointers: + return "data-ptrs"; + case eSectionTypeDebug: + return "debug"; + case eSectionTypeZeroFill: + return "zero-fill"; + case eSectionTypeDataObjCMessageRefs: + return "objc-message-refs"; + case eSectionTypeDataObjCCFStrings: + return "objc-cfstrings"; + case eSectionTypeDWARFDebugAbbrev: + return "dwarf-abbrev"; + case eSectionTypeDWARFDebugAddr: + return "dwarf-addr"; + case eSectionTypeDWARFDebugAranges: + return "dwarf-aranges"; + case eSectionTypeDWARFDebugFrame: + return "dwarf-frame"; + case eSectionTypeDWARFDebugInfo: + return "dwarf-info"; + case eSectionTypeDWARFDebugLine: + return "dwarf-line"; + case eSectionTypeDWARFDebugLoc: + return "dwarf-loc"; + case eSectionTypeDWARFDebugMacInfo: + return "dwarf-macinfo"; + case eSectionTypeDWARFDebugMacro: + return "dwarf-macro"; + case eSectionTypeDWARFDebugPubNames: + return "dwarf-pubnames"; + case eSectionTypeDWARFDebugPubTypes: + return "dwarf-pubtypes"; + case eSectionTypeDWARFDebugRanges: + return "dwarf-ranges"; + case eSectionTypeDWARFDebugStr: + return "dwarf-str"; + case eSectionTypeDWARFDebugStrOffsets: + return "dwarf-str-offsets"; + case eSectionTypeELFSymbolTable: + return "elf-symbol-table"; + case eSectionTypeELFDynamicSymbols: + return "elf-dynamic-symbols"; + case eSectionTypeELFRelocationEntries: + return "elf-relocation-entries"; + case eSectionTypeELFDynamicLinkInfo: + return "elf-dynamic-link-info"; + case eSectionTypeDWARFAppleNames: + return "apple-names"; + case eSectionTypeDWARFAppleTypes: + return "apple-types"; + case eSectionTypeDWARFAppleNamespaces: + return "apple-namespaces"; + case eSectionTypeDWARFAppleObjC: + return "apple-objc"; + case eSectionTypeEHFrame: + return "eh-frame"; + case eSectionTypeARMexidx: + return "ARM.exidx"; + case eSectionTypeARMextab: + return "ARM.extab"; + case eSectionTypeCompactUnwind: + return "compact-unwind"; + case eSectionTypeGoSymtab: + return "go-symtab"; + case eSectionTypeAbsoluteAddress: + return "absolute"; + case eSectionTypeOther: + return "regular"; + } + return "unknown"; } diff --git a/lldb/source/Utility/JSON.cpp b/lldb/source/Utility/JSON.cpp index 7ad3232..5b809c5 100644 --- a/lldb/source/Utility/JSON.cpp +++ b/lldb/source/Utility/JSON.cpp @@ -9,685 +9,542 @@ #include "lldb/Utility/JSON.h" -#include <limits.h> #include "lldb/Core/StreamString.h" #include "lldb/Host/StringConvert.h" #include "llvm/Support/ErrorHandling.h" +#include <limits.h> using namespace lldb_private; -std::string -JSONString::json_string_quote_metachars (const std::string &s) -{ - if (s.find('"') == std::string::npos) - return s; - - std::string output; - const size_t s_size = s.size(); - const char *s_chars = s.c_str(); - for (size_t i = 0; i < s_size; i++) - { - unsigned char ch = *(s_chars + i); - if (ch == '"') - { - output.push_back ('\\'); - } - output.push_back (ch); +std::string JSONString::json_string_quote_metachars(const std::string &s) { + if (s.find('"') == std::string::npos) + return s; + + std::string output; + const size_t s_size = s.size(); + const char *s_chars = s.c_str(); + for (size_t i = 0; i < s_size; i++) { + unsigned char ch = *(s_chars + i); + if (ch == '"') { + output.push_back('\\'); } - return output; + output.push_back(ch); + } + return output; } -JSONString::JSONString () : - JSONValue(JSONValue::Kind::String), - m_data() -{ -} +JSONString::JSONString() : JSONValue(JSONValue::Kind::String), m_data() {} -JSONString::JSONString (const char* s) : - JSONValue(JSONValue::Kind::String), - m_data(s ? s : "") -{ -} +JSONString::JSONString(const char *s) + : JSONValue(JSONValue::Kind::String), m_data(s ? s : "") {} -JSONString::JSONString (const std::string& s) : - JSONValue(JSONValue::Kind::String), - m_data(s) -{ -} +JSONString::JSONString(const std::string &s) + : JSONValue(JSONValue::Kind::String), m_data(s) {} -void -JSONString::Write (Stream& s) -{ - s.Printf("\"%s\"", json_string_quote_metachars(m_data).c_str()); +void JSONString::Write(Stream &s) { + s.Printf("\"%s\"", json_string_quote_metachars(m_data).c_str()); } -uint64_t -JSONNumber::GetAsUnsigned() const -{ - switch (m_data_type) - { - case DataType::Unsigned: - return m_data.m_unsigned; - case DataType::Signed: - return (uint64_t)m_data.m_signed; - case DataType::Double: - return (uint64_t)m_data.m_double; - } - llvm_unreachable("Unhandled data type"); +uint64_t JSONNumber::GetAsUnsigned() const { + switch (m_data_type) { + case DataType::Unsigned: + return m_data.m_unsigned; + case DataType::Signed: + return (uint64_t)m_data.m_signed; + case DataType::Double: + return (uint64_t)m_data.m_double; + } + llvm_unreachable("Unhandled data type"); } -int64_t -JSONNumber::GetAsSigned() const -{ - switch (m_data_type) - { - case DataType::Unsigned: - return (int64_t)m_data.m_unsigned; - case DataType::Signed: - return m_data.m_signed; - case DataType::Double: - return (int64_t)m_data.m_double; - } - llvm_unreachable("Unhandled data type"); +int64_t JSONNumber::GetAsSigned() const { + switch (m_data_type) { + case DataType::Unsigned: + return (int64_t)m_data.m_unsigned; + case DataType::Signed: + return m_data.m_signed; + case DataType::Double: + return (int64_t)m_data.m_double; + } + llvm_unreachable("Unhandled data type"); } -double -JSONNumber::GetAsDouble() const -{ - switch (m_data_type) - { - case DataType::Unsigned: - return (double)m_data.m_unsigned; - case DataType::Signed: - return (double)m_data.m_signed; - case DataType::Double: - return m_data.m_double; - } - llvm_unreachable("Unhandled data type"); +double JSONNumber::GetAsDouble() const { + switch (m_data_type) { + case DataType::Unsigned: + return (double)m_data.m_unsigned; + case DataType::Signed: + return (double)m_data.m_signed; + case DataType::Double: + return m_data.m_double; + } + llvm_unreachable("Unhandled data type"); } -void -JSONNumber::Write (Stream& s) -{ - switch (m_data_type) - { - case DataType::Unsigned: - s.Printf("%" PRIu64, m_data.m_unsigned); - break; - case DataType::Signed: - s.Printf("%" PRId64, m_data.m_signed); - break; - case DataType::Double: - s.Printf("%g", m_data.m_double); - break; - } +void JSONNumber::Write(Stream &s) { + switch (m_data_type) { + case DataType::Unsigned: + s.Printf("%" PRIu64, m_data.m_unsigned); + break; + case DataType::Signed: + s.Printf("%" PRId64, m_data.m_signed); + break; + case DataType::Double: + s.Printf("%g", m_data.m_double); + break; + } } -JSONTrue::JSONTrue () : - JSONValue(JSONValue::Kind::True) -{ -} +JSONTrue::JSONTrue() : JSONValue(JSONValue::Kind::True) {} -void -JSONTrue::Write(Stream& s) -{ - s.Printf("true"); -} +void JSONTrue::Write(Stream &s) { s.Printf("true"); } -JSONFalse::JSONFalse () : - JSONValue(JSONValue::Kind::False) -{ -} +JSONFalse::JSONFalse() : JSONValue(JSONValue::Kind::False) {} -void -JSONFalse::Write(Stream& s) -{ - s.Printf("false"); -} +void JSONFalse::Write(Stream &s) { s.Printf("false"); } -JSONNull::JSONNull () : - JSONValue(JSONValue::Kind::Null) -{ -} +JSONNull::JSONNull() : JSONValue(JSONValue::Kind::Null) {} -void -JSONNull::Write(Stream& s) -{ - s.Printf("null"); -} +void JSONNull::Write(Stream &s) { s.Printf("null"); } -JSONObject::JSONObject () : - JSONValue(JSONValue::Kind::Object) -{ -} +JSONObject::JSONObject() : JSONValue(JSONValue::Kind::Object) {} -void -JSONObject::Write (Stream& s) -{ - bool first = true; - s.PutChar('{'); - auto iter = m_elements.begin(), end = m_elements.end(); - for (;iter != end; iter++) - { - if (first) - first = false; - else - s.PutChar(','); - JSONString key(iter->first); - JSONValue::SP value(iter->second); - key.Write(s); - s.PutChar(':'); - value->Write(s); - } - s.PutChar('}'); +void JSONObject::Write(Stream &s) { + bool first = true; + s.PutChar('{'); + auto iter = m_elements.begin(), end = m_elements.end(); + for (; iter != end; iter++) { + if (first) + first = false; + else + s.PutChar(','); + JSONString key(iter->first); + JSONValue::SP value(iter->second); + key.Write(s); + s.PutChar(':'); + value->Write(s); + } + s.PutChar('}'); } -bool -JSONObject::SetObject (const std::string& key, - JSONValue::SP value) -{ - if (key.empty() || nullptr == value.get()) - return false; - m_elements[key] = value; - return true; +bool JSONObject::SetObject(const std::string &key, JSONValue::SP value) { + if (key.empty() || nullptr == value.get()) + return false; + m_elements[key] = value; + return true; } -JSONValue::SP -JSONObject::GetObject (const std::string& key) -{ - auto iter = m_elements.find(key), end = m_elements.end(); - if (iter == end) - return JSONValue::SP(); - return iter->second; +JSONValue::SP JSONObject::GetObject(const std::string &key) { + auto iter = m_elements.find(key), end = m_elements.end(); + if (iter == end) + return JSONValue::SP(); + return iter->second; } -JSONArray::JSONArray () : - JSONValue(JSONValue::Kind::Array) -{ +JSONArray::JSONArray() : JSONValue(JSONValue::Kind::Array) {} + +void JSONArray::Write(Stream &s) { + bool first = true; + s.PutChar('['); + auto iter = m_elements.begin(), end = m_elements.end(); + for (; iter != end; iter++) { + if (first) + first = false; + else + s.PutChar(','); + (*iter)->Write(s); + } + s.PutChar(']'); } -void -JSONArray::Write (Stream& s) -{ - bool first = true; - s.PutChar('['); - auto iter = m_elements.begin(), end = m_elements.end(); - for (;iter != end; iter++) - { - if (first) - first = false; - else - s.PutChar(','); - (*iter)->Write(s); - } - s.PutChar(']'); -} - -bool -JSONArray::SetObject (Index i, - JSONValue::SP value) -{ - if (value.get() == nullptr) - return false; - if (i < m_elements.size()) - { - m_elements[i] = value; - return true; - } - if (i == m_elements.size()) - { - m_elements.push_back(value); - return true; - } +bool JSONArray::SetObject(Index i, JSONValue::SP value) { + if (value.get() == nullptr) return false; -} - -bool -JSONArray::AppendObject (JSONValue::SP value) -{ - if (value.get() == nullptr) - return false; + if (i < m_elements.size()) { + m_elements[i] = value; + return true; + } + if (i == m_elements.size()) { m_elements.push_back(value); return true; + } + return false; } -JSONValue::SP -JSONArray::GetObject (Index i) -{ - if (i < m_elements.size()) - return m_elements[i]; - return JSONValue::SP(); +bool JSONArray::AppendObject(JSONValue::SP value) { + if (value.get() == nullptr) + return false; + m_elements.push_back(value); + return true; } -JSONArray::Size -JSONArray::GetNumElements () -{ - return m_elements.size(); +JSONValue::SP JSONArray::GetObject(Index i) { + if (i < m_elements.size()) + return m_elements[i]; + return JSONValue::SP(); } +JSONArray::Size JSONArray::GetNumElements() { return m_elements.size(); } + +JSONParser::JSONParser(const char *cstr) : StringExtractor(cstr) {} + +JSONParser::Token JSONParser::GetToken(std::string &value) { + StreamString error; + + value.clear(); + SkipSpaces(); + const uint64_t start_index = m_index; + const char ch = GetChar(); + switch (ch) { + case '{': + return Token::ObjectStart; + case '}': + return Token::ObjectEnd; + case '[': + return Token::ArrayStart; + case ']': + return Token::ArrayEnd; + case ',': + return Token::Comma; + case ':': + return Token::Colon; + case '\0': + return Token::EndOfFile; + case 't': + if (GetChar() == 'r') + if (GetChar() == 'u') + if (GetChar() == 'e') + return Token::True; + break; + + case 'f': + if (GetChar() == 'a') + if (GetChar() == 'l') + if (GetChar() == 's') + if (GetChar() == 'e') + return Token::False; + break; + + case 'n': + if (GetChar() == 'u') + if (GetChar() == 'l') + if (GetChar() == 'l') + return Token::Null; + break; + + case '"': { + while (1) { + bool was_escaped = false; + int escaped_ch = GetEscapedChar(was_escaped); + if (escaped_ch == -1) { + error.Printf( + "error: an error occurred getting a character from offset %" PRIu64, + start_index); + value = std::move(error.GetString()); + return Token::Error; + + } else { + const bool is_end_quote = escaped_ch == '"'; + const bool is_null = escaped_ch == 0; + if (was_escaped || (!is_end_quote && !is_null)) { + if (CHAR_MIN <= escaped_ch && escaped_ch <= CHAR_MAX) { + value.append(1, (char)escaped_ch); + } else { + error.Printf("error: wide character support is needed for unicode " + "character 0x%4.4x at offset %" PRIu64, + escaped_ch, start_index); + value = std::move(error.GetString()); + return Token::Error; + } + } else if (is_end_quote) { + return Token::String; + } else if (is_null) { + value = "error: missing end quote for string"; + return Token::Error; + } + } + } + } break; + + case '-': + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': { + bool done = false; + bool got_decimal_point = false; + uint64_t exp_index = 0; + bool got_int_digits = (ch >= '0') && (ch <= '9'); + bool got_frac_digits = false; + bool got_exp_digits = false; + while (!done) { + const char next_ch = PeekChar(); + switch (next_ch) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + if (exp_index != 0) { + got_exp_digits = true; + } else if (got_decimal_point) { + got_frac_digits = true; + } else { + got_int_digits = true; + } + ++m_index; // Skip this character + break; + + case '.': + if (got_decimal_point) { + error.Printf("error: extra decimal point found at offset %" PRIu64, + start_index); + value = std::move(error.GetString()); + return Token::Error; + } else { + got_decimal_point = true; + ++m_index; // Skip this character + } + break; + + case 'e': + case 'E': + if (exp_index != 0) { + error.Printf( + "error: extra exponent character found at offset %" PRIu64, + start_index); + value = std::move(error.GetString()); + return Token::Error; + } else { + exp_index = m_index; + ++m_index; // Skip this character + } + break; + + case '+': + case '-': + // The '+' and '-' can only come after an exponent character... + if (exp_index == m_index - 1) { + ++m_index; // Skip the exponent sign character + } else { + error.Printf("error: unexpected %c character at offset %" PRIu64, + next_ch, start_index); + value = std::move(error.GetString()); + return Token::Error; + } + break; -JSONParser::JSONParser (const char *cstr) : - StringExtractor(cstr) -{ -} - -JSONParser::Token -JSONParser::GetToken (std::string &value) -{ - StreamString error; - - value.clear(); - SkipSpaces (); - const uint64_t start_index = m_index; - const char ch = GetChar(); - switch (ch) - { - case '{': return Token::ObjectStart; - case '}': return Token::ObjectEnd; - case '[': return Token::ArrayStart; - case ']': return Token::ArrayEnd; - case ',': return Token::Comma; - case ':': return Token::Colon; - case '\0': return Token::EndOfFile; - case 't': - if (GetChar() == 'r') - if (GetChar() == 'u') - if (GetChar() == 'e') - return Token::True; - break; - - case 'f': - if (GetChar() == 'a') - if (GetChar() == 'l') - if (GetChar() == 's') - if (GetChar() == 'e') - return Token::False; - break; - - case 'n': - if (GetChar() == 'u') - if (GetChar() == 'l') - if (GetChar() == 'l') - return Token::Null; - break; - - case '"': - { - while (1) - { - bool was_escaped = false; - int escaped_ch = GetEscapedChar(was_escaped); - if (escaped_ch == -1) - { - error.Printf("error: an error occurred getting a character from offset %" PRIu64, start_index); - value = std::move(error.GetString()); - return Token::Error; - - } - else - { - const bool is_end_quote = escaped_ch == '"'; - const bool is_null = escaped_ch == 0; - if (was_escaped || (!is_end_quote && !is_null)) - { - if (CHAR_MIN <= escaped_ch && escaped_ch <= CHAR_MAX) - { - value.append(1, (char)escaped_ch); - } - else - { - error.Printf("error: wide character support is needed for unicode character 0x%4.4x at offset %" PRIu64, escaped_ch, start_index); - value = std::move(error.GetString()); - return Token::Error; - } - } - else if (is_end_quote) - { - return Token::String; - } - else if (is_null) - { - value = "error: missing end quote for string"; - return Token::Error; - } - } - } - } - break; - - case '-': - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - { - bool done = false; - bool got_decimal_point = false; - uint64_t exp_index = 0; - bool got_int_digits = (ch >= '0') && (ch <= '9'); - bool got_frac_digits = false; - bool got_exp_digits = false; - while (!done) - { - const char next_ch = PeekChar(); - switch (next_ch) - { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - if (exp_index != 0) - { - got_exp_digits = true; - } - else if (got_decimal_point) - { - got_frac_digits = true; - } - else - { - got_int_digits = true; - } - ++m_index; // Skip this character - break; - - case '.': - if (got_decimal_point) - { - error.Printf("error: extra decimal point found at offset %" PRIu64, start_index); - value = std::move(error.GetString()); - return Token::Error; - } - else - { - got_decimal_point = true; - ++m_index; // Skip this character - } - break; - - case 'e': - case 'E': - if (exp_index != 0) - { - error.Printf("error: extra exponent character found at offset %" PRIu64, start_index); - value = std::move(error.GetString()); - return Token::Error; - } - else - { - exp_index = m_index; - ++m_index; // Skip this character - } - break; - - case '+': - case '-': - // The '+' and '-' can only come after an exponent character... - if (exp_index == m_index - 1) - { - ++m_index; // Skip the exponent sign character - } - else - { - error.Printf("error: unexpected %c character at offset %" PRIu64, next_ch, start_index); - value = std::move(error.GetString()); - return Token::Error; - } - break; - - default: - done = true; - break; - } - } - - if (m_index > start_index) - { - value = m_packet.substr(start_index, m_index - start_index); - if (got_decimal_point) - { - if (exp_index != 0) - { - // We have an exponent, make sure we got exponent digits - if (got_exp_digits) - { - return Token::Float; - } - else - { - error.Printf("error: got exponent character but no exponent digits at offset in float value \"%s\"", value.c_str()); - value = std::move(error.GetString()); - return Token::Error; - } - } - else - { - // No exponent, but we need at least one decimal after the decimal point - if (got_frac_digits) - { - return Token::Float; - } - else - { - error.Printf("error: no digits after decimal point \"%s\"", value.c_str()); - value = std::move(error.GetString()); - return Token::Error; - } - } - } - else - { - // No decimal point - if (got_int_digits) - { - // We need at least some integer digits to make an integer - return Token::Integer; - } - else - { - error.Printf("error: no digits negate sign \"%s\"", value.c_str()); - value = std::move(error.GetString()); - return Token::Error; - } - } - } - else - { - error.Printf("error: invalid number found at offset %" PRIu64, start_index); - value = std::move(error.GetString()); - return Token::Error; - } - } - break; - default: - break; + default: + done = true; + break; + } } - error.Printf("error: failed to parse token at offset %" PRIu64 " (around character '%c')", start_index, ch); - value = std::move(error.GetString()); - return Token::Error; -} -int -JSONParser::GetEscapedChar(bool &was_escaped) -{ - was_escaped = false; - const char ch = GetChar(); - if (ch == '\\') - { - was_escaped = true; - const char ch2 = GetChar(); - switch (ch2) - { - case '"': - case '\\': - case '/': - default: - break; - - case 'b': return '\b'; - case 'f': return '\f'; - case 'n': return '\n'; - case 'r': return '\r'; - case 't': return '\t'; - case 'u': - { - const int hi_byte = DecodeHexU8(); - const int lo_byte = DecodeHexU8(); - if (hi_byte >=0 && lo_byte >= 0) - return hi_byte << 8 | lo_byte; - return -1; - } - break; + if (m_index > start_index) { + value = m_packet.substr(start_index, m_index - start_index); + if (got_decimal_point) { + if (exp_index != 0) { + // We have an exponent, make sure we got exponent digits + if (got_exp_digits) { + return Token::Float; + } else { + error.Printf("error: got exponent character but no exponent digits " + "at offset in float value \"%s\"", + value.c_str()); + value = std::move(error.GetString()); + return Token::Error; + } + } else { + // No exponent, but we need at least one decimal after the decimal + // point + if (got_frac_digits) { + return Token::Float; + } else { + error.Printf("error: no digits after decimal point \"%s\"", + value.c_str()); + value = std::move(error.GetString()); + return Token::Error; + } + } + } else { + // No decimal point + if (got_int_digits) { + // We need at least some integer digits to make an integer + return Token::Integer; + } else { + error.Printf("error: no digits negate sign \"%s\"", value.c_str()); + value = std::move(error.GetString()); + return Token::Error; } - return ch2; + } + } else { + error.Printf("error: invalid number found at offset %" PRIu64, + start_index); + value = std::move(error.GetString()); + return Token::Error; } - return ch; + } break; + default: + break; + } + error.Printf("error: failed to parse token at offset %" PRIu64 + " (around character '%c')", + start_index, ch); + value = std::move(error.GetString()); + return Token::Error; } -JSONValue::SP -JSONParser::ParseJSONObject () -{ - // The "JSONParser::Token::ObjectStart" token should have already been consumed - // by the time this function is called - std::unique_ptr<JSONObject> dict_up(new JSONObject()); - - std::string value; - std::string key; - while (1) - { - JSONParser::Token token = GetToken(value); - - if (token == JSONParser::Token::String) - { - key.swap(value); - token = GetToken(value); - if (token == JSONParser::Token::Colon) - { - JSONValue::SP value_sp = ParseJSONValue(); - if (value_sp) - dict_up->SetObject(key, value_sp); - else - break; - } - } - else if (token == JSONParser::Token::ObjectEnd) - { - return JSONValue::SP(dict_up.release()); - } - else if (token == JSONParser::Token::Comma) - { - continue; - } - else - { - break; - } +int JSONParser::GetEscapedChar(bool &was_escaped) { + was_escaped = false; + const char ch = GetChar(); + if (ch == '\\') { + was_escaped = true; + const char ch2 = GetChar(); + switch (ch2) { + case '"': + case '\\': + case '/': + default: + break; + + case 'b': + return '\b'; + case 'f': + return '\f'; + case 'n': + return '\n'; + case 'r': + return '\r'; + case 't': + return '\t'; + case 'u': { + const int hi_byte = DecodeHexU8(); + const int lo_byte = DecodeHexU8(); + if (hi_byte >= 0 && lo_byte >= 0) + return hi_byte << 8 | lo_byte; + return -1; + } break; } - return JSONValue::SP(); + return ch2; + } + return ch; } -JSONValue::SP -JSONParser::ParseJSONArray () -{ - // The "JSONParser::Token::ObjectStart" token should have already been consumed - // by the time this function is called - std::unique_ptr<JSONArray> array_up(new JSONArray()); - - std::string value; - std::string key; - while (1) - { +JSONValue::SP JSONParser::ParseJSONObject() { + // The "JSONParser::Token::ObjectStart" token should have already been + // consumed + // by the time this function is called + std::unique_ptr<JSONObject> dict_up(new JSONObject()); + + std::string value; + std::string key; + while (1) { + JSONParser::Token token = GetToken(value); + + if (token == JSONParser::Token::String) { + key.swap(value); + token = GetToken(value); + if (token == JSONParser::Token::Colon) { JSONValue::SP value_sp = ParseJSONValue(); if (value_sp) - array_up->AppendObject(value_sp); + dict_up->SetObject(key, value_sp); else - break; + break; + } + } else if (token == JSONParser::Token::ObjectEnd) { + return JSONValue::SP(dict_up.release()); + } else if (token == JSONParser::Token::Comma) { + continue; + } else { + break; + } + } + return JSONValue::SP(); +} - JSONParser::Token token = GetToken(value); - if (token == JSONParser::Token::Comma) - { - continue; - } - else if (token == JSONParser::Token::ArrayEnd) - { - return JSONValue::SP(array_up.release()); - } - else - { - break; - } +JSONValue::SP JSONParser::ParseJSONArray() { + // The "JSONParser::Token::ObjectStart" token should have already been + // consumed + // by the time this function is called + std::unique_ptr<JSONArray> array_up(new JSONArray()); + + std::string value; + std::string key; + while (1) { + JSONValue::SP value_sp = ParseJSONValue(); + if (value_sp) + array_up->AppendObject(value_sp); + else + break; + + JSONParser::Token token = GetToken(value); + if (token == JSONParser::Token::Comma) { + continue; + } else if (token == JSONParser::Token::ArrayEnd) { + return JSONValue::SP(array_up.release()); + } else { + break; } - return JSONValue::SP(); + } + return JSONValue::SP(); } -JSONValue::SP -JSONParser::ParseJSONValue () -{ - std::string value; - const JSONParser::Token token = GetToken(value); - switch (token) - { - case JSONParser::Token::ObjectStart: - return ParseJSONObject(); - - case JSONParser::Token::ArrayStart: - return ParseJSONArray(); - - case JSONParser::Token::Integer: - { - if (value.front() == '-') - { - bool success = false; - int64_t sval = StringConvert::ToSInt64(value.c_str(), 0, 0, &success); - if (success) - return JSONValue::SP(new JSONNumber(sval)); - } - else - { - bool success = false; - uint64_t uval = StringConvert::ToUInt64(value.c_str(), 0, 0, &success); - if (success) - return JSONValue::SP(new JSONNumber(uval)); - } - } - break; - - case JSONParser::Token::Float: - { - bool success = false; - double val = StringConvert::ToDouble(value.c_str(), 0.0, &success); - if (success) - return JSONValue::SP(new JSONNumber(val)); - } - break; +JSONValue::SP JSONParser::ParseJSONValue() { + std::string value; + const JSONParser::Token token = GetToken(value); + switch (token) { + case JSONParser::Token::ObjectStart: + return ParseJSONObject(); + + case JSONParser::Token::ArrayStart: + return ParseJSONArray(); + + case JSONParser::Token::Integer: { + if (value.front() == '-') { + bool success = false; + int64_t sval = StringConvert::ToSInt64(value.c_str(), 0, 0, &success); + if (success) + return JSONValue::SP(new JSONNumber(sval)); + } else { + bool success = false; + uint64_t uval = StringConvert::ToUInt64(value.c_str(), 0, 0, &success); + if (success) + return JSONValue::SP(new JSONNumber(uval)); + } + } break; - case JSONParser::Token::String: - return JSONValue::SP(new JSONString(value)); + case JSONParser::Token::Float: { + bool success = false; + double val = StringConvert::ToDouble(value.c_str(), 0.0, &success); + if (success) + return JSONValue::SP(new JSONNumber(val)); + } break; - case JSONParser::Token::True: - return JSONValue::SP(new JSONTrue()); + case JSONParser::Token::String: + return JSONValue::SP(new JSONString(value)); - case JSONParser::Token::False: - return JSONValue::SP(new JSONFalse()); + case JSONParser::Token::True: + return JSONValue::SP(new JSONTrue()); - case JSONParser::Token::Null: - return JSONValue::SP(new JSONNull()); + case JSONParser::Token::False: + return JSONValue::SP(new JSONFalse()); - default: - break; - } - return JSONValue::SP(); - + case JSONParser::Token::Null: + return JSONValue::SP(new JSONNull()); + + default: + break; + } + return JSONValue::SP(); } diff --git a/lldb/source/Utility/KQueue.cpp b/lldb/source/Utility/KQueue.cpp index c0aace4..56c0d1b 100644 --- a/lldb/source/Utility/KQueue.cpp +++ b/lldb/source/Utility/KQueue.cpp @@ -17,71 +17,60 @@ using namespace lldb_private; -int -KQueue::GetFD (bool can_create) -{ - if (!IsValid () && can_create) - m_fd = kqueue(); - return m_fd; +int KQueue::GetFD(bool can_create) { + if (!IsValid() && can_create) + m_fd = kqueue(); + return m_fd; } -int -KQueue::Close () -{ - const int fd = m_fd; - if (fd >= 0) - { - m_fd = -1; - return close(fd); - } - return 0; +int KQueue::Close() { + const int fd = m_fd; + if (fd >= 0) { + m_fd = -1; + return close(fd); + } + return 0; } -int -KQueue::WaitForEvents (struct kevent *events, int num_events, Error &error, uint32_t timeout_usec) -{ - const int fd_kqueue = GetFD(false); - if (fd_kqueue >= 0) - { - TimeSpecTimeout timeout; - const struct timespec *timeout_ptr = timeout.SetRelativeTimeoutMircoSeconds32 (timeout_usec); - int result = ::kevent(fd_kqueue, NULL, 0, events, num_events, timeout_ptr); - if (result == -1) - error.SetErrorToErrno(); - else - error.Clear(); - return result; - } +int KQueue::WaitForEvents(struct kevent *events, int num_events, Error &error, + uint32_t timeout_usec) { + const int fd_kqueue = GetFD(false); + if (fd_kqueue >= 0) { + TimeSpecTimeout timeout; + const struct timespec *timeout_ptr = + timeout.SetRelativeTimeoutMircoSeconds32(timeout_usec); + int result = ::kevent(fd_kqueue, NULL, 0, events, num_events, timeout_ptr); + if (result == -1) + error.SetErrorToErrno(); else - { - error.SetErrorString("invalid kqueue fd"); - } - return 0; + error.Clear(); + return result; + } else { + error.SetErrorString("invalid kqueue fd"); + } + return 0; } -bool -KQueue::AddFDEvent (int fd, bool read, bool write, bool vnode) -{ - const int fd_kqueue = GetFD(true); - if (fd_kqueue >= 0) - { - struct kevent event; - event.ident = fd; - event.filter = 0; - if (read) - event.filter |= EVFILT_READ; - if (write) - event.filter |= EVFILT_WRITE; - if (vnode) - event.filter |= EVFILT_VNODE; - event.flags = EV_ADD | EV_CLEAR; - event.fflags = 0; - event.data = 0; - event.udata = NULL; - int err = ::kevent(fd_kqueue, &event, 1, NULL, 0, NULL); - return err == 0; - } - return false; +bool KQueue::AddFDEvent(int fd, bool read, bool write, bool vnode) { + const int fd_kqueue = GetFD(true); + if (fd_kqueue >= 0) { + struct kevent event; + event.ident = fd; + event.filter = 0; + if (read) + event.filter |= EVFILT_READ; + if (write) + event.filter |= EVFILT_WRITE; + if (vnode) + event.filter |= EVFILT_VNODE; + event.flags = EV_ADD | EV_CLEAR; + event.fflags = 0; + event.data = 0; + event.udata = NULL; + int err = ::kevent(fd_kqueue, &event, 1, NULL, 0, NULL); + return err == 0; + } + return false; } #endif diff --git a/lldb/source/Utility/KQueue.h b/lldb/source/Utility/KQueue.h index c5680aa..116e701 100644 --- a/lldb/source/Utility/KQueue.h +++ b/lldb/source/Utility/KQueue.h @@ -16,53 +16,34 @@ #ifdef LLDB_USE_KQUEUES -#include <sys/types.h> #include <sys/event.h> #include <sys/time.h> +#include <sys/types.h> #include "lldb/lldb-defines.h" namespace lldb_private { -class KQueue -{ +class KQueue { public: - KQueue() : - m_fd(-1) - { - } - - ~KQueue() - { - Close(); - } - - bool - IsValid () const - { - return m_fd >= 0; - } - - int - GetFD (bool can_create); - - int - Close (); - - bool - AddFDEvent (int fd, - bool read, - bool write, - bool vnode); - - int - WaitForEvents (struct kevent *events, - int num_events, - Error &error, - uint32_t timeout_usec = UINT32_MAX); // UINT32_MAX means infinite timeout + KQueue() : m_fd(-1) {} + + ~KQueue() { Close(); } + + bool IsValid() const { return m_fd >= 0; } + + int GetFD(bool can_create); + + int Close(); + + bool AddFDEvent(int fd, bool read, bool write, bool vnode); + + int WaitForEvents( + struct kevent *events, int num_events, Error &error, + uint32_t timeout_usec = UINT32_MAX); // UINT32_MAX means infinite timeout protected: - int m_fd; // The kqueue fd + int m_fd; // The kqueue fd }; } // namespace lldb_private diff --git a/lldb/source/Utility/LLDBAssert.cpp b/lldb/source/Utility/LLDBAssert.cpp index 68aa872..6f35dcd 100644 --- a/lldb/source/Utility/LLDBAssert.cpp +++ b/lldb/source/Utility/LLDBAssert.cpp @@ -1,4 +1,5 @@ -//===--------------------- LLDBAssert.cpp --------------------------*- C++ -*-===// +//===--------------------- LLDBAssert.cpp --------------------------*- C++ +//-*-===// // // The LLVM Compiler Infrastructure // @@ -10,27 +11,23 @@ #include "lldb/Utility/LLDBAssert.h" #include "llvm/Support/Format.h" -#include "llvm/Support/raw_ostream.h" #include "llvm/Support/Signals.h" +#include "llvm/Support/raw_ostream.h" using namespace llvm; using namespace lldb_private; -void -lldb_private::lldb_assert (bool expression, - const char* expr_text, - const char* func, - const char* file, - unsigned int line) -{ - if (expression) - ; - else - { - errs() << format("Assertion failed: (%s), function %s, file %s, line %u\n", - expr_text, func, file, line); - errs() << "backtrace leading to the failure:\n"; - llvm::sys::PrintStackTrace(errs()); - errs() << "please file a bug report against lldb reporting this failure log, and as many details as possible\n"; - } +void lldb_private::lldb_assert(bool expression, const char *expr_text, + const char *func, const char *file, + unsigned int line) { + if (expression) + ; + else { + errs() << format("Assertion failed: (%s), function %s, file %s, line %u\n", + expr_text, func, file, line); + errs() << "backtrace leading to the failure:\n"; + llvm::sys::PrintStackTrace(errs()); + errs() << "please file a bug report against lldb reporting this failure " + "log, and as many details as possible\n"; + } } diff --git a/lldb/source/Utility/ModuleCache.cpp b/lldb/source/Utility/ModuleCache.cpp index aa55880..bf76db9 100644 --- a/lldb/source/Utility/ModuleCache.cpp +++ b/lldb/source/Utility/ModuleCache.cpp @@ -28,311 +28,309 @@ using namespace lldb_private; namespace { -const char* kModulesSubdir = ".cache"; -const char* kLockDirName = ".lock"; -const char* kTempFileName = ".temp"; -const char* kTempSymFileName = ".symtemp"; -const char* kSymFileExtension = ".sym"; -const char* kFSIllegalChars = "\\/:*?\"<>|"; - -std::string -GetEscapedHostname(const char* hostname) -{ - std::string result(hostname); - size_t size = result.size(); - for (size_t i = 0; i < size; ++i) - { - if ((result[i] >=1 && result[i] <= 31) || - strchr(kFSIllegalChars, result[i]) != nullptr) - result[i] = '_'; - } - return result; +const char *kModulesSubdir = ".cache"; +const char *kLockDirName = ".lock"; +const char *kTempFileName = ".temp"; +const char *kTempSymFileName = ".symtemp"; +const char *kSymFileExtension = ".sym"; +const char *kFSIllegalChars = "\\/:*?\"<>|"; + +std::string GetEscapedHostname(const char *hostname) { + std::string result(hostname); + size_t size = result.size(); + for (size_t i = 0; i < size; ++i) { + if ((result[i] >= 1 && result[i] <= 31) || + strchr(kFSIllegalChars, result[i]) != nullptr) + result[i] = '_'; + } + return result; } -class ModuleLock -{ +class ModuleLock { private: - File m_file; - std::unique_ptr<lldb_private::LockFile> m_lock; - FileSpec m_file_spec; + File m_file; + std::unique_ptr<lldb_private::LockFile> m_lock; + FileSpec m_file_spec; public: - ModuleLock (const FileSpec &root_dir_spec, const UUID &uuid, Error& error); - void Delete (); + ModuleLock(const FileSpec &root_dir_spec, const UUID &uuid, Error &error); + void Delete(); }; -FileSpec -JoinPath (const FileSpec &path1, const char* path2) -{ - FileSpec result_spec (path1); - result_spec.AppendPathComponent (path2); - return result_spec; +FileSpec JoinPath(const FileSpec &path1, const char *path2) { + FileSpec result_spec(path1); + result_spec.AppendPathComponent(path2); + return result_spec; } -Error -MakeDirectory (const FileSpec &dir_path) -{ - if (dir_path.Exists ()) - { - if (!dir_path.IsDirectory ()) - return Error ("Invalid existing path"); +Error MakeDirectory(const FileSpec &dir_path) { + if (dir_path.Exists()) { + if (!dir_path.IsDirectory()) + return Error("Invalid existing path"); - return Error (); - } + return Error(); + } - return FileSystem::MakeDirectory(dir_path, eFilePermissionsDirectoryDefault); + return FileSystem::MakeDirectory(dir_path, eFilePermissionsDirectoryDefault); } -FileSpec -GetModuleDirectory (const FileSpec &root_dir_spec, const UUID &uuid) -{ - const auto modules_dir_spec = JoinPath (root_dir_spec, kModulesSubdir); - return JoinPath (modules_dir_spec, uuid.GetAsString ().c_str ()); +FileSpec GetModuleDirectory(const FileSpec &root_dir_spec, const UUID &uuid) { + const auto modules_dir_spec = JoinPath(root_dir_spec, kModulesSubdir); + return JoinPath(modules_dir_spec, uuid.GetAsString().c_str()); } -FileSpec -GetSymbolFileSpec(const FileSpec& module_file_spec) -{ - return FileSpec((module_file_spec.GetPath() + kSymFileExtension).c_str(), false); +FileSpec GetSymbolFileSpec(const FileSpec &module_file_spec) { + return FileSpec((module_file_spec.GetPath() + kSymFileExtension).c_str(), + false); } -void -DeleteExistingModule (const FileSpec &root_dir_spec, const FileSpec &sysroot_module_path_spec) -{ - Log *log (GetLogIfAllCategoriesSet (LIBLLDB_LOG_MODULES)); - UUID module_uuid; - { - auto module_sp = std::make_shared<Module>(ModuleSpec (sysroot_module_path_spec)); - module_uuid = module_sp->GetUUID (); - } - - if (!module_uuid.IsValid ()) - return; - - Error error; - ModuleLock lock (root_dir_spec, module_uuid, error); - if (error.Fail ()) - { - if (log) - log->Printf ("Failed to lock module %s: %s", - module_uuid.GetAsString ().c_str (), - error.AsCString ()); - } - - auto link_count = FileSystem::GetHardlinkCount (sysroot_module_path_spec); - if (link_count == -1) - return; - - if (link_count > 2) // module is referred by other hosts. - return; - - const auto module_spec_dir = GetModuleDirectory (root_dir_spec, module_uuid); - FileSystem::DeleteDirectory (module_spec_dir, true); - lock.Delete(); +void DeleteExistingModule(const FileSpec &root_dir_spec, + const FileSpec &sysroot_module_path_spec) { + Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_MODULES)); + UUID module_uuid; + { + auto module_sp = + std::make_shared<Module>(ModuleSpec(sysroot_module_path_spec)); + module_uuid = module_sp->GetUUID(); + } + + if (!module_uuid.IsValid()) + return; + + Error error; + ModuleLock lock(root_dir_spec, module_uuid, error); + if (error.Fail()) { + if (log) + log->Printf("Failed to lock module %s: %s", + module_uuid.GetAsString().c_str(), error.AsCString()); + } + + auto link_count = FileSystem::GetHardlinkCount(sysroot_module_path_spec); + if (link_count == -1) + return; + + if (link_count > 2) // module is referred by other hosts. + return; + + const auto module_spec_dir = GetModuleDirectory(root_dir_spec, module_uuid); + FileSystem::DeleteDirectory(module_spec_dir, true); + lock.Delete(); } -void -DecrementRefExistingModule (const FileSpec &root_dir_spec, const FileSpec &sysroot_module_path_spec) -{ - // Remove $platform/.cache/$uuid folder if nobody else references it. - DeleteExistingModule (root_dir_spec, sysroot_module_path_spec); +void DecrementRefExistingModule(const FileSpec &root_dir_spec, + const FileSpec &sysroot_module_path_spec) { + // Remove $platform/.cache/$uuid folder if nobody else references it. + DeleteExistingModule(root_dir_spec, sysroot_module_path_spec); - // Remove sysroot link. - FileSystem::Unlink (sysroot_module_path_spec); + // Remove sysroot link. + FileSystem::Unlink(sysroot_module_path_spec); - FileSpec symfile_spec = GetSymbolFileSpec (sysroot_module_path_spec); - if (symfile_spec.Exists ()) // delete module's symbol file if exists. - FileSystem::Unlink (symfile_spec); + FileSpec symfile_spec = GetSymbolFileSpec(sysroot_module_path_spec); + if (symfile_spec.Exists()) // delete module's symbol file if exists. + FileSystem::Unlink(symfile_spec); } -Error -CreateHostSysRootModuleLink (const FileSpec &root_dir_spec, const char *hostname, - const FileSpec &platform_module_spec, - const FileSpec &local_module_spec, - bool delete_existing) -{ - const auto sysroot_module_path_spec = JoinPath ( - JoinPath (root_dir_spec, hostname), platform_module_spec.GetPath ().c_str ()); - if (sysroot_module_path_spec.Exists()) - { - if (!delete_existing) - return Error (); - - DecrementRefExistingModule (root_dir_spec, sysroot_module_path_spec); - } - - const auto error = MakeDirectory (FileSpec (sysroot_module_path_spec.GetDirectory ().AsCString (), false)); - if (error.Fail ()) - return error; - - return FileSystem::Hardlink(sysroot_module_path_spec, local_module_spec); +Error CreateHostSysRootModuleLink(const FileSpec &root_dir_spec, + const char *hostname, + const FileSpec &platform_module_spec, + const FileSpec &local_module_spec, + bool delete_existing) { + const auto sysroot_module_path_spec = + JoinPath(JoinPath(root_dir_spec, hostname), + platform_module_spec.GetPath().c_str()); + if (sysroot_module_path_spec.Exists()) { + if (!delete_existing) + return Error(); + + DecrementRefExistingModule(root_dir_spec, sysroot_module_path_spec); + } + + const auto error = MakeDirectory( + FileSpec(sysroot_module_path_spec.GetDirectory().AsCString(), false)); + if (error.Fail()) + return error; + + return FileSystem::Hardlink(sysroot_module_path_spec, local_module_spec); } -} // namespace - -ModuleLock::ModuleLock (const FileSpec &root_dir_spec, const UUID &uuid, Error& error) -{ - const auto lock_dir_spec = JoinPath (root_dir_spec, kLockDirName); - error = MakeDirectory (lock_dir_spec); - if (error.Fail ()) - return; - - m_file_spec = JoinPath (lock_dir_spec, uuid.GetAsString ().c_str ()); - m_file.Open (m_file_spec.GetCString (), - File::eOpenOptionWrite | File::eOpenOptionCanCreate | File::eOpenOptionCloseOnExec); - if (!m_file) - { - error.SetErrorToErrno (); - return; - } - - m_lock.reset (new lldb_private::LockFile (m_file.GetDescriptor ())); - error = m_lock->WriteLock (0, 1); - if (error.Fail ()) - error.SetErrorStringWithFormat ("Failed to lock file: %s", error.AsCString ()); +} // namespace + +ModuleLock::ModuleLock(const FileSpec &root_dir_spec, const UUID &uuid, + Error &error) { + const auto lock_dir_spec = JoinPath(root_dir_spec, kLockDirName); + error = MakeDirectory(lock_dir_spec); + if (error.Fail()) + return; + + m_file_spec = JoinPath(lock_dir_spec, uuid.GetAsString().c_str()); + m_file.Open(m_file_spec.GetCString(), File::eOpenOptionWrite | + File::eOpenOptionCanCreate | + File::eOpenOptionCloseOnExec); + if (!m_file) { + error.SetErrorToErrno(); + return; + } + + m_lock.reset(new lldb_private::LockFile(m_file.GetDescriptor())); + error = m_lock->WriteLock(0, 1); + if (error.Fail()) + error.SetErrorStringWithFormat("Failed to lock file: %s", + error.AsCString()); } -void ModuleLock::Delete () -{ - if (!m_file) - return; +void ModuleLock::Delete() { + if (!m_file) + return; - m_file.Close (); - FileSystem::Unlink (m_file_spec); + m_file.Close(); + FileSystem::Unlink(m_file_spec); } ///////////////////////////////////////////////////////////////////////// -Error -ModuleCache::Put (const FileSpec &root_dir_spec, - const char *hostname, - const ModuleSpec &module_spec, - const FileSpec &tmp_file, - const FileSpec &target_file) -{ - const auto module_spec_dir = GetModuleDirectory (root_dir_spec, module_spec.GetUUID ()); - const auto module_file_path = JoinPath (module_spec_dir, target_file.GetFilename ().AsCString ()); - - const auto tmp_file_path = tmp_file.GetPath (); - const auto err_code = llvm::sys::fs::rename (tmp_file_path.c_str (), module_file_path.GetPath ().c_str ()); - if (err_code) - return Error ("Failed to rename file %s to %s: %s", - tmp_file_path.c_str (), module_file_path.GetPath ().c_str (), err_code.message ().c_str ()); - - const auto error = CreateHostSysRootModuleLink(root_dir_spec, hostname, target_file, module_file_path, true); - if (error.Fail ()) - return Error ("Failed to create link to %s: %s", module_file_path.GetPath ().c_str (), error.AsCString ()); - return Error (); +Error ModuleCache::Put(const FileSpec &root_dir_spec, const char *hostname, + const ModuleSpec &module_spec, const FileSpec &tmp_file, + const FileSpec &target_file) { + const auto module_spec_dir = + GetModuleDirectory(root_dir_spec, module_spec.GetUUID()); + const auto module_file_path = + JoinPath(module_spec_dir, target_file.GetFilename().AsCString()); + + const auto tmp_file_path = tmp_file.GetPath(); + const auto err_code = llvm::sys::fs::rename( + tmp_file_path.c_str(), module_file_path.GetPath().c_str()); + if (err_code) + return Error("Failed to rename file %s to %s: %s", tmp_file_path.c_str(), + module_file_path.GetPath().c_str(), + err_code.message().c_str()); + + const auto error = CreateHostSysRootModuleLink( + root_dir_spec, hostname, target_file, module_file_path, true); + if (error.Fail()) + return Error("Failed to create link to %s: %s", + module_file_path.GetPath().c_str(), error.AsCString()); + return Error(); } -Error -ModuleCache::Get (const FileSpec &root_dir_spec, - const char *hostname, - const ModuleSpec &module_spec, - ModuleSP &cached_module_sp, - bool *did_create_ptr) -{ - const auto find_it = m_loaded_modules.find (module_spec.GetUUID ().GetAsString()); - if (find_it != m_loaded_modules.end ()) - { - cached_module_sp = (*find_it).second.lock (); - if (cached_module_sp) - return Error (); - m_loaded_modules.erase (find_it); - } - - const auto module_spec_dir = GetModuleDirectory (root_dir_spec, module_spec.GetUUID ()); - const auto module_file_path = JoinPath (module_spec_dir, module_spec.GetFileSpec ().GetFilename ().AsCString ()); - - if (!module_file_path.Exists ()) - return Error ("Module %s not found", module_file_path.GetPath ().c_str ()); - if (module_file_path.GetByteSize () != module_spec.GetObjectSize ()) - return Error ("Module %s has invalid file size", module_file_path.GetPath ().c_str ()); - - // We may have already cached module but downloaded from an another host - in this case let's create a link to it. - auto error = CreateHostSysRootModuleLink(root_dir_spec, hostname, module_spec.GetFileSpec(), module_file_path, false); - if (error.Fail ()) - return Error ("Failed to create link to %s: %s", module_file_path.GetPath().c_str(), error.AsCString()); - - auto cached_module_spec (module_spec); - cached_module_spec.GetUUID ().Clear (); // Clear UUID since it may contain md5 content hash instead of real UUID. - cached_module_spec.GetFileSpec () = module_file_path; - cached_module_spec.GetPlatformFileSpec () = module_spec.GetFileSpec (); - - error = ModuleList::GetSharedModule(cached_module_spec, - cached_module_sp, - nullptr, - nullptr, - did_create_ptr, - false); - if (error.Fail()) - return error; - - FileSpec symfile_spec = GetSymbolFileSpec(cached_module_sp->GetFileSpec ()); - if (symfile_spec.Exists ()) - cached_module_sp->SetSymbolFileFileSpec (symfile_spec); - - m_loaded_modules.insert (std::make_pair (module_spec.GetUUID ().GetAsString (), cached_module_sp)); - - return Error (); +Error ModuleCache::Get(const FileSpec &root_dir_spec, const char *hostname, + const ModuleSpec &module_spec, + ModuleSP &cached_module_sp, bool *did_create_ptr) { + const auto find_it = + m_loaded_modules.find(module_spec.GetUUID().GetAsString()); + if (find_it != m_loaded_modules.end()) { + cached_module_sp = (*find_it).second.lock(); + if (cached_module_sp) + return Error(); + m_loaded_modules.erase(find_it); + } + + const auto module_spec_dir = + GetModuleDirectory(root_dir_spec, module_spec.GetUUID()); + const auto module_file_path = JoinPath( + module_spec_dir, module_spec.GetFileSpec().GetFilename().AsCString()); + + if (!module_file_path.Exists()) + return Error("Module %s not found", module_file_path.GetPath().c_str()); + if (module_file_path.GetByteSize() != module_spec.GetObjectSize()) + return Error("Module %s has invalid file size", + module_file_path.GetPath().c_str()); + + // We may have already cached module but downloaded from an another host - in + // this case let's create a link to it. + auto error = CreateHostSysRootModuleLink(root_dir_spec, hostname, + module_spec.GetFileSpec(), + module_file_path, false); + if (error.Fail()) + return Error("Failed to create link to %s: %s", + module_file_path.GetPath().c_str(), error.AsCString()); + + auto cached_module_spec(module_spec); + cached_module_spec.GetUUID().Clear(); // Clear UUID since it may contain md5 + // content hash instead of real UUID. + cached_module_spec.GetFileSpec() = module_file_path; + cached_module_spec.GetPlatformFileSpec() = module_spec.GetFileSpec(); + + error = ModuleList::GetSharedModule(cached_module_spec, cached_module_sp, + nullptr, nullptr, did_create_ptr, false); + if (error.Fail()) + return error; + + FileSpec symfile_spec = GetSymbolFileSpec(cached_module_sp->GetFileSpec()); + if (symfile_spec.Exists()) + cached_module_sp->SetSymbolFileFileSpec(symfile_spec); + + m_loaded_modules.insert( + std::make_pair(module_spec.GetUUID().GetAsString(), cached_module_sp)); + + return Error(); } -Error -ModuleCache::GetAndPut (const FileSpec &root_dir_spec, - const char *hostname, - const ModuleSpec &module_spec, - const ModuleDownloader &module_downloader, - const SymfileDownloader &symfile_downloader, - lldb::ModuleSP &cached_module_sp, - bool *did_create_ptr) -{ - const auto module_spec_dir = GetModuleDirectory (root_dir_spec, module_spec.GetUUID ()); - auto error = MakeDirectory (module_spec_dir); - if (error.Fail ()) - return error; - - ModuleLock lock (root_dir_spec, module_spec.GetUUID (), error); - if (error.Fail ()) - return Error("Failed to lock module %s: %s", module_spec.GetUUID ().GetAsString().c_str(), error.AsCString ()); - - const auto escaped_hostname(GetEscapedHostname(hostname)); - // Check local cache for a module. - error = Get (root_dir_spec, escaped_hostname.c_str(), module_spec, cached_module_sp, did_create_ptr); - if (error.Success ()) - return error; - - const auto tmp_download_file_spec = JoinPath (module_spec_dir, kTempFileName); - error = module_downloader (module_spec, tmp_download_file_spec); - llvm::FileRemover tmp_file_remover (tmp_download_file_spec.GetPath ().c_str ()); - if (error.Fail ()) - return Error("Failed to download module: %s", error.AsCString ()); - - // Put downloaded file into local module cache. - error = Put (root_dir_spec, escaped_hostname.c_str(), module_spec, tmp_download_file_spec, module_spec.GetFileSpec ()); - if (error.Fail ()) - return Error ("Failed to put module into cache: %s", error.AsCString ()); - - tmp_file_remover.releaseFile (); - error = Get (root_dir_spec, escaped_hostname.c_str(), module_spec, cached_module_sp, did_create_ptr); - if (error.Fail ()) - return error; - - // Fetching a symbol file for the module - const auto tmp_download_sym_file_spec = JoinPath (module_spec_dir, kTempSymFileName); - error = symfile_downloader (cached_module_sp, tmp_download_sym_file_spec); - llvm::FileRemover tmp_symfile_remover (tmp_download_sym_file_spec.GetPath ().c_str ()); - if (error.Fail ()) - // Failed to download a symfile but fetching the module was successful. The module might - // contain the necessary symbols and the debugging is also possible without a symfile. - return Error (); - - error = Put (root_dir_spec, escaped_hostname.c_str(), module_spec, tmp_download_sym_file_spec, GetSymbolFileSpec(module_spec.GetFileSpec ())); - if (error.Fail ()) - return Error ("Failed to put symbol file into cache: %s", error.AsCString ()); - - tmp_symfile_remover.releaseFile(); - - FileSpec symfile_spec = GetSymbolFileSpec (cached_module_sp->GetFileSpec ()); - cached_module_sp->SetSymbolFileFileSpec (symfile_spec); - return Error (); +Error ModuleCache::GetAndPut(const FileSpec &root_dir_spec, + const char *hostname, + const ModuleSpec &module_spec, + const ModuleDownloader &module_downloader, + const SymfileDownloader &symfile_downloader, + lldb::ModuleSP &cached_module_sp, + bool *did_create_ptr) { + const auto module_spec_dir = + GetModuleDirectory(root_dir_spec, module_spec.GetUUID()); + auto error = MakeDirectory(module_spec_dir); + if (error.Fail()) + return error; + + ModuleLock lock(root_dir_spec, module_spec.GetUUID(), error); + if (error.Fail()) + return Error("Failed to lock module %s: %s", + module_spec.GetUUID().GetAsString().c_str(), + error.AsCString()); + + const auto escaped_hostname(GetEscapedHostname(hostname)); + // Check local cache for a module. + error = Get(root_dir_spec, escaped_hostname.c_str(), module_spec, + cached_module_sp, did_create_ptr); + if (error.Success()) + return error; + + const auto tmp_download_file_spec = JoinPath(module_spec_dir, kTempFileName); + error = module_downloader(module_spec, tmp_download_file_spec); + llvm::FileRemover tmp_file_remover(tmp_download_file_spec.GetPath().c_str()); + if (error.Fail()) + return Error("Failed to download module: %s", error.AsCString()); + + // Put downloaded file into local module cache. + error = Put(root_dir_spec, escaped_hostname.c_str(), module_spec, + tmp_download_file_spec, module_spec.GetFileSpec()); + if (error.Fail()) + return Error("Failed to put module into cache: %s", error.AsCString()); + + tmp_file_remover.releaseFile(); + error = Get(root_dir_spec, escaped_hostname.c_str(), module_spec, + cached_module_sp, did_create_ptr); + if (error.Fail()) + return error; + + // Fetching a symbol file for the module + const auto tmp_download_sym_file_spec = + JoinPath(module_spec_dir, kTempSymFileName); + error = symfile_downloader(cached_module_sp, tmp_download_sym_file_spec); + llvm::FileRemover tmp_symfile_remover( + tmp_download_sym_file_spec.GetPath().c_str()); + if (error.Fail()) + // Failed to download a symfile but fetching the module was successful. The + // module might + // contain the necessary symbols and the debugging is also possible without + // a symfile. + return Error(); + + error = Put(root_dir_spec, escaped_hostname.c_str(), module_spec, + tmp_download_sym_file_spec, + GetSymbolFileSpec(module_spec.GetFileSpec())); + if (error.Fail()) + return Error("Failed to put symbol file into cache: %s", error.AsCString()); + + tmp_symfile_remover.releaseFile(); + + FileSpec symfile_spec = GetSymbolFileSpec(cached_module_sp->GetFileSpec()); + cached_module_sp->SetSymbolFileFileSpec(symfile_spec); + return Error(); } diff --git a/lldb/source/Utility/ModuleCache.h b/lldb/source/Utility/ModuleCache.h index bb9b308..6faa5ff 100644 --- a/lldb/source/Utility/ModuleCache.h +++ b/lldb/source/Utility/ModuleCache.h @@ -10,8 +10,8 @@ #ifndef utility_ModuleCache_h_ #define utility_ModuleCache_h_ -#include "lldb/lldb-types.h" #include "lldb/lldb-forward.h" +#include "lldb/lldb-types.h" #include "lldb/Core/Error.h" #include "lldb/Host/File.h" @@ -32,50 +32,45 @@ class UUID; /// /// Caches locally modules that are downloaded from remote targets. /// Each cached module maintains 2 views: -/// - UUID view: /${CACHE_ROOT}/${PLATFORM_NAME}/.cache/${UUID}/${MODULE_FILENAME} -/// - Sysroot view: /${CACHE_ROOT}/${PLATFORM_NAME}/${HOSTNAME}/${MODULE_FULL_FILEPATH} +/// - UUID view: +/// /${CACHE_ROOT}/${PLATFORM_NAME}/.cache/${UUID}/${MODULE_FILENAME} +/// - Sysroot view: +/// /${CACHE_ROOT}/${PLATFORM_NAME}/${HOSTNAME}/${MODULE_FULL_FILEPATH} /// /// UUID views stores a real module file, whereas Sysroot view holds a symbolic /// link to UUID-view file. /// /// Example: -/// UUID view : /tmp/lldb/remote-linux/.cache/30C94DC6-6A1F-E951-80C3-D68D2B89E576-D5AE213C/libc.so.6 +/// UUID view : +/// /tmp/lldb/remote-linux/.cache/30C94DC6-6A1F-E951-80C3-D68D2B89E576-D5AE213C/libc.so.6 /// Sysroot view: /tmp/lldb/remote-linux/ubuntu/lib/x86_64-linux-gnu/libc.so.6 //---------------------------------------------------------------------- -class ModuleCache -{ +class ModuleCache { public: - using ModuleDownloader = std::function<Error (const ModuleSpec&, const FileSpec&)>; - using SymfileDownloader = std::function<Error (const lldb::ModuleSP&, const FileSpec&)>; + using ModuleDownloader = + std::function<Error(const ModuleSpec &, const FileSpec &)>; + using SymfileDownloader = + std::function<Error(const lldb::ModuleSP &, const FileSpec &)>; - Error - GetAndPut(const FileSpec &root_dir_spec, - const char *hostname, - const ModuleSpec &module_spec, - const ModuleDownloader &module_downloader, - const SymfileDownloader &symfile_downloader, - lldb::ModuleSP &cached_module_sp, - bool *did_create_ptr); + Error GetAndPut(const FileSpec &root_dir_spec, const char *hostname, + const ModuleSpec &module_spec, + const ModuleDownloader &module_downloader, + const SymfileDownloader &symfile_downloader, + lldb::ModuleSP &cached_module_sp, bool *did_create_ptr); private: - Error - Put (const FileSpec &root_dir_spec, - const char *hostname, - const ModuleSpec &module_spec, - const FileSpec &tmp_file, - const FileSpec &target_file); + Error Put(const FileSpec &root_dir_spec, const char *hostname, + const ModuleSpec &module_spec, const FileSpec &tmp_file, + const FileSpec &target_file); - Error - Get (const FileSpec &root_dir_spec, - const char *hostname, - const ModuleSpec &module_spec, - lldb::ModuleSP &cached_module_sp, - bool *did_create_ptr); + Error Get(const FileSpec &root_dir_spec, const char *hostname, + const ModuleSpec &module_spec, lldb::ModuleSP &cached_module_sp, + bool *did_create_ptr); - std::unordered_map<std::string, lldb::ModuleWP> m_loaded_modules; + std::unordered_map<std::string, lldb::ModuleWP> m_loaded_modules; }; } // namespace lldb_private -#endif // utility_ModuleCache_h_ +#endif // utility_ModuleCache_h_ diff --git a/lldb/source/Utility/NameMatches.cpp b/lldb/source/Utility/NameMatches.cpp index e10c47e..bd30760 100644 --- a/lldb/source/Utility/NameMatches.cpp +++ b/lldb/source/Utility/NameMatches.cpp @@ -6,45 +6,40 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#include "lldb/Core/RegularExpression.h" #include "lldb/Utility/NameMatches.h" +#include "lldb/Core/RegularExpression.h" #include "llvm/ADT/StringRef.h" using namespace lldb_private; -bool -lldb_private::NameMatches(const char *name, NameMatchType match_type, const char *match) -{ - if (match_type == eNameMatchIgnore) - return true; +bool lldb_private::NameMatches(const char *name, NameMatchType match_type, + const char *match) { + if (match_type == eNameMatchIgnore) + return true; - if (name == match) - return true; + if (name == match) + return true; - if (name && match) - { - llvm::StringRef name_sref(name); - llvm::StringRef match_sref(match); - switch (match_type) - { - case eNameMatchIgnore: // This case cannot occur: tested before - return true; - case eNameMatchEquals: - return name_sref == match_sref; - case eNameMatchContains: - return name_sref.find(match_sref) != llvm::StringRef::npos; - case eNameMatchStartsWith: - return name_sref.startswith(match_sref); - case eNameMatchEndsWith: - return name_sref.endswith(match_sref); - case eNameMatchRegularExpression: - { - RegularExpression regex(match); - return regex.Execute(name); - } - break; - } + if (name && match) { + llvm::StringRef name_sref(name); + llvm::StringRef match_sref(match); + switch (match_type) { + case eNameMatchIgnore: // This case cannot occur: tested before + return true; + case eNameMatchEquals: + return name_sref == match_sref; + case eNameMatchContains: + return name_sref.find(match_sref) != llvm::StringRef::npos; + case eNameMatchStartsWith: + return name_sref.startswith(match_sref); + case eNameMatchEndsWith: + return name_sref.endswith(match_sref); + case eNameMatchRegularExpression: { + RegularExpression regex(match); + return regex.Execute(name); + } break; } - return false; + } + return false; } diff --git a/lldb/source/Utility/PseudoTerminal.cpp b/lldb/source/Utility/PseudoTerminal.cpp index 7a200f2..555dcf1 100644 --- a/lldb/source/Utility/PseudoTerminal.cpp +++ b/lldb/source/Utility/PseudoTerminal.cpp @@ -7,13 +7,13 @@ // //===----------------------------------------------------------------------===// -#include "lldb/Host/Config.h" #include "lldb/Utility/PseudoTerminal.h" +#include "lldb/Host/Config.h" #include <errno.h> +#include <stdio.h> #include <stdlib.h> #include <string.h> -#include <stdio.h> #if defined(TIOCSCTTY) #include <sys/ioctl.h> #endif @@ -29,11 +29,8 @@ using namespace lldb_utility; //---------------------------------------------------------------------- // PseudoTerminal constructor //---------------------------------------------------------------------- -PseudoTerminal::PseudoTerminal () : - m_master_fd(invalid_fd), - m_slave_fd(invalid_fd) -{ -} +PseudoTerminal::PseudoTerminal() + : m_master_fd(invalid_fd), m_slave_fd(invalid_fd) {} //---------------------------------------------------------------------- // Destructor @@ -43,40 +40,33 @@ PseudoTerminal::PseudoTerminal () : // ReleaseMasterFileDescriptor() or the ReleaseSaveFileDescriptor() // member functions. //---------------------------------------------------------------------- -PseudoTerminal::~PseudoTerminal () -{ - CloseMasterFileDescriptor(); - CloseSlaveFileDescriptor(); +PseudoTerminal::~PseudoTerminal() { + CloseMasterFileDescriptor(); + CloseSlaveFileDescriptor(); } //---------------------------------------------------------------------- // Close the master file descriptor if it is valid. //---------------------------------------------------------------------- -void -PseudoTerminal::CloseMasterFileDescriptor () -{ - if (m_master_fd >= 0) - { - // Don't call 'close' on m_master_fd for Windows as a dummy implementation of - // posix_openpt above always gives it a 0 value. +void PseudoTerminal::CloseMasterFileDescriptor() { + if (m_master_fd >= 0) { +// Don't call 'close' on m_master_fd for Windows as a dummy implementation of +// posix_openpt above always gives it a 0 value. #ifndef _WIN32 - ::close (m_master_fd); + ::close(m_master_fd); #endif - m_master_fd = invalid_fd; - } + m_master_fd = invalid_fd; + } } //---------------------------------------------------------------------- // Close the slave file descriptor if it is valid. //---------------------------------------------------------------------- -void -PseudoTerminal::CloseSlaveFileDescriptor () -{ - if (m_slave_fd >= 0) - { - ::close (m_slave_fd); - m_slave_fd = invalid_fd; - } +void PseudoTerminal::CloseSlaveFileDescriptor() { + if (m_slave_fd >= 0) { + ::close(m_slave_fd); + m_slave_fd = invalid_fd; + } } //---------------------------------------------------------------------- @@ -93,40 +83,36 @@ PseudoTerminal::CloseSlaveFileDescriptor () // RETURNS: // Zero when successful, non-zero indicating an error occurred. //---------------------------------------------------------------------- -bool -PseudoTerminal::OpenFirstAvailableMaster (int oflag, char *error_str, size_t error_len) -{ +bool PseudoTerminal::OpenFirstAvailableMaster(int oflag, char *error_str, + size_t error_len) { + if (error_str) + error_str[0] = '\0'; + + // Open the master side of a pseudo terminal + m_master_fd = ::posix_openpt(oflag); + if (m_master_fd < 0) { if (error_str) - error_str[0] = '\0'; - - // Open the master side of a pseudo terminal - m_master_fd = ::posix_openpt (oflag); - if (m_master_fd < 0) - { - if (error_str) - ::strerror_r (errno, error_str, error_len); - return false; - } + ::strerror_r(errno, error_str, error_len); + return false; + } - // Grant access to the slave pseudo terminal - if (::grantpt (m_master_fd) < 0) - { - if (error_str) - ::strerror_r (errno, error_str, error_len); - CloseMasterFileDescriptor (); - return false; - } + // Grant access to the slave pseudo terminal + if (::grantpt(m_master_fd) < 0) { + if (error_str) + ::strerror_r(errno, error_str, error_len); + CloseMasterFileDescriptor(); + return false; + } - // Clear the lock flag on the slave pseudo terminal - if (::unlockpt (m_master_fd) < 0) - { - if (error_str) - ::strerror_r (errno, error_str, error_len); - CloseMasterFileDescriptor (); - return false; - } + // Clear the lock flag on the slave pseudo terminal + if (::unlockpt(m_master_fd) < 0) { + if (error_str) + ::strerror_r(errno, error_str, error_len); + CloseMasterFileDescriptor(); + return false; + } - return true; + return true; } //---------------------------------------------------------------------- @@ -140,34 +126,29 @@ PseudoTerminal::OpenFirstAvailableMaster (int oflag, char *error_str, size_t err // RETURNS: // Zero when successful, non-zero indicating an error occurred. //---------------------------------------------------------------------- -bool -PseudoTerminal::OpenSlave (int oflag, char *error_str, size_t error_len) -{ - if (error_str) - error_str[0] = '\0'; +bool PseudoTerminal::OpenSlave(int oflag, char *error_str, size_t error_len) { + if (error_str) + error_str[0] = '\0'; - CloseSlaveFileDescriptor(); + CloseSlaveFileDescriptor(); - // Open the master side of a pseudo terminal - const char *slave_name = GetSlaveName (error_str, error_len); + // Open the master side of a pseudo terminal + const char *slave_name = GetSlaveName(error_str, error_len); - if (slave_name == nullptr) - return false; + if (slave_name == nullptr) + return false; - m_slave_fd = ::open (slave_name, oflag); + m_slave_fd = ::open(slave_name, oflag); - if (m_slave_fd < 0) - { - if (error_str) - ::strerror_r (errno, error_str, error_len); - return false; - } + if (m_slave_fd < 0) { + if (error_str) + ::strerror_r(errno, error_str, error_len); + return false; + } - return true; + return true; } - - //---------------------------------------------------------------------- // Get the name of the slave pseudo terminal. A master pseudo terminal // should already be valid prior to calling this function (see @@ -179,27 +160,25 @@ PseudoTerminal::OpenSlave (int oflag, char *error_str, size_t error_len) // that comes from static memory, so a copy of the string should be // made as subsequent calls can change this value. //---------------------------------------------------------------------- -const char* -PseudoTerminal::GetSlaveName (char *error_str, size_t error_len) const -{ - if (error_str) - error_str[0] = '\0'; +const char *PseudoTerminal::GetSlaveName(char *error_str, + size_t error_len) const { + if (error_str) + error_str[0] = '\0'; - if (m_master_fd < 0) - { - if (error_str) - ::snprintf (error_str, error_len, "%s", "master file descriptor is invalid"); - return nullptr; - } - const char *slave_name = ::ptsname (m_master_fd); + if (m_master_fd < 0) { + if (error_str) + ::snprintf(error_str, error_len, "%s", + "master file descriptor is invalid"); + return nullptr; + } + const char *slave_name = ::ptsname(m_master_fd); - if (error_str && slave_name == nullptr) - ::strerror_r (errno, error_str, error_len); + if (error_str && slave_name == nullptr) + ::strerror_r(errno, error_str, error_len); - return slave_name; + return slave_name; } - //---------------------------------------------------------------------- // Fork a child process and have its stdio routed to a pseudo terminal. // @@ -221,74 +200,62 @@ PseudoTerminal::GetSlaveName (char *error_str, size_t error_len) const // in the parent process: the pid of the child, or -1 if fork fails // in the child process: zero //---------------------------------------------------------------------- -lldb::pid_t -PseudoTerminal::Fork (char *error_str, size_t error_len) -{ - if (error_str) - error_str[0] = '\0'; - pid_t pid = LLDB_INVALID_PROCESS_ID; +lldb::pid_t PseudoTerminal::Fork(char *error_str, size_t error_len) { + if (error_str) + error_str[0] = '\0'; + pid_t pid = LLDB_INVALID_PROCESS_ID; #if !defined(LLDB_DISABLE_POSIX) - int flags = O_RDWR; - flags |= O_CLOEXEC; - if (OpenFirstAvailableMaster (flags, error_str, error_len)) - { - // Successfully opened our master pseudo terminal - - pid = ::fork (); - if (pid < 0) - { - // Fork failed - if (error_str) - ::strerror_r (errno, error_str, error_len); - } - else if (pid == 0) - { - // Child Process - ::setsid(); - - if (OpenSlave (O_RDWR, error_str, error_len)) - { - // Successfully opened slave - - // Master FD should have O_CLOEXEC set, but let's close it just in case... - CloseMasterFileDescriptor (); + int flags = O_RDWR; + flags |= O_CLOEXEC; + if (OpenFirstAvailableMaster(flags, error_str, error_len)) { + // Successfully opened our master pseudo terminal + + pid = ::fork(); + if (pid < 0) { + // Fork failed + if (error_str) + ::strerror_r(errno, error_str, error_len); + } else if (pid == 0) { + // Child Process + ::setsid(); + + if (OpenSlave(O_RDWR, error_str, error_len)) { + // Successfully opened slave + + // Master FD should have O_CLOEXEC set, but let's close it just in + // case... + CloseMasterFileDescriptor(); #if defined(TIOCSCTTY) - // Acquire the controlling terminal - if (::ioctl (m_slave_fd, TIOCSCTTY, (char *)0) < 0) - { - if (error_str) - ::strerror_r (errno, error_str, error_len); - } + // Acquire the controlling terminal + if (::ioctl(m_slave_fd, TIOCSCTTY, (char *)0) < 0) { + if (error_str) + ::strerror_r(errno, error_str, error_len); + } #endif - // Duplicate all stdio file descriptors to the slave pseudo terminal - if (::dup2 (m_slave_fd, STDIN_FILENO) != STDIN_FILENO) - { - if (error_str && !error_str[0]) - ::strerror_r (errno, error_str, error_len); - } - - if (::dup2 (m_slave_fd, STDOUT_FILENO) != STDOUT_FILENO) - { - if (error_str && !error_str[0]) - ::strerror_r (errno, error_str, error_len); - } - - if (::dup2 (m_slave_fd, STDERR_FILENO) != STDERR_FILENO) - { - if (error_str && !error_str[0]) - ::strerror_r (errno, error_str, error_len); - } - } + // Duplicate all stdio file descriptors to the slave pseudo terminal + if (::dup2(m_slave_fd, STDIN_FILENO) != STDIN_FILENO) { + if (error_str && !error_str[0]) + ::strerror_r(errno, error_str, error_len); } - else - { - // Parent Process - // Do nothing and let the pid get returned! + + if (::dup2(m_slave_fd, STDOUT_FILENO) != STDOUT_FILENO) { + if (error_str && !error_str[0]) + ::strerror_r(errno, error_str, error_len); } + + if (::dup2(m_slave_fd, STDERR_FILENO) != STDERR_FILENO) { + if (error_str && !error_str[0]) + ::strerror_r(errno, error_str, error_len); + } + } + } else { + // Parent Process + // Do nothing and let the pid get returned! } + } #endif - return pid; + return pid; } //---------------------------------------------------------------------- @@ -300,11 +267,7 @@ PseudoTerminal::Fork (char *error_str, size_t error_len) // Returns the master file descriptor, or -1 if the master file // descriptor is not currently valid. //---------------------------------------------------------------------- -int -PseudoTerminal::GetMasterFileDescriptor () const -{ - return m_master_fd; -} +int PseudoTerminal::GetMasterFileDescriptor() const { return m_master_fd; } //---------------------------------------------------------------------- // The slave file descriptor accessor. @@ -312,11 +275,7 @@ PseudoTerminal::GetMasterFileDescriptor () const // Returns the slave file descriptor, or -1 if the slave file // descriptor is not currently valid. //---------------------------------------------------------------------- -int -PseudoTerminal::GetSlaveFileDescriptor () const -{ - return m_slave_fd; -} +int PseudoTerminal::GetSlaveFileDescriptor() const { return m_slave_fd; } //---------------------------------------------------------------------- // Release ownership of the master pseudo terminal file descriptor @@ -324,15 +283,13 @@ PseudoTerminal::GetSlaveFileDescriptor () const // master file descriptor if the ownership isn't released using this // call and the master file descriptor has been opened. //---------------------------------------------------------------------- -int -PseudoTerminal::ReleaseMasterFileDescriptor () -{ - // Release ownership of the master pseudo terminal file - // descriptor without closing it. (the destructor for this - // class will close it otherwise!) - int fd = m_master_fd; - m_master_fd = invalid_fd; - return fd; +int PseudoTerminal::ReleaseMasterFileDescriptor() { + // Release ownership of the master pseudo terminal file + // descriptor without closing it. (the destructor for this + // class will close it otherwise!) + int fd = m_master_fd; + m_master_fd = invalid_fd; + return fd; } //---------------------------------------------------------------------- @@ -341,14 +298,11 @@ PseudoTerminal::ReleaseMasterFileDescriptor () // slave file descriptor if the ownership isn't released using this // call and the slave file descriptor has been opened. //---------------------------------------------------------------------- -int -PseudoTerminal::ReleaseSlaveFileDescriptor () -{ - // Release ownership of the slave pseudo terminal file - // descriptor without closing it (the destructor for this - // class will close it otherwise!) - int fd = m_slave_fd; - m_slave_fd = invalid_fd; - return fd; +int PseudoTerminal::ReleaseSlaveFileDescriptor() { + // Release ownership of the slave pseudo terminal file + // descriptor without closing it (the destructor for this + // class will close it otherwise!) + int fd = m_slave_fd; + m_slave_fd = invalid_fd; + return fd; } - diff --git a/lldb/source/Utility/Range.cpp b/lldb/source/Utility/Range.cpp index 158d1e7..95f00e5 100644 --- a/lldb/source/Utility/Range.cpp +++ b/lldb/source/Utility/Range.cpp @@ -1,4 +1,5 @@ -//===--------------------- Range.cpp -----------------------------*- C++ -*-===// +//===--------------------- Range.cpp -----------------------------*- C++ +//-*-===// // // The LLVM Compiler Infrastructure // @@ -11,93 +12,63 @@ using namespace lldb_utility; -Range::Range (const Range& rng) : -m_low(rng.m_low), -m_high(rng.m_high) -{ - InitRange(); +Range::Range(const Range &rng) : m_low(rng.m_low), m_high(rng.m_high) { + InitRange(); } -Range::Range (Range::ValueType low, - Range::ValueType high) : -m_low(low), -m_high(high) -{ - InitRange(); +Range::Range(Range::ValueType low, Range::ValueType high) + : m_low(low), m_high(high) { + InitRange(); } -void -Range::InitRange () -{ - if (m_low == OPEN_END) - { - if (m_high == OPEN_END) - m_low = 0; - else - { - // make an empty range - m_low = 1; - m_high = 0; - } +void Range::InitRange() { + if (m_low == OPEN_END) { + if (m_high == OPEN_END) + m_low = 0; + else { + // make an empty range + m_low = 1; + m_high = 0; } + } } -Range& -Range::operator = (const Range& rhs) -{ - if (&rhs != this) - { - this->m_low = rhs.m_low; - this->m_high = rhs.m_high; - } - return *this; +Range &Range::operator=(const Range &rhs) { + if (&rhs != this) { + this->m_low = rhs.m_low; + this->m_high = rhs.m_high; + } + return *this; } -void -Range::Flip () -{ - std::swap(m_high, m_low); -} +void Range::Flip() { std::swap(m_high, m_low); } -void -Range::Intersection (const Range& other) -{ - m_low = std::max(m_low,other.m_low); - m_high = std::min(m_high,other.m_high); +void Range::Intersection(const Range &other) { + m_low = std::max(m_low, other.m_low); + m_high = std::min(m_high, other.m_high); } -void -Range::Union (const Range& other) -{ - m_low = std::min(m_low,other.m_low); - m_high = std::max(m_high,other.m_high); +void Range::Union(const Range &other) { + m_low = std::min(m_low, other.m_low); + m_high = std::max(m_high, other.m_high); } -void -Range::Iterate (RangeCallback callback) -{ - ValueType counter = m_low; - while (counter <= m_high) - { - bool should_continue = callback(counter); - if (!should_continue) - return; - counter++; - } +void Range::Iterate(RangeCallback callback) { + ValueType counter = m_low; + while (counter <= m_high) { + bool should_continue = callback(counter); + if (!should_continue) + return; + counter++; + } } -bool -Range::IsEmpty () -{ - return (m_low > m_high); -} +bool Range::IsEmpty() { return (m_low > m_high); } -Range::ValueType -Range::GetSize () -{ - if (m_high == OPEN_END) - return OPEN_END; - if (m_high >= m_low) - return m_high - m_low + 1; - return 0; +Range::ValueType Range::GetSize() { + if (m_high == OPEN_END) + return OPEN_END; + if (m_high >= m_low) + return m_high - m_low + 1; + return 0; } diff --git a/lldb/source/Utility/RegisterNumber.cpp b/lldb/source/Utility/RegisterNumber.cpp index 8116cda..07dd223 100644 --- a/lldb/source/Utility/RegisterNumber.cpp +++ b/lldb/source/Utility/RegisterNumber.cpp @@ -8,150 +8,112 @@ //===----------------------------------------------------------------------===// #include "lldb/Utility/RegisterNumber.h" -#include "lldb/Target/Thread.h" #include "lldb/Target/RegisterContext.h" +#include "lldb/Target/Thread.h" using namespace lldb_private; - -RegisterNumber::RegisterNumber (lldb_private::Thread &thread, lldb::RegisterKind kind, uint32_t num) : - m_reg_ctx_sp (thread.GetRegisterContext()), - m_regnum (num), - m_kind (kind), - m_kind_regnum_map (), - m_name ("") -{ - if (m_reg_ctx_sp.get()) - { - const lldb_private::RegisterInfo *reginfo = m_reg_ctx_sp->GetRegisterInfoAtIndex (GetAsKind (lldb::eRegisterKindLLDB)); - if (reginfo && reginfo->name) - { - m_name = reginfo->name; - } +RegisterNumber::RegisterNumber(lldb_private::Thread &thread, + lldb::RegisterKind kind, uint32_t num) + : m_reg_ctx_sp(thread.GetRegisterContext()), m_regnum(num), m_kind(kind), + m_kind_regnum_map(), m_name("") { + if (m_reg_ctx_sp.get()) { + const lldb_private::RegisterInfo *reginfo = + m_reg_ctx_sp->GetRegisterInfoAtIndex( + GetAsKind(lldb::eRegisterKindLLDB)); + if (reginfo && reginfo->name) { + m_name = reginfo->name; } + } } -RegisterNumber::RegisterNumber () : - m_reg_ctx_sp(), - m_regnum (LLDB_INVALID_REGNUM), - m_kind (lldb::kNumRegisterKinds), - m_kind_regnum_map (), - m_name (nullptr) -{ -} - -void -RegisterNumber::init (lldb_private::Thread &thread, lldb::RegisterKind kind, uint32_t num) -{ - m_reg_ctx_sp = thread.GetRegisterContext(); - m_regnum = num; - m_kind = kind; - if (m_reg_ctx_sp.get()) - { - const lldb_private::RegisterInfo *reginfo = m_reg_ctx_sp->GetRegisterInfoAtIndex (GetAsKind (lldb::eRegisterKindLLDB)); - if (reginfo && reginfo->name) - { - m_name = reginfo->name; - } +RegisterNumber::RegisterNumber() + : m_reg_ctx_sp(), m_regnum(LLDB_INVALID_REGNUM), + m_kind(lldb::kNumRegisterKinds), m_kind_regnum_map(), m_name(nullptr) {} + +void RegisterNumber::init(lldb_private::Thread &thread, lldb::RegisterKind kind, + uint32_t num) { + m_reg_ctx_sp = thread.GetRegisterContext(); + m_regnum = num; + m_kind = kind; + if (m_reg_ctx_sp.get()) { + const lldb_private::RegisterInfo *reginfo = + m_reg_ctx_sp->GetRegisterInfoAtIndex( + GetAsKind(lldb::eRegisterKindLLDB)); + if (reginfo && reginfo->name) { + m_name = reginfo->name; } + } } -const RegisterNumber & -RegisterNumber::operator = (const RegisterNumber &rhs) -{ - m_reg_ctx_sp = rhs.m_reg_ctx_sp; - m_regnum = rhs.m_regnum; - m_kind = rhs.m_kind; - for (auto it : rhs.m_kind_regnum_map) - m_kind_regnum_map[it.first] = it.second; - m_name = rhs.m_name; - return *this; +const RegisterNumber &RegisterNumber::operator=(const RegisterNumber &rhs) { + m_reg_ctx_sp = rhs.m_reg_ctx_sp; + m_regnum = rhs.m_regnum; + m_kind = rhs.m_kind; + for (auto it : rhs.m_kind_regnum_map) + m_kind_regnum_map[it.first] = it.second; + m_name = rhs.m_name; + return *this; } -bool -RegisterNumber::operator == (RegisterNumber &rhs) -{ - if (IsValid() != rhs.IsValid()) - return false; - - if (m_kind == rhs.m_kind) - { - if (m_regnum == rhs.m_regnum) - return true; - else - return false; - } - - uint32_t rhs_regnum = rhs.GetAsKind (m_kind); - if (rhs_regnum != LLDB_INVALID_REGNUM) - { - if (m_regnum == rhs_regnum) - return true; - else - return false; - } - uint32_t lhs_regnum = GetAsKind (rhs.m_kind); - { - if (lhs_regnum == rhs.m_regnum) - return true; - else - return false; - } +bool RegisterNumber::operator==(RegisterNumber &rhs) { + if (IsValid() != rhs.IsValid()) return false; -} -bool -RegisterNumber::operator != (RegisterNumber &rhs) -{ - return !(*this == rhs); + if (m_kind == rhs.m_kind) { + if (m_regnum == rhs.m_regnum) + return true; + else + return false; + } + + uint32_t rhs_regnum = rhs.GetAsKind(m_kind); + if (rhs_regnum != LLDB_INVALID_REGNUM) { + if (m_regnum == rhs_regnum) + return true; + else + return false; + } + uint32_t lhs_regnum = GetAsKind(rhs.m_kind); + { + if (lhs_regnum == rhs.m_regnum) + return true; + else + return false; + } + return false; } -bool -RegisterNumber::IsValid () const -{ - return m_reg_ctx_sp.get() - && m_kind != lldb::kNumRegisterKinds - && m_regnum != LLDB_INVALID_REGNUM; +bool RegisterNumber::operator!=(RegisterNumber &rhs) { return !(*this == rhs); } + +bool RegisterNumber::IsValid() const { + return m_reg_ctx_sp.get() && m_kind != lldb::kNumRegisterKinds && + m_regnum != LLDB_INVALID_REGNUM; } -uint32_t -RegisterNumber::GetAsKind (lldb::RegisterKind kind) -{ - if (m_regnum == LLDB_INVALID_REGNUM) - return LLDB_INVALID_REGNUM; +uint32_t RegisterNumber::GetAsKind(lldb::RegisterKind kind) { + if (m_regnum == LLDB_INVALID_REGNUM) + return LLDB_INVALID_REGNUM; - if (kind == m_kind) - return m_regnum; + if (kind == m_kind) + return m_regnum; - Collection::iterator iter = m_kind_regnum_map.find (kind); - if (iter != m_kind_regnum_map.end()) - { - return iter->second; - } - uint32_t output_regnum = LLDB_INVALID_REGNUM; - if (m_reg_ctx_sp - && m_reg_ctx_sp->ConvertBetweenRegisterKinds (m_kind, m_regnum, kind, output_regnum) - && output_regnum != LLDB_INVALID_REGNUM) - { - m_kind_regnum_map[kind] = output_regnum; - } - return output_regnum; + Collection::iterator iter = m_kind_regnum_map.find(kind); + if (iter != m_kind_regnum_map.end()) { + return iter->second; + } + uint32_t output_regnum = LLDB_INVALID_REGNUM; + if (m_reg_ctx_sp && + m_reg_ctx_sp->ConvertBetweenRegisterKinds(m_kind, m_regnum, kind, + output_regnum) && + output_regnum != LLDB_INVALID_REGNUM) { + m_kind_regnum_map[kind] = output_regnum; + } + return output_regnum; } -uint32_t -RegisterNumber::GetRegisterNumber () const -{ - return m_regnum; -} +uint32_t RegisterNumber::GetRegisterNumber() const { return m_regnum; } -lldb::RegisterKind -RegisterNumber::GetRegisterKind () const -{ - return m_kind; -} +lldb::RegisterKind RegisterNumber::GetRegisterKind() const { return m_kind; } -const char * -RegisterNumber::GetName () -{ - return m_name; -} +const char *RegisterNumber::GetName() { return m_name; } diff --git a/lldb/source/Utility/SelectHelper.cpp b/lldb/source/Utility/SelectHelper.cpp index 44282d2..cd9a0f6 100644 --- a/lldb/source/Utility/SelectHelper.cpp +++ b/lldb/source/Utility/SelectHelper.cpp @@ -32,269 +32,220 @@ // Project includes #include "lldb/Core/Error.h" -#include "lldb/Utility/SelectHelper.h" #include "lldb/Utility/LLDBAssert.h" +#include "lldb/Utility/SelectHelper.h" -SelectHelper::SelectHelper() : - m_fd_map(), - m_end_time() // Infinite timeout unless SelectHelper::SetTimeout() gets called -{ -} +SelectHelper::SelectHelper() + : m_fd_map(), m_end_time() // Infinite timeout unless + // SelectHelper::SetTimeout() gets called +{} -void -SelectHelper::SetTimeout(const std::chrono::microseconds &timeout) -{ - using namespace std::chrono; - m_end_time = steady_clock::time_point(steady_clock::now() + timeout); +void SelectHelper::SetTimeout(const std::chrono::microseconds &timeout) { + using namespace std::chrono; + m_end_time = steady_clock::time_point(steady_clock::now() + timeout); } -void -SelectHelper::FDSetRead(int fd) -{ - m_fd_map[fd].read_set = true; -} +void SelectHelper::FDSetRead(int fd) { m_fd_map[fd].read_set = true; } -void -SelectHelper::FDSetWrite(int fd) -{ - m_fd_map[fd].write_set = true; -} +void SelectHelper::FDSetWrite(int fd) { m_fd_map[fd].write_set = true; } -void -SelectHelper::FDSetError(int fd) -{ - m_fd_map[fd].error_set = true; -} +void SelectHelper::FDSetError(int fd) { m_fd_map[fd].error_set = true; } -bool -SelectHelper::FDIsSetRead(int fd) const -{ - auto pos = m_fd_map.find(fd); - if (pos != m_fd_map.end()) - return pos->second.read_is_set; - else - return false; +bool SelectHelper::FDIsSetRead(int fd) const { + auto pos = m_fd_map.find(fd); + if (pos != m_fd_map.end()) + return pos->second.read_is_set; + else + return false; } -bool -SelectHelper::FDIsSetWrite(int fd) const -{ - auto pos = m_fd_map.find(fd); - if (pos != m_fd_map.end()) - return pos->second.write_is_set; - else - return false; +bool SelectHelper::FDIsSetWrite(int fd) const { + auto pos = m_fd_map.find(fd); + if (pos != m_fd_map.end()) + return pos->second.write_is_set; + else + return false; } -bool -SelectHelper::FDIsSetError(int fd) const -{ - auto pos = m_fd_map.find(fd); - if (pos != m_fd_map.end()) - return pos->second.error_is_set; - else - return false; +bool SelectHelper::FDIsSetError(int fd) const { + auto pos = m_fd_map.find(fd); + if (pos != m_fd_map.end()) + return pos->second.error_is_set; + else + return false; } -lldb_private::Error -SelectHelper::Select() -{ - lldb_private::Error error; +lldb_private::Error SelectHelper::Select() { + lldb_private::Error error; #ifdef _MSC_VER - // On windows FD_SETSIZE limits the number of file descriptors, not their numeric value. - lldbassert(m_fd_map.size() <= FD_SETSIZE); - if (m_fd_map.size() > FD_SETSIZE) - return lldb_private::Error("Too many file descriptors for select()"); + // On windows FD_SETSIZE limits the number of file descriptors, not their + // numeric value. + lldbassert(m_fd_map.size() <= FD_SETSIZE); + if (m_fd_map.size() > FD_SETSIZE) + return lldb_private::Error("Too many file descriptors for select()"); #endif - int max_read_fd = -1; - int max_write_fd = -1; - int max_error_fd = -1; - int max_fd = -1; - for (auto &pair : m_fd_map) - { - pair.second.PrepareForSelect(); - const int fd = pair.first; + int max_read_fd = -1; + int max_write_fd = -1; + int max_error_fd = -1; + int max_fd = -1; + for (auto &pair : m_fd_map) { + pair.second.PrepareForSelect(); + const int fd = pair.first; #if !defined(__APPLE__) && !defined(_MSC_VER) - lldbassert(fd < FD_SETSIZE); - if (fd >= FD_SETSIZE) - { - error.SetErrorStringWithFormat("%i is too large for select()", fd); - return error; - } + lldbassert(fd < FD_SETSIZE); + if (fd >= FD_SETSIZE) { + error.SetErrorStringWithFormat("%i is too large for select()", fd); + return error; + } #endif - if (pair.second.read_set) - { - max_read_fd = std::max<int>(fd, max_read_fd); - max_fd = std::max<int>(fd, max_fd); - } - if (pair.second.write_set) - { - max_write_fd = std::max<int>(fd, max_write_fd); - max_fd = std::max<int>(fd, max_fd); - } - if (pair.second.error_set) - { - max_error_fd = std::max<int>(fd, max_error_fd); - max_fd = std::max<int>(fd, max_fd); - } + if (pair.second.read_set) { + max_read_fd = std::max<int>(fd, max_read_fd); + max_fd = std::max<int>(fd, max_fd); } - - if (max_fd == -1) - { - error.SetErrorString("no valid file descriptors"); - return error; + if (pair.second.write_set) { + max_write_fd = std::max<int>(fd, max_write_fd); + max_fd = std::max<int>(fd, max_fd); + } + if (pair.second.error_set) { + max_error_fd = std::max<int>(fd, max_error_fd); + max_fd = std::max<int>(fd, max_fd); } + } - const int nfds = max_fd + 1; - fd_set *read_fdset_ptr = nullptr; - fd_set *write_fdset_ptr = nullptr; - fd_set *error_fdset_ptr = nullptr; - //---------------------------------------------------------------------- - // Initialize and zero out the fdsets - //---------------------------------------------------------------------- + if (max_fd == -1) { + error.SetErrorString("no valid file descriptors"); + return error; + } + + const int nfds = max_fd + 1; + fd_set *read_fdset_ptr = nullptr; + fd_set *write_fdset_ptr = nullptr; + fd_set *error_fdset_ptr = nullptr; +//---------------------------------------------------------------------- +// Initialize and zero out the fdsets +//---------------------------------------------------------------------- #if defined(__APPLE__) - llvm::SmallVector<fd_set, 1> read_fdset; - llvm::SmallVector<fd_set, 1> write_fdset; - llvm::SmallVector<fd_set, 1> error_fdset; - - if (max_read_fd >= 0) - { - read_fdset.resize((nfds / FD_SETSIZE) + 1); - read_fdset_ptr = read_fdset.data(); - } - if (max_write_fd >= 0) - { - write_fdset.resize((nfds / FD_SETSIZE) + 1); - write_fdset_ptr = write_fdset.data(); - } - if (max_error_fd >= 0) - { - error_fdset.resize((nfds / FD_SETSIZE) + 1); - error_fdset_ptr = error_fdset.data(); - } - for (auto &fd_set : read_fdset) - FD_ZERO(&fd_set); - for (auto &fd_set : write_fdset) - FD_ZERO(&fd_set); - for (auto &fd_set : error_fdset) - FD_ZERO(&fd_set); + llvm::SmallVector<fd_set, 1> read_fdset; + llvm::SmallVector<fd_set, 1> write_fdset; + llvm::SmallVector<fd_set, 1> error_fdset; + + if (max_read_fd >= 0) { + read_fdset.resize((nfds / FD_SETSIZE) + 1); + read_fdset_ptr = read_fdset.data(); + } + if (max_write_fd >= 0) { + write_fdset.resize((nfds / FD_SETSIZE) + 1); + write_fdset_ptr = write_fdset.data(); + } + if (max_error_fd >= 0) { + error_fdset.resize((nfds / FD_SETSIZE) + 1); + error_fdset_ptr = error_fdset.data(); + } + for (auto &fd_set : read_fdset) + FD_ZERO(&fd_set); + for (auto &fd_set : write_fdset) + FD_ZERO(&fd_set); + for (auto &fd_set : error_fdset) + FD_ZERO(&fd_set); #else - fd_set read_fdset; - fd_set write_fdset; - fd_set error_fdset; - - if (max_read_fd >= 0) - { - FD_ZERO(&read_fdset); - read_fdset_ptr = &read_fdset; - } - if (max_write_fd >= 0) - { - FD_ZERO(&write_fdset); - write_fdset_ptr = &write_fdset; - } - if (max_error_fd >= 0) - { - FD_ZERO(&error_fdset); - error_fdset_ptr = &error_fdset; - } + fd_set read_fdset; + fd_set write_fdset; + fd_set error_fdset; + + if (max_read_fd >= 0) { + FD_ZERO(&read_fdset); + read_fdset_ptr = &read_fdset; + } + if (max_write_fd >= 0) { + FD_ZERO(&write_fdset); + write_fdset_ptr = &write_fdset; + } + if (max_error_fd >= 0) { + FD_ZERO(&error_fdset); + error_fdset_ptr = &error_fdset; + } #endif - //---------------------------------------------------------------------- - // Set the FD bits in the fdsets for read/write/error - //---------------------------------------------------------------------- - for (auto &pair : m_fd_map) - { - const int fd = pair.first; + //---------------------------------------------------------------------- + // Set the FD bits in the fdsets for read/write/error + //---------------------------------------------------------------------- + for (auto &pair : m_fd_map) { + const int fd = pair.first; - if (pair.second.read_set) - FD_SET(fd, read_fdset_ptr); + if (pair.second.read_set) + FD_SET(fd, read_fdset_ptr); - if (pair.second.write_set) - FD_SET(fd, write_fdset_ptr); + if (pair.second.write_set) + FD_SET(fd, write_fdset_ptr); - if (pair.second.error_set) - FD_SET(fd, error_fdset_ptr); - } + if (pair.second.error_set) + FD_SET(fd, error_fdset_ptr); + } - //---------------------------------------------------------------------- - // Setup our timeout time value if needed - //---------------------------------------------------------------------- - struct timeval *tv_ptr = nullptr; - struct timeval tv = {0, 0}; + //---------------------------------------------------------------------- + // Setup our timeout time value if needed + //---------------------------------------------------------------------- + struct timeval *tv_ptr = nullptr; + struct timeval tv = {0, 0}; - while (1) - { - using namespace std::chrono; - //------------------------------------------------------------------ - // Setup out relative timeout based on the end time if we have one - //------------------------------------------------------------------ - if (m_end_time.hasValue()) - { - tv_ptr = &tv; - const auto remaining_dur = duration_cast<microseconds>(m_end_time.getValue() - steady_clock::now()); - if (remaining_dur.count() > 0) - { - // Wait for a specific amount of time - const auto dur_secs = duration_cast<seconds>(remaining_dur); - const auto dur_usecs = remaining_dur % seconds(1); - tv.tv_sec = dur_secs.count(); - tv.tv_usec = dur_usecs.count(); - } - else - { - // Just poll once with no timeout - tv.tv_sec = 0; - tv.tv_usec = 0; - } - } - const int num_set_fds = ::select(nfds, read_fdset_ptr, write_fdset_ptr, error_fdset_ptr, tv_ptr); - if (num_set_fds < 0) - { - // We got an error - error.SetErrorToErrno(); - if (error.GetError() == EINTR) - { - error.Clear(); - continue; // Keep calling select if we get EINTR - } - else - return error; + while (1) { + using namespace std::chrono; + //------------------------------------------------------------------ + // Setup out relative timeout based on the end time if we have one + //------------------------------------------------------------------ + if (m_end_time.hasValue()) { + tv_ptr = &tv; + const auto remaining_dur = duration_cast<microseconds>( + m_end_time.getValue() - steady_clock::now()); + if (remaining_dur.count() > 0) { + // Wait for a specific amount of time + const auto dur_secs = duration_cast<seconds>(remaining_dur); + const auto dur_usecs = remaining_dur % seconds(1); + tv.tv_sec = dur_secs.count(); + tv.tv_usec = dur_usecs.count(); + } else { + // Just poll once with no timeout + tv.tv_sec = 0; + tv.tv_usec = 0; + } + } + const int num_set_fds = ::select(nfds, read_fdset_ptr, write_fdset_ptr, + error_fdset_ptr, tv_ptr); + if (num_set_fds < 0) { + // We got an error + error.SetErrorToErrno(); + if (error.GetError() == EINTR) { + error.Clear(); + continue; // Keep calling select if we get EINTR + } else + return error; + } else if (num_set_fds == 0) { + // Timeout + error.SetError(ETIMEDOUT, lldb::eErrorTypePOSIX); + error.SetErrorString("timed out"); + return error; + } else { + // One or more descriptors were set, update the FDInfo::select_is_set mask + // so users can ask the SelectHelper class so clients can call one of: + + for (auto &pair : m_fd_map) { + const int fd = pair.first; + + if (pair.second.read_set) { + if (FD_ISSET(fd, read_fdset_ptr)) + pair.second.read_is_set = true; } - else if (num_set_fds == 0) - { - // Timeout - error.SetError(ETIMEDOUT, lldb::eErrorTypePOSIX); - error.SetErrorString("timed out"); - return error; + if (pair.second.write_set) { + if (FD_ISSET(fd, write_fdset_ptr)) + pair.second.write_is_set = true; } - else - { - // One or more descriptors were set, update the FDInfo::select_is_set mask - // so users can ask the SelectHelper class so clients can call one of: - - for (auto &pair : m_fd_map) - { - const int fd = pair.first; - - if (pair.second.read_set) - { - if (FD_ISSET(fd, read_fdset_ptr)) - pair.second.read_is_set = true; - } - if (pair.second.write_set) - { - if (FD_ISSET(fd, write_fdset_ptr)) - pair.second.write_is_set = true; - } - if (pair.second.error_set) - { - if (FD_ISSET(fd, error_fdset_ptr)) - pair.second.error_is_set = true; - } - } - break; + if (pair.second.error_set) { + if (FD_ISSET(fd, error_fdset_ptr)) + pair.second.error_is_set = true; } + } + break; } - return error; + } + return error; } diff --git a/lldb/source/Utility/SharingPtr.cpp b/lldb/source/Utility/SharingPtr.cpp index 7eedeb0..cf32b21 100644 --- a/lldb/source/Utility/SharingPtr.cpp +++ b/lldb/source/Utility/SharingPtr.cpp @@ -9,12 +9,12 @@ #include "lldb/Utility/SharingPtr.h" -#if defined (ENABLE_SP_LOGGING) +#if defined(ENABLE_SP_LOGGING) // If ENABLE_SP_LOGGING is defined, then log all shared pointer assignments // and allow them to be queried using a pointer by a call to: -#include <execinfo.h> #include <assert.h> +#include <execinfo.h> #include "llvm/ADT/STLExtras.h" @@ -22,147 +22,114 @@ #include <mutex> #include <vector> -class Backtrace -{ +class Backtrace { public: - Backtrace (); - - ~Backtrace (); - - void - GetFrames (); - - void - Dump () const; - + Backtrace(); + + ~Backtrace(); + + void GetFrames(); + + void Dump() const; + private: - void *m_sp_this; - std::vector<void *> m_frames; + void *m_sp_this; + std::vector<void *> m_frames; }; +Backtrace::Backtrace() : m_frames() {} -Backtrace::Backtrace () : m_frames() -{ -} - -Backtrace::~Backtrace () -{ -} +Backtrace::~Backtrace() {} -void -Backtrace::GetFrames () -{ - void *frames[1024]; - const int count = ::backtrace (frames, llvm::array_lengthof(frames)); - if (count > 2) - m_frames.assign (frames + 2, frames + (count - 2)); +void Backtrace::GetFrames() { + void *frames[1024]; + const int count = ::backtrace(frames, llvm::array_lengthof(frames)); + if (count > 2) + m_frames.assign(frames + 2, frames + (count - 2)); } -void -Backtrace::Dump () const -{ - if (!m_frames.empty()) - ::backtrace_symbols_fd (m_frames.data(), m_frames.size(), STDOUT_FILENO); - write (STDOUT_FILENO, "\n\n", 2); +void Backtrace::Dump() const { + if (!m_frames.empty()) + ::backtrace_symbols_fd(m_frames.data(), m_frames.size(), STDOUT_FILENO); + write(STDOUT_FILENO, "\n\n", 2); } -extern "C" void track_sp (void *sp_this, void *ptr, long use_count) -{ - typedef std::pair<void *, Backtrace> PtrBacktracePair; - typedef std::map<void *, PtrBacktracePair> PtrToBacktraceMap; - static std::mutex g_mutex; - std::lock_guard<std::mutex> guard(g_mutex); - static PtrToBacktraceMap g_map; - - if (sp_this) - { - printf ("sp(%p) -> %p %lu\n", sp_this, ptr, use_count); - - if (ptr) - { - Backtrace bt; - bt.GetFrames(); - g_map[sp_this] = std::make_pair(ptr, bt); - } - else - { - g_map.erase (sp_this); - } +extern "C" void track_sp(void *sp_this, void *ptr, long use_count) { + typedef std::pair<void *, Backtrace> PtrBacktracePair; + typedef std::map<void *, PtrBacktracePair> PtrToBacktraceMap; + static std::mutex g_mutex; + std::lock_guard<std::mutex> guard(g_mutex); + static PtrToBacktraceMap g_map; + + if (sp_this) { + printf("sp(%p) -> %p %lu\n", sp_this, ptr, use_count); + + if (ptr) { + Backtrace bt; + bt.GetFrames(); + g_map[sp_this] = std::make_pair(ptr, bt); + } else { + g_map.erase(sp_this); } - else - { - if (ptr) - printf ("Searching for shared pointers that are tracking %p: ", ptr); - else - printf ("Dump all live shared pointres: "); - - uint32_t matches = 0; - PtrToBacktraceMap::iterator pos, end = g_map.end(); - for (pos = g_map.begin(); pos != end; ++pos) - { - if (ptr == NULL || pos->second.first == ptr) - { - ++matches; - printf ("\nsp(%p): %p\n", pos->first, pos->second.first); - pos->second.second.Dump(); - } - } - if (matches == 0) - { - printf ("none.\n"); - } + } else { + if (ptr) + printf("Searching for shared pointers that are tracking %p: ", ptr); + else + printf("Dump all live shared pointres: "); + + uint32_t matches = 0; + PtrToBacktraceMap::iterator pos, end = g_map.end(); + for (pos = g_map.begin(); pos != end; ++pos) { + if (ptr == NULL || pos->second.first == ptr) { + ++matches; + printf("\nsp(%p): %p\n", pos->first, pos->second.first); + pos->second.second.Dump(); + } } + if (matches == 0) { + printf("none.\n"); + } + } } -// Put dump_sp_refs in the lldb namespace to it gets through our exports lists filter in the LLDB.framework or lldb.so +// Put dump_sp_refs in the lldb namespace to it gets through our exports lists +// filter in the LLDB.framework or lldb.so namespace lldb { - - void dump_sp_refs (void *ptr) - { - // Use a specially crafted call to "track_sp" which will - // dump info on all live shared pointers that reference "ptr" - track_sp (NULL, ptr, 0); - } - + +void dump_sp_refs(void *ptr) { + // Use a specially crafted call to "track_sp" which will + // dump info on all live shared pointers that reference "ptr" + track_sp(NULL, ptr, 0); +} } #endif namespace lldb_private { -namespace imp -{ +namespace imp { +shared_count::~shared_count() {} - shared_count::~shared_count() - { - } - - void - shared_count::add_shared() - { +void shared_count::add_shared() { #ifdef _MSC_VER - _InterlockedIncrement(&shared_owners_); + _InterlockedIncrement(&shared_owners_); #else - ++shared_owners_; + ++shared_owners_; #endif - } +} - void - shared_count::release_shared() - { +void shared_count::release_shared() { #ifdef _MSC_VER - if (_InterlockedDecrement(&shared_owners_) == -1) + if (_InterlockedDecrement(&shared_owners_) == -1) #else - if (--shared_owners_ == -1) + if (--shared_owners_ == -1) #endif - { - on_zero_shared(); - delete this; - } - } + { + on_zero_shared(); + delete this; + } +} } // imp - } // namespace lldb - diff --git a/lldb/source/Utility/StdStringExtractor.cpp b/lldb/source/Utility/StdStringExtractor.cpp index 5152f3e2..c439edd 100644 --- a/lldb/source/Utility/StdStringExtractor.cpp +++ b/lldb/source/Utility/StdStringExtractor.cpp @@ -16,81 +16,58 @@ // Other libraries and framework includes // Project includes -static inline int -xdigit_to_sint (char ch) -{ - if (ch >= 'a' && ch <= 'f') - return 10 + ch - 'a'; - if (ch >= 'A' && ch <= 'F') - return 10 + ch - 'A'; - if (ch >= '0' && ch <= '9') - return ch - '0'; - return -1; +static inline int xdigit_to_sint(char ch) { + if (ch >= 'a' && ch <= 'f') + return 10 + ch - 'a'; + if (ch >= 'A' && ch <= 'F') + return 10 + ch - 'A'; + if (ch >= '0' && ch <= '9') + return ch - '0'; + return -1; } //---------------------------------------------------------------------- // StdStringExtractor constructor //---------------------------------------------------------------------- -StdStringExtractor::StdStringExtractor() : - m_packet(), - m_index (0) -{ -} - +StdStringExtractor::StdStringExtractor() : m_packet(), m_index(0) {} -StdStringExtractor::StdStringExtractor(const char *packet_cstr) : - m_packet(), - m_index (0) -{ - if (packet_cstr) - m_packet.assign (packet_cstr); +StdStringExtractor::StdStringExtractor(const char *packet_cstr) + : m_packet(), m_index(0) { + if (packet_cstr) + m_packet.assign(packet_cstr); } - //---------------------------------------------------------------------- // StdStringExtractor copy constructor //---------------------------------------------------------------------- -StdStringExtractor::StdStringExtractor(const StdStringExtractor& rhs) : - m_packet (rhs.m_packet), - m_index (rhs.m_index) -{ - -} +StdStringExtractor::StdStringExtractor(const StdStringExtractor &rhs) + : m_packet(rhs.m_packet), m_index(rhs.m_index) {} //---------------------------------------------------------------------- // StdStringExtractor assignment operator //---------------------------------------------------------------------- -const StdStringExtractor& -StdStringExtractor::operator=(const StdStringExtractor& rhs) -{ - if (this != &rhs) - { - m_packet = rhs.m_packet; - m_index = rhs.m_index; - - } - return *this; +const StdStringExtractor &StdStringExtractor:: +operator=(const StdStringExtractor &rhs) { + if (this != &rhs) { + m_packet = rhs.m_packet; + m_index = rhs.m_index; + } + return *this; } //---------------------------------------------------------------------- // Destructor //---------------------------------------------------------------------- -StdStringExtractor::~StdStringExtractor() -{ -} - - -char -StdStringExtractor::GetChar (char fail_value) -{ - if (m_index < m_packet.size()) - { - char ch = m_packet[m_index]; - ++m_index; - return ch; - } - m_index = UINT64_MAX; - return fail_value; +StdStringExtractor::~StdStringExtractor() {} + +char StdStringExtractor::GetChar(char fail_value) { + if (m_index < m_packet.size()) { + char ch = m_packet[m_index]; + ++m_index; + return ch; + } + m_index = UINT64_MAX; + return fail_value; } //---------------------------------------------------------------------- @@ -101,274 +78,221 @@ StdStringExtractor::GetChar (char fail_value) // If there is not a pair of valid hex digits at the head of the // StdStringExtractor, it is left unchanged and -1 is returned //---------------------------------------------------------------------- -int -StdStringExtractor::DecodeHexU8() -{ - SkipSpaces(); - if (GetBytesLeft() < 2) - { - return -1; - } - const int hi_nibble = xdigit_to_sint(m_packet[m_index]); - const int lo_nibble = xdigit_to_sint(m_packet[m_index+1]); - if (hi_nibble == -1 || lo_nibble == -1) - { - return -1; - } - m_index += 2; - return (uint8_t)((hi_nibble << 4) + lo_nibble); +int StdStringExtractor::DecodeHexU8() { + SkipSpaces(); + if (GetBytesLeft() < 2) { + return -1; + } + const int hi_nibble = xdigit_to_sint(m_packet[m_index]); + const int lo_nibble = xdigit_to_sint(m_packet[m_index + 1]); + if (hi_nibble == -1 || lo_nibble == -1) { + return -1; + } + m_index += 2; + return (uint8_t)((hi_nibble << 4) + lo_nibble); } //---------------------------------------------------------------------- // Extract an unsigned character from two hex ASCII chars in the packet // string, or return fail_value on failure //---------------------------------------------------------------------- -uint8_t -StdStringExtractor::GetHexU8 (uint8_t fail_value, bool set_eof_on_fail) -{ - // On success, fail_value will be overwritten with the next - // character in the stream - GetHexU8Ex(fail_value, set_eof_on_fail); - return fail_value; +uint8_t StdStringExtractor::GetHexU8(uint8_t fail_value, bool set_eof_on_fail) { + // On success, fail_value will be overwritten with the next + // character in the stream + GetHexU8Ex(fail_value, set_eof_on_fail); + return fail_value; } -bool -StdStringExtractor::GetHexU8Ex (uint8_t& ch, bool set_eof_on_fail) -{ - int byte = DecodeHexU8(); - if (byte == -1) - { - if (set_eof_on_fail || m_index >= m_packet.size()) - m_index = UINT64_MAX; - // ch should not be changed in case of failure - return false; - } - ch = (uint8_t)byte; - return true; +bool StdStringExtractor::GetHexU8Ex(uint8_t &ch, bool set_eof_on_fail) { + int byte = DecodeHexU8(); + if (byte == -1) { + if (set_eof_on_fail || m_index >= m_packet.size()) + m_index = UINT64_MAX; + // ch should not be changed in case of failure + return false; + } + ch = (uint8_t)byte; + return true; } -uint32_t -StdStringExtractor::GetU32 (uint32_t fail_value, int base) -{ - if (m_index < m_packet.size()) - { - char *end = nullptr; - const char *start = m_packet.c_str(); - const char *cstr = start + m_index; - uint32_t result = static_cast<uint32_t>(::strtoul (cstr, &end, base)); - - if (end && end != cstr) - { - m_index = end - start; - return result; - } +uint32_t StdStringExtractor::GetU32(uint32_t fail_value, int base) { + if (m_index < m_packet.size()) { + char *end = nullptr; + const char *start = m_packet.c_str(); + const char *cstr = start + m_index; + uint32_t result = static_cast<uint32_t>(::strtoul(cstr, &end, base)); + + if (end && end != cstr) { + m_index = end - start; + return result; } - return fail_value; + } + return fail_value; } -int32_t -StdStringExtractor::GetS32 (int32_t fail_value, int base) -{ - if (m_index < m_packet.size()) - { - char *end = nullptr; - const char *start = m_packet.c_str(); - const char *cstr = start + m_index; - int32_t result = static_cast<int32_t>(::strtol (cstr, &end, base)); - - if (end && end != cstr) - { - m_index = end - start; - return result; - } +int32_t StdStringExtractor::GetS32(int32_t fail_value, int base) { + if (m_index < m_packet.size()) { + char *end = nullptr; + const char *start = m_packet.c_str(); + const char *cstr = start + m_index; + int32_t result = static_cast<int32_t>(::strtol(cstr, &end, base)); + + if (end && end != cstr) { + m_index = end - start; + return result; } - return fail_value; + } + return fail_value; } +uint64_t StdStringExtractor::GetU64(uint64_t fail_value, int base) { + if (m_index < m_packet.size()) { + char *end = nullptr; + const char *start = m_packet.c_str(); + const char *cstr = start + m_index; + uint64_t result = ::strtoull(cstr, &end, base); -uint64_t -StdStringExtractor::GetU64 (uint64_t fail_value, int base) -{ - if (m_index < m_packet.size()) - { - char *end = nullptr; - const char *start = m_packet.c_str(); - const char *cstr = start + m_index; - uint64_t result = ::strtoull (cstr, &end, base); - - if (end && end != cstr) - { - m_index = end - start; - return result; - } + if (end && end != cstr) { + m_index = end - start; + return result; } - return fail_value; + } + return fail_value; } -int64_t -StdStringExtractor::GetS64 (int64_t fail_value, int base) -{ - if (m_index < m_packet.size()) - { - char *end = nullptr; - const char *start = m_packet.c_str(); - const char *cstr = start + m_index; - int64_t result = ::strtoll (cstr, &end, base); - - if (end && end != cstr) - { - m_index = end - start; - return result; - } +int64_t StdStringExtractor::GetS64(int64_t fail_value, int base) { + if (m_index < m_packet.size()) { + char *end = nullptr; + const char *start = m_packet.c_str(); + const char *cstr = start + m_index; + int64_t result = ::strtoll(cstr, &end, base); + + if (end && end != cstr) { + m_index = end - start; + return result; } - return fail_value; + } + return fail_value; } - -uint32_t -StdStringExtractor::GetHexMaxU32 (bool little_endian, uint32_t fail_value) -{ - uint32_t result = 0; - uint32_t nibble_count = 0; - - SkipSpaces(); - if (little_endian) - { - uint32_t shift_amount = 0; - while (m_index < m_packet.size() && ::isxdigit (m_packet[m_index])) - { - // Make sure we don't exceed the size of a uint32_t... - if (nibble_count >= (sizeof(uint32_t) * 2)) - { - m_index = UINT64_MAX; - return fail_value; - } - - uint8_t nibble_lo; - uint8_t nibble_hi = xdigit_to_sint (m_packet[m_index]); - ++m_index; - if (m_index < m_packet.size() && ::isxdigit (m_packet[m_index])) - { - nibble_lo = xdigit_to_sint (m_packet[m_index]); - ++m_index; - result |= ((uint32_t)nibble_hi << (shift_amount + 4)); - result |= ((uint32_t)nibble_lo << shift_amount); - nibble_count += 2; - shift_amount += 8; - } - else - { - result |= ((uint32_t)nibble_hi << shift_amount); - nibble_count += 1; - shift_amount += 4; - } - - } +uint32_t StdStringExtractor::GetHexMaxU32(bool little_endian, + uint32_t fail_value) { + uint32_t result = 0; + uint32_t nibble_count = 0; + + SkipSpaces(); + if (little_endian) { + uint32_t shift_amount = 0; + while (m_index < m_packet.size() && ::isxdigit(m_packet[m_index])) { + // Make sure we don't exceed the size of a uint32_t... + if (nibble_count >= (sizeof(uint32_t) * 2)) { + m_index = UINT64_MAX; + return fail_value; + } + + uint8_t nibble_lo; + uint8_t nibble_hi = xdigit_to_sint(m_packet[m_index]); + ++m_index; + if (m_index < m_packet.size() && ::isxdigit(m_packet[m_index])) { + nibble_lo = xdigit_to_sint(m_packet[m_index]); + ++m_index; + result |= ((uint32_t)nibble_hi << (shift_amount + 4)); + result |= ((uint32_t)nibble_lo << shift_amount); + nibble_count += 2; + shift_amount += 8; + } else { + result |= ((uint32_t)nibble_hi << shift_amount); + nibble_count += 1; + shift_amount += 4; + } } - else - { - while (m_index < m_packet.size() && ::isxdigit (m_packet[m_index])) - { - // Make sure we don't exceed the size of a uint32_t... - if (nibble_count >= (sizeof(uint32_t) * 2)) - { - m_index = UINT64_MAX; - return fail_value; - } - - uint8_t nibble = xdigit_to_sint (m_packet[m_index]); - // Big Endian - result <<= 4; - result |= nibble; - - ++m_index; - ++nibble_count; - } + } else { + while (m_index < m_packet.size() && ::isxdigit(m_packet[m_index])) { + // Make sure we don't exceed the size of a uint32_t... + if (nibble_count >= (sizeof(uint32_t) * 2)) { + m_index = UINT64_MAX; + return fail_value; + } + + uint8_t nibble = xdigit_to_sint(m_packet[m_index]); + // Big Endian + result <<= 4; + result |= nibble; + + ++m_index; + ++nibble_count; } - return result; + } + return result; } -uint64_t -StdStringExtractor::GetHexMaxU64 (bool little_endian, uint64_t fail_value) -{ - uint64_t result = 0; - uint32_t nibble_count = 0; - - SkipSpaces(); - if (little_endian) - { - uint32_t shift_amount = 0; - while (m_index < m_packet.size() && ::isxdigit (m_packet[m_index])) - { - // Make sure we don't exceed the size of a uint64_t... - if (nibble_count >= (sizeof(uint64_t) * 2)) - { - m_index = UINT64_MAX; - return fail_value; - } - - uint8_t nibble_lo; - uint8_t nibble_hi = xdigit_to_sint (m_packet[m_index]); - ++m_index; - if (m_index < m_packet.size() && ::isxdigit (m_packet[m_index])) - { - nibble_lo = xdigit_to_sint (m_packet[m_index]); - ++m_index; - result |= ((uint64_t)nibble_hi << (shift_amount + 4)); - result |= ((uint64_t)nibble_lo << shift_amount); - nibble_count += 2; - shift_amount += 8; - } - else - { - result |= ((uint64_t)nibble_hi << shift_amount); - nibble_count += 1; - shift_amount += 4; - } - - } +uint64_t StdStringExtractor::GetHexMaxU64(bool little_endian, + uint64_t fail_value) { + uint64_t result = 0; + uint32_t nibble_count = 0; + + SkipSpaces(); + if (little_endian) { + uint32_t shift_amount = 0; + while (m_index < m_packet.size() && ::isxdigit(m_packet[m_index])) { + // Make sure we don't exceed the size of a uint64_t... + if (nibble_count >= (sizeof(uint64_t) * 2)) { + m_index = UINT64_MAX; + return fail_value; + } + + uint8_t nibble_lo; + uint8_t nibble_hi = xdigit_to_sint(m_packet[m_index]); + ++m_index; + if (m_index < m_packet.size() && ::isxdigit(m_packet[m_index])) { + nibble_lo = xdigit_to_sint(m_packet[m_index]); + ++m_index; + result |= ((uint64_t)nibble_hi << (shift_amount + 4)); + result |= ((uint64_t)nibble_lo << shift_amount); + nibble_count += 2; + shift_amount += 8; + } else { + result |= ((uint64_t)nibble_hi << shift_amount); + nibble_count += 1; + shift_amount += 4; + } } - else - { - while (m_index < m_packet.size() && ::isxdigit (m_packet[m_index])) - { - // Make sure we don't exceed the size of a uint64_t... - if (nibble_count >= (sizeof(uint64_t) * 2)) - { - m_index = UINT64_MAX; - return fail_value; - } - - uint8_t nibble = xdigit_to_sint (m_packet[m_index]); - // Big Endian - result <<= 4; - result |= nibble; - - ++m_index; - ++nibble_count; - } + } else { + while (m_index < m_packet.size() && ::isxdigit(m_packet[m_index])) { + // Make sure we don't exceed the size of a uint64_t... + if (nibble_count >= (sizeof(uint64_t) * 2)) { + m_index = UINT64_MAX; + return fail_value; + } + + uint8_t nibble = xdigit_to_sint(m_packet[m_index]); + // Big Endian + result <<= 4; + result |= nibble; + + ++m_index; + ++nibble_count; } - return result; + } + return result; } -size_t -StdStringExtractor::GetHexBytes (void *dst_void, size_t dst_len, uint8_t fail_fill_value) -{ - uint8_t *dst = (uint8_t*)dst_void; - size_t bytes_extracted = 0; - while (bytes_extracted < dst_len && GetBytesLeft ()) - { - dst[bytes_extracted] = GetHexU8 (fail_fill_value); - if (IsGood()) - ++bytes_extracted; - else - break; - } +size_t StdStringExtractor::GetHexBytes(void *dst_void, size_t dst_len, + uint8_t fail_fill_value) { + uint8_t *dst = (uint8_t *)dst_void; + size_t bytes_extracted = 0; + while (bytes_extracted < dst_len && GetBytesLeft()) { + dst[bytes_extracted] = GetHexU8(fail_fill_value); + if (IsGood()) + ++bytes_extracted; + else + break; + } - for (size_t i = bytes_extracted; i < dst_len; ++i) - dst[i] = fail_fill_value; + for (size_t i = bytes_extracted; i < dst_len; ++i) + dst[i] = fail_fill_value; - return bytes_extracted; + return bytes_extracted; } //---------------------------------------------------------------------- @@ -377,126 +301,105 @@ StdStringExtractor::GetHexBytes (void *dst_void, size_t dst_len, uint8_t fail_fi // // Returns the number of bytes successfully decoded //---------------------------------------------------------------------- -size_t -StdStringExtractor::GetHexBytesAvail (void *dst_void, size_t dst_len) -{ - uint8_t *dst = (uint8_t*)dst_void; - size_t bytes_extracted = 0; - while (bytes_extracted < dst_len) - { - int decode = DecodeHexU8(); - if (decode == -1) - { - break; - } - dst[bytes_extracted++] = (uint8_t)decode; +size_t StdStringExtractor::GetHexBytesAvail(void *dst_void, size_t dst_len) { + uint8_t *dst = (uint8_t *)dst_void; + size_t bytes_extracted = 0; + while (bytes_extracted < dst_len) { + int decode = DecodeHexU8(); + if (decode == -1) { + break; } - return bytes_extracted; + dst[bytes_extracted++] = (uint8_t)decode; + } + return bytes_extracted; } // Consume ASCII hex nibble character pairs until we have decoded byte_size // bytes of data. -uint64_t -StdStringExtractor::GetHexWithFixedSize (uint32_t byte_size, bool little_endian, uint64_t fail_value) -{ - if (byte_size <= 8 && GetBytesLeft() >= byte_size * 2) - { - uint64_t result = 0; - uint32_t i; - if (little_endian) - { - // Little Endian - uint32_t shift_amount; - for (i = 0, shift_amount = 0; - i < byte_size && IsGood(); - ++i, shift_amount += 8) - { - result |= ((uint64_t)GetHexU8() << shift_amount); - } - } - else - { - // Big Endian - for (i = 0; i < byte_size && IsGood(); ++i) - { - result <<= 8; - result |= GetHexU8(); - } - } +uint64_t StdStringExtractor::GetHexWithFixedSize(uint32_t byte_size, + bool little_endian, + uint64_t fail_value) { + if (byte_size <= 8 && GetBytesLeft() >= byte_size * 2) { + uint64_t result = 0; + uint32_t i; + if (little_endian) { + // Little Endian + uint32_t shift_amount; + for (i = 0, shift_amount = 0; i < byte_size && IsGood(); + ++i, shift_amount += 8) { + result |= ((uint64_t)GetHexU8() << shift_amount); + } + } else { + // Big Endian + for (i = 0; i < byte_size && IsGood(); ++i) { + result <<= 8; + result |= GetHexU8(); + } } - m_index = UINT64_MAX; - return fail_value; + } + m_index = UINT64_MAX; + return fail_value; } -size_t -StdStringExtractor::GetHexByteString (std::string &str) -{ - str.clear(); - str.reserve(GetBytesLeft() / 2); - char ch; - while ((ch = GetHexU8()) != '\0') - str.append(1, ch); - return str.size(); +size_t StdStringExtractor::GetHexByteString(std::string &str) { + str.clear(); + str.reserve(GetBytesLeft() / 2); + char ch; + while ((ch = GetHexU8()) != '\0') + str.append(1, ch); + return str.size(); } -size_t -StdStringExtractor::GetHexByteStringFixedLength (std::string &str, uint32_t nibble_length) -{ - str.clear(); +size_t StdStringExtractor::GetHexByteStringFixedLength(std::string &str, + uint32_t nibble_length) { + str.clear(); - uint32_t nibble_count = 0; - for (const char *pch = Peek(); (nibble_count < nibble_length) && (pch != nullptr); str.append(1, GetHexU8(0, false)), pch = Peek (), nibble_count += 2) - {} + uint32_t nibble_count = 0; + for (const char *pch = Peek(); + (nibble_count < nibble_length) && (pch != nullptr); + str.append(1, GetHexU8(0, false)), pch = Peek(), nibble_count += 2) { + } - return str.size(); + return str.size(); } -size_t -StdStringExtractor::GetHexByteStringTerminatedBy (std::string &str, - char terminator) -{ - str.clear(); - char ch; - while ((ch = GetHexU8(0,false)) != '\0') - str.append(1, ch); - if (Peek() && *Peek() == terminator) - return str.size(); - - str.clear(); +size_t StdStringExtractor::GetHexByteStringTerminatedBy(std::string &str, + char terminator) { + str.clear(); + char ch; + while ((ch = GetHexU8(0, false)) != '\0') + str.append(1, ch); + if (Peek() && *Peek() == terminator) return str.size(); + + str.clear(); + return str.size(); } -bool -StdStringExtractor::GetNameColonValue (std::string &name, std::string &value) -{ - // Read something in the form of NNNN:VVVV; where NNNN is any character - // that is not a colon, followed by a ':' character, then a value (one or - // more ';' chars), followed by a ';' - if (m_index < m_packet.size()) - { - const size_t colon_idx = m_packet.find (':', m_index); - if (colon_idx != std::string::npos) - { - const size_t semicolon_idx = m_packet.find (';', colon_idx); - if (semicolon_idx != std::string::npos) - { - name.assign (m_packet, m_index, colon_idx - m_index); - value.assign (m_packet, colon_idx + 1, semicolon_idx - (colon_idx + 1)); - m_index = semicolon_idx + 1; - return true; - } - } +bool StdStringExtractor::GetNameColonValue(std::string &name, + std::string &value) { + // Read something in the form of NNNN:VVVV; where NNNN is any character + // that is not a colon, followed by a ':' character, then a value (one or + // more ';' chars), followed by a ';' + if (m_index < m_packet.size()) { + const size_t colon_idx = m_packet.find(':', m_index); + if (colon_idx != std::string::npos) { + const size_t semicolon_idx = m_packet.find(';', colon_idx); + if (semicolon_idx != std::string::npos) { + name.assign(m_packet, m_index, colon_idx - m_index); + value.assign(m_packet, colon_idx + 1, semicolon_idx - (colon_idx + 1)); + m_index = semicolon_idx + 1; + return true; + } } - m_index = UINT64_MAX; - return false; + } + m_index = UINT64_MAX; + return false; } -void -StdStringExtractor::SkipSpaces () -{ - const size_t n = m_packet.size(); - while (m_index < n && isspace(m_packet[m_index])) - ++m_index; +void StdStringExtractor::SkipSpaces() { + const size_t n = m_packet.size(); + while (m_index < n && isspace(m_packet[m_index])) + ++m_index; } - diff --git a/lldb/source/Utility/StringExtractor.cpp b/lldb/source/Utility/StringExtractor.cpp index f62c836..d8ba397 100644 --- a/lldb/source/Utility/StringExtractor.cpp +++ b/lldb/source/Utility/StringExtractor.cpp @@ -17,85 +17,62 @@ // Other libraries and framework includes // Project includes -static inline int -xdigit_to_sint (char ch) -{ - if (ch >= 'a' && ch <= 'f') - return 10 + ch - 'a'; - if (ch >= 'A' && ch <= 'F') - return 10 + ch - 'A'; - if (ch >= '0' && ch <= '9') - return ch - '0'; - return -1; +static inline int xdigit_to_sint(char ch) { + if (ch >= 'a' && ch <= 'f') + return 10 + ch - 'a'; + if (ch >= 'A' && ch <= 'F') + return 10 + ch - 'A'; + if (ch >= '0' && ch <= '9') + return ch - '0'; + return -1; } //---------------------------------------------------------------------- // StringExtractor constructor //---------------------------------------------------------------------- -StringExtractor::StringExtractor() : - m_packet(), - m_index (0) -{ -} +StringExtractor::StringExtractor() : m_packet(), m_index(0) {} -StringExtractor::StringExtractor(llvm::StringRef packet_str) : m_packet(), m_index(0) -{ - m_packet.assign(packet_str.begin(), packet_str.end()); +StringExtractor::StringExtractor(llvm::StringRef packet_str) + : m_packet(), m_index(0) { + m_packet.assign(packet_str.begin(), packet_str.end()); } -StringExtractor::StringExtractor(const char *packet_cstr) : - m_packet(), - m_index (0) -{ - if (packet_cstr) - m_packet.assign (packet_cstr); +StringExtractor::StringExtractor(const char *packet_cstr) + : m_packet(), m_index(0) { + if (packet_cstr) + m_packet.assign(packet_cstr); } - //---------------------------------------------------------------------- // StringExtractor copy constructor //---------------------------------------------------------------------- -StringExtractor::StringExtractor(const StringExtractor& rhs) : - m_packet (rhs.m_packet), - m_index (rhs.m_index) -{ - -} +StringExtractor::StringExtractor(const StringExtractor &rhs) + : m_packet(rhs.m_packet), m_index(rhs.m_index) {} //---------------------------------------------------------------------- // StringExtractor assignment operator //---------------------------------------------------------------------- -const StringExtractor& -StringExtractor::operator=(const StringExtractor& rhs) -{ - if (this != &rhs) - { - m_packet = rhs.m_packet; - m_index = rhs.m_index; - - } - return *this; +const StringExtractor &StringExtractor::operator=(const StringExtractor &rhs) { + if (this != &rhs) { + m_packet = rhs.m_packet; + m_index = rhs.m_index; + } + return *this; } //---------------------------------------------------------------------- // Destructor //---------------------------------------------------------------------- -StringExtractor::~StringExtractor() -{ -} - - -char -StringExtractor::GetChar (char fail_value) -{ - if (m_index < m_packet.size()) - { - char ch = m_packet[m_index]; - ++m_index; - return ch; - } - m_index = UINT64_MAX; - return fail_value; +StringExtractor::~StringExtractor() {} + +char StringExtractor::GetChar(char fail_value) { + if (m_index < m_packet.size()) { + char ch = m_packet[m_index]; + ++m_index; + return ch; + } + m_index = UINT64_MAX; + return fail_value; } //---------------------------------------------------------------------- @@ -106,273 +83,220 @@ StringExtractor::GetChar (char fail_value) // If there is not a pair of valid hex digits at the head of the // StringExtractor, it is left unchanged and -1 is returned //---------------------------------------------------------------------- -int -StringExtractor::DecodeHexU8() -{ - SkipSpaces(); - if (GetBytesLeft() < 2) - { - return -1; - } - const int hi_nibble = xdigit_to_sint(m_packet[m_index]); - const int lo_nibble = xdigit_to_sint(m_packet[m_index+1]); - if (hi_nibble == -1 || lo_nibble == -1) - { - return -1; - } - m_index += 2; - return (uint8_t)((hi_nibble << 4) + lo_nibble); +int StringExtractor::DecodeHexU8() { + SkipSpaces(); + if (GetBytesLeft() < 2) { + return -1; + } + const int hi_nibble = xdigit_to_sint(m_packet[m_index]); + const int lo_nibble = xdigit_to_sint(m_packet[m_index + 1]); + if (hi_nibble == -1 || lo_nibble == -1) { + return -1; + } + m_index += 2; + return (uint8_t)((hi_nibble << 4) + lo_nibble); } //---------------------------------------------------------------------- // Extract an unsigned character from two hex ASCII chars in the packet // string, or return fail_value on failure //---------------------------------------------------------------------- -uint8_t -StringExtractor::GetHexU8 (uint8_t fail_value, bool set_eof_on_fail) -{ - // On success, fail_value will be overwritten with the next - // character in the stream - GetHexU8Ex(fail_value, set_eof_on_fail); - return fail_value; +uint8_t StringExtractor::GetHexU8(uint8_t fail_value, bool set_eof_on_fail) { + // On success, fail_value will be overwritten with the next + // character in the stream + GetHexU8Ex(fail_value, set_eof_on_fail); + return fail_value; } -bool -StringExtractor::GetHexU8Ex (uint8_t& ch, bool set_eof_on_fail) -{ - int byte = DecodeHexU8(); - if (byte == -1) - { - if (set_eof_on_fail || m_index >= m_packet.size()) - m_index = UINT64_MAX; - // ch should not be changed in case of failure - return false; - } - ch = (uint8_t)byte; - return true; +bool StringExtractor::GetHexU8Ex(uint8_t &ch, bool set_eof_on_fail) { + int byte = DecodeHexU8(); + if (byte == -1) { + if (set_eof_on_fail || m_index >= m_packet.size()) + m_index = UINT64_MAX; + // ch should not be changed in case of failure + return false; + } + ch = (uint8_t)byte; + return true; } -uint32_t -StringExtractor::GetU32 (uint32_t fail_value, int base) -{ - if (m_index < m_packet.size()) - { - char *end = nullptr; - const char *start = m_packet.c_str(); - const char *cstr = start + m_index; - uint32_t result = static_cast<uint32_t>(::strtoul (cstr, &end, base)); - - if (end && end != cstr) - { - m_index = end - start; - return result; - } - } - return fail_value; -} +uint32_t StringExtractor::GetU32(uint32_t fail_value, int base) { + if (m_index < m_packet.size()) { + char *end = nullptr; + const char *start = m_packet.c_str(); + const char *cstr = start + m_index; + uint32_t result = static_cast<uint32_t>(::strtoul(cstr, &end, base)); -int32_t -StringExtractor::GetS32 (int32_t fail_value, int base) -{ - if (m_index < m_packet.size()) - { - char *end = nullptr; - const char *start = m_packet.c_str(); - const char *cstr = start + m_index; - int32_t result = static_cast<int32_t>(::strtol (cstr, &end, base)); - - if (end && end != cstr) - { - m_index = end - start; - return result; - } + if (end && end != cstr) { + m_index = end - start; + return result; } - return fail_value; + } + return fail_value; } +int32_t StringExtractor::GetS32(int32_t fail_value, int base) { + if (m_index < m_packet.size()) { + char *end = nullptr; + const char *start = m_packet.c_str(); + const char *cstr = start + m_index; + int32_t result = static_cast<int32_t>(::strtol(cstr, &end, base)); -uint64_t -StringExtractor::GetU64 (uint64_t fail_value, int base) -{ - if (m_index < m_packet.size()) - { - char *end = nullptr; - const char *start = m_packet.c_str(); - const char *cstr = start + m_index; - uint64_t result = ::strtoull (cstr, &end, base); - - if (end && end != cstr) - { - m_index = end - start; - return result; - } + if (end && end != cstr) { + m_index = end - start; + return result; } - return fail_value; + } + return fail_value; } -int64_t -StringExtractor::GetS64 (int64_t fail_value, int base) -{ - if (m_index < m_packet.size()) - { - char *end = nullptr; - const char *start = m_packet.c_str(); - const char *cstr = start + m_index; - int64_t result = ::strtoll (cstr, &end, base); - - if (end && end != cstr) - { - m_index = end - start; - return result; - } +uint64_t StringExtractor::GetU64(uint64_t fail_value, int base) { + if (m_index < m_packet.size()) { + char *end = nullptr; + const char *start = m_packet.c_str(); + const char *cstr = start + m_index; + uint64_t result = ::strtoull(cstr, &end, base); + + if (end && end != cstr) { + m_index = end - start; + return result; } - return fail_value; + } + return fail_value; } +int64_t StringExtractor::GetS64(int64_t fail_value, int base) { + if (m_index < m_packet.size()) { + char *end = nullptr; + const char *start = m_packet.c_str(); + const char *cstr = start + m_index; + int64_t result = ::strtoll(cstr, &end, base); -uint32_t -StringExtractor::GetHexMaxU32 (bool little_endian, uint32_t fail_value) -{ - uint32_t result = 0; - uint32_t nibble_count = 0; - - SkipSpaces(); - if (little_endian) - { - uint32_t shift_amount = 0; - while (m_index < m_packet.size() && ::isxdigit (m_packet[m_index])) - { - // Make sure we don't exceed the size of a uint32_t... - if (nibble_count >= (sizeof(uint32_t) * 2)) - { - m_index = UINT64_MAX; - return fail_value; - } - - uint8_t nibble_lo; - uint8_t nibble_hi = xdigit_to_sint (m_packet[m_index]); - ++m_index; - if (m_index < m_packet.size() && ::isxdigit (m_packet[m_index])) - { - nibble_lo = xdigit_to_sint (m_packet[m_index]); - ++m_index; - result |= ((uint32_t)nibble_hi << (shift_amount + 4)); - result |= ((uint32_t)nibble_lo << shift_amount); - nibble_count += 2; - shift_amount += 8; - } - else - { - result |= ((uint32_t)nibble_hi << shift_amount); - nibble_count += 1; - shift_amount += 4; - } - - } - } - else - { - while (m_index < m_packet.size() && ::isxdigit (m_packet[m_index])) - { - // Make sure we don't exceed the size of a uint32_t... - if (nibble_count >= (sizeof(uint32_t) * 2)) - { - m_index = UINT64_MAX; - return fail_value; - } - - uint8_t nibble = xdigit_to_sint (m_packet[m_index]); - // Big Endian - result <<= 4; - result |= nibble; - - ++m_index; - ++nibble_count; - } + if (end && end != cstr) { + m_index = end - start; + return result; } - return result; + } + return fail_value; } -uint64_t -StringExtractor::GetHexMaxU64 (bool little_endian, uint64_t fail_value) -{ - uint64_t result = 0; - uint32_t nibble_count = 0; - - SkipSpaces(); - if (little_endian) - { - uint32_t shift_amount = 0; - while (m_index < m_packet.size() && ::isxdigit (m_packet[m_index])) - { - // Make sure we don't exceed the size of a uint64_t... - if (nibble_count >= (sizeof(uint64_t) * 2)) - { - m_index = UINT64_MAX; - return fail_value; - } - - uint8_t nibble_lo; - uint8_t nibble_hi = xdigit_to_sint (m_packet[m_index]); - ++m_index; - if (m_index < m_packet.size() && ::isxdigit (m_packet[m_index])) - { - nibble_lo = xdigit_to_sint (m_packet[m_index]); - ++m_index; - result |= ((uint64_t)nibble_hi << (shift_amount + 4)); - result |= ((uint64_t)nibble_lo << shift_amount); - nibble_count += 2; - shift_amount += 8; - } - else - { - result |= ((uint64_t)nibble_hi << shift_amount); - nibble_count += 1; - shift_amount += 4; - } - - } +uint32_t StringExtractor::GetHexMaxU32(bool little_endian, + uint32_t fail_value) { + uint32_t result = 0; + uint32_t nibble_count = 0; + + SkipSpaces(); + if (little_endian) { + uint32_t shift_amount = 0; + while (m_index < m_packet.size() && ::isxdigit(m_packet[m_index])) { + // Make sure we don't exceed the size of a uint32_t... + if (nibble_count >= (sizeof(uint32_t) * 2)) { + m_index = UINT64_MAX; + return fail_value; + } + + uint8_t nibble_lo; + uint8_t nibble_hi = xdigit_to_sint(m_packet[m_index]); + ++m_index; + if (m_index < m_packet.size() && ::isxdigit(m_packet[m_index])) { + nibble_lo = xdigit_to_sint(m_packet[m_index]); + ++m_index; + result |= ((uint32_t)nibble_hi << (shift_amount + 4)); + result |= ((uint32_t)nibble_lo << shift_amount); + nibble_count += 2; + shift_amount += 8; + } else { + result |= ((uint32_t)nibble_hi << shift_amount); + nibble_count += 1; + shift_amount += 4; + } } - else - { - while (m_index < m_packet.size() && ::isxdigit (m_packet[m_index])) - { - // Make sure we don't exceed the size of a uint64_t... - if (nibble_count >= (sizeof(uint64_t) * 2)) - { - m_index = UINT64_MAX; - return fail_value; - } - - uint8_t nibble = xdigit_to_sint (m_packet[m_index]); - // Big Endian - result <<= 4; - result |= nibble; - - ++m_index; - ++nibble_count; - } + } else { + while (m_index < m_packet.size() && ::isxdigit(m_packet[m_index])) { + // Make sure we don't exceed the size of a uint32_t... + if (nibble_count >= (sizeof(uint32_t) * 2)) { + m_index = UINT64_MAX; + return fail_value; + } + + uint8_t nibble = xdigit_to_sint(m_packet[m_index]); + // Big Endian + result <<= 4; + result |= nibble; + + ++m_index; + ++nibble_count; } - return result; + } + return result; } -size_t -StringExtractor::GetHexBytes (llvm::MutableArrayRef<uint8_t> dest, uint8_t fail_fill_value) -{ - size_t bytes_extracted = 0; - while (!dest.empty() && GetBytesLeft() > 0) - { - dest[0] = GetHexU8 (fail_fill_value); - if (!IsGood()) - break; - ++bytes_extracted; - dest = dest.drop_front(); +uint64_t StringExtractor::GetHexMaxU64(bool little_endian, + uint64_t fail_value) { + uint64_t result = 0; + uint32_t nibble_count = 0; + + SkipSpaces(); + if (little_endian) { + uint32_t shift_amount = 0; + while (m_index < m_packet.size() && ::isxdigit(m_packet[m_index])) { + // Make sure we don't exceed the size of a uint64_t... + if (nibble_count >= (sizeof(uint64_t) * 2)) { + m_index = UINT64_MAX; + return fail_value; + } + + uint8_t nibble_lo; + uint8_t nibble_hi = xdigit_to_sint(m_packet[m_index]); + ++m_index; + if (m_index < m_packet.size() && ::isxdigit(m_packet[m_index])) { + nibble_lo = xdigit_to_sint(m_packet[m_index]); + ++m_index; + result |= ((uint64_t)nibble_hi << (shift_amount + 4)); + result |= ((uint64_t)nibble_lo << shift_amount); + nibble_count += 2; + shift_amount += 8; + } else { + result |= ((uint64_t)nibble_hi << shift_amount); + nibble_count += 1; + shift_amount += 4; + } } + } else { + while (m_index < m_packet.size() && ::isxdigit(m_packet[m_index])) { + // Make sure we don't exceed the size of a uint64_t... + if (nibble_count >= (sizeof(uint64_t) * 2)) { + m_index = UINT64_MAX; + return fail_value; + } + + uint8_t nibble = xdigit_to_sint(m_packet[m_index]); + // Big Endian + result <<= 4; + result |= nibble; + + ++m_index; + ++nibble_count; + } + } + return result; +} - if (!dest.empty()) - ::memset(dest.data(), fail_fill_value, dest.size()); - - return bytes_extracted; +size_t StringExtractor::GetHexBytes(llvm::MutableArrayRef<uint8_t> dest, + uint8_t fail_fill_value) { + size_t bytes_extracted = 0; + while (!dest.empty() && GetBytesLeft() > 0) { + dest[0] = GetHexU8(fail_fill_value); + if (!IsGood()) + break; + ++bytes_extracted; + dest = dest.drop_front(); + } + + if (!dest.empty()) + ::memset(dest.data(), fail_fill_value, dest.size()); + + return bytes_extracted; } //---------------------------------------------------------------------- @@ -381,134 +305,116 @@ StringExtractor::GetHexBytes (llvm::MutableArrayRef<uint8_t> dest, uint8_t fail_ // // Returns the number of bytes successfully decoded //---------------------------------------------------------------------- -size_t -StringExtractor::GetHexBytesAvail (llvm::MutableArrayRef<uint8_t> dest) -{ - size_t bytes_extracted = 0; - while (!dest.empty()) - { - int decode = DecodeHexU8(); - if (decode == -1) - break; - dest[0] = (uint8_t)decode; - dest = dest.drop_front(); - ++bytes_extracted; - } - return bytes_extracted; +size_t StringExtractor::GetHexBytesAvail(llvm::MutableArrayRef<uint8_t> dest) { + size_t bytes_extracted = 0; + while (!dest.empty()) { + int decode = DecodeHexU8(); + if (decode == -1) + break; + dest[0] = (uint8_t)decode; + dest = dest.drop_front(); + ++bytes_extracted; + } + return bytes_extracted; } // Consume ASCII hex nibble character pairs until we have decoded byte_size // bytes of data. -uint64_t -StringExtractor::GetHexWithFixedSize (uint32_t byte_size, bool little_endian, uint64_t fail_value) -{ - if (byte_size <= 8 && GetBytesLeft() >= byte_size * 2) - { - uint64_t result = 0; - uint32_t i; - if (little_endian) - { - // Little Endian - uint32_t shift_amount; - for (i = 0, shift_amount = 0; - i < byte_size && IsGood(); - ++i, shift_amount += 8) - { - result |= ((uint64_t)GetHexU8() << shift_amount); - } - } - else - { - // Big Endian - for (i = 0; i < byte_size && IsGood(); ++i) - { - result <<= 8; - result |= GetHexU8(); - } - } +uint64_t StringExtractor::GetHexWithFixedSize(uint32_t byte_size, + bool little_endian, + uint64_t fail_value) { + if (byte_size <= 8 && GetBytesLeft() >= byte_size * 2) { + uint64_t result = 0; + uint32_t i; + if (little_endian) { + // Little Endian + uint32_t shift_amount; + for (i = 0, shift_amount = 0; i < byte_size && IsGood(); + ++i, shift_amount += 8) { + result |= ((uint64_t)GetHexU8() << shift_amount); + } + } else { + // Big Endian + for (i = 0; i < byte_size && IsGood(); ++i) { + result <<= 8; + result |= GetHexU8(); + } } - m_index = UINT64_MAX; - return fail_value; + } + m_index = UINT64_MAX; + return fail_value; } -size_t -StringExtractor::GetHexByteString (std::string &str) -{ - str.clear(); - str.reserve(GetBytesLeft() / 2); - char ch; - while ((ch = GetHexU8()) != '\0') - str.append(1, ch); - return str.size(); +size_t StringExtractor::GetHexByteString(std::string &str) { + str.clear(); + str.reserve(GetBytesLeft() / 2); + char ch; + while ((ch = GetHexU8()) != '\0') + str.append(1, ch); + return str.size(); } -size_t -StringExtractor::GetHexByteStringFixedLength (std::string &str, uint32_t nibble_length) -{ - str.clear(); +size_t StringExtractor::GetHexByteStringFixedLength(std::string &str, + uint32_t nibble_length) { + str.clear(); - uint32_t nibble_count = 0; - for (const char *pch = Peek(); (nibble_count < nibble_length) && (pch != nullptr); str.append(1, GetHexU8(0, false)), pch = Peek (), nibble_count += 2) - {} + uint32_t nibble_count = 0; + for (const char *pch = Peek(); + (nibble_count < nibble_length) && (pch != nullptr); + str.append(1, GetHexU8(0, false)), pch = Peek(), nibble_count += 2) { + } - return str.size(); + return str.size(); } -size_t -StringExtractor::GetHexByteStringTerminatedBy (std::string &str, - char terminator) -{ - str.clear(); - char ch; - while ((ch = GetHexU8(0,false)) != '\0') - str.append(1, ch); - if (Peek() && *Peek() == terminator) - return str.size(); - - str.clear(); +size_t StringExtractor::GetHexByteStringTerminatedBy(std::string &str, + char terminator) { + str.clear(); + char ch; + while ((ch = GetHexU8(0, false)) != '\0') + str.append(1, ch); + if (Peek() && *Peek() == terminator) return str.size(); -} -bool -StringExtractor::GetNameColonValue(llvm::StringRef &name, llvm::StringRef &value) -{ - // Read something in the form of NNNN:VVVV; where NNNN is any character - // that is not a colon, followed by a ':' character, then a value (one or - // more ';' chars), followed by a ';' - if (m_index >= m_packet.size()) - return fail(); - - llvm::StringRef view(m_packet); - if (view.empty()) - return fail(); - - llvm::StringRef a, b, c, d; - view = view.substr(m_index); - std::tie(a, b) = view.split(':'); - if (a.empty() || b.empty()) - return fail(); - std::tie(c, d) = b.split(';'); - if (b == c && d.empty()) - return fail(); - - name = a; - value = c; - if (d.empty()) - m_index = m_packet.size(); - else - { - size_t bytes_consumed = d.data() - view.data(); - m_index += bytes_consumed; - } - return true; + str.clear(); + return str.size(); } -void -StringExtractor::SkipSpaces () -{ - const size_t n = m_packet.size(); - while (m_index < n && isspace(m_packet[m_index])) - ++m_index; +bool StringExtractor::GetNameColonValue(llvm::StringRef &name, + llvm::StringRef &value) { + // Read something in the form of NNNN:VVVV; where NNNN is any character + // that is not a colon, followed by a ':' character, then a value (one or + // more ';' chars), followed by a ';' + if (m_index >= m_packet.size()) + return fail(); + + llvm::StringRef view(m_packet); + if (view.empty()) + return fail(); + + llvm::StringRef a, b, c, d; + view = view.substr(m_index); + std::tie(a, b) = view.split(':'); + if (a.empty() || b.empty()) + return fail(); + std::tie(c, d) = b.split(';'); + if (b == c && d.empty()) + return fail(); + + name = a; + value = c; + if (d.empty()) + m_index = m_packet.size(); + else { + size_t bytes_consumed = d.data() - view.data(); + m_index += bytes_consumed; + } + return true; } +void StringExtractor::SkipSpaces() { + const size_t n = m_packet.size(); + while (m_index < n && isspace(m_packet[m_index])) + ++m_index; +} diff --git a/lldb/source/Utility/StringExtractorGDBRemote.cpp b/lldb/source/Utility/StringExtractorGDBRemote.cpp index d2619af..c2f8f5a4 100644 --- a/lldb/source/Utility/StringExtractorGDBRemote.cpp +++ b/lldb/source/Utility/StringExtractorGDBRemote.cpp @@ -16,505 +16,550 @@ #include "Utility/StringExtractorGDBRemote.h" StringExtractorGDBRemote::ResponseType -StringExtractorGDBRemote::GetResponseType () const -{ - if (m_packet.empty()) - return eUnsupported; +StringExtractorGDBRemote::GetResponseType() const { + if (m_packet.empty()) + return eUnsupported; + + switch (m_packet[0]) { + case 'E': + if (m_packet.size() == 3 && isxdigit(m_packet[1]) && isxdigit(m_packet[2])) + return eError; + break; + + case 'O': + if (m_packet.size() == 2 && m_packet[1] == 'K') + return eOK; + break; + + case '+': + if (m_packet.size() == 1) + return eAck; + break; + + case '-': + if (m_packet.size() == 1) + return eNack; + break; + } + return eResponse; +} + +StringExtractorGDBRemote::ServerPacketType +StringExtractorGDBRemote::GetServerPacketType() const { +#define PACKET_MATCHES(s) \ + ((packet_size == (sizeof(s) - 1)) && (strcmp((packet_cstr), (s)) == 0)) +#define PACKET_STARTS_WITH(s) \ + ((packet_size >= (sizeof(s) - 1)) && \ + ::strncmp(packet_cstr, s, (sizeof(s) - 1)) == 0) + + // Empty is not a supported packet... + if (m_packet.empty()) + return eServerPacketType_invalid; + + const size_t packet_size = m_packet.size(); + const char *packet_cstr = m_packet.c_str(); + switch (m_packet[0]) { + + case '%': + return eServerPacketType_notify; + + case '\x03': + if (packet_size == 1) + return eServerPacketType_interrupt; + break; + + case '-': + if (packet_size == 1) + return eServerPacketType_nack; + break; + + case '+': + if (packet_size == 1) + return eServerPacketType_ack; + break; + + case 'A': + return eServerPacketType_A; + + case 'Q': - switch (m_packet[0]) - { + switch (packet_cstr[1]) { case 'E': - if (m_packet.size() == 3 && - isxdigit(m_packet[1]) && - isxdigit(m_packet[2])) - return eError; - break; - - case 'O': - if (m_packet.size() == 2 && m_packet[1] == 'K') - return eOK; - break; - - case '+': - if (m_packet.size() == 1) - return eAck; - break; - - case '-': - if (m_packet.size() == 1) - return eNack; - break; + if (PACKET_STARTS_WITH("QEnvironment:")) + return eServerPacketType_QEnvironment; + if (PACKET_STARTS_WITH("QEnvironmentHexEncoded:")) + return eServerPacketType_QEnvironmentHexEncoded; + break; + + case 'S': + if (PACKET_MATCHES("QStartNoAckMode")) + return eServerPacketType_QStartNoAckMode; + if (PACKET_STARTS_WITH("QSaveRegisterState")) + return eServerPacketType_QSaveRegisterState; + if (PACKET_STARTS_WITH("QSetDisableASLR:")) + return eServerPacketType_QSetDisableASLR; + if (PACKET_STARTS_WITH("QSetDetachOnError:")) + return eServerPacketType_QSetDetachOnError; + if (PACKET_STARTS_WITH("QSetSTDIN:")) + return eServerPacketType_QSetSTDIN; + if (PACKET_STARTS_WITH("QSetSTDOUT:")) + return eServerPacketType_QSetSTDOUT; + if (PACKET_STARTS_WITH("QSetSTDERR:")) + return eServerPacketType_QSetSTDERR; + if (PACKET_STARTS_WITH("QSetWorkingDir:")) + return eServerPacketType_QSetWorkingDir; + if (PACKET_STARTS_WITH("QSetLogging:")) + return eServerPacketType_QSetLogging; + if (PACKET_STARTS_WITH("QSetMaxPacketSize:")) + return eServerPacketType_QSetMaxPacketSize; + if (PACKET_STARTS_WITH("QSetMaxPayloadSize:")) + return eServerPacketType_QSetMaxPayloadSize; + if (PACKET_STARTS_WITH("QSetEnableAsyncProfiling;")) + return eServerPacketType_QSetEnableAsyncProfiling; + if (PACKET_STARTS_WITH("QSyncThreadState:")) + return eServerPacketType_QSyncThreadState; + break; + + case 'L': + if (PACKET_STARTS_WITH("QLaunchArch:")) + return eServerPacketType_QLaunchArch; + if (PACKET_MATCHES("QListThreadsInStopReply")) + return eServerPacketType_QListThreadsInStopReply; + break; + + case 'R': + if (PACKET_STARTS_WITH("QRestoreRegisterState:")) + return eServerPacketType_QRestoreRegisterState; + break; + + case 'T': + if (PACKET_MATCHES("QThreadSuffixSupported")) + return eServerPacketType_QThreadSuffixSupported; + break; } - return eResponse; -} + break; + + case 'q': + switch (packet_cstr[1]) { + case 's': + if (PACKET_MATCHES("qsProcessInfo")) + return eServerPacketType_qsProcessInfo; + if (PACKET_MATCHES("qsThreadInfo")) + return eServerPacketType_qsThreadInfo; + break; + + case 'f': + if (PACKET_STARTS_WITH("qfProcessInfo")) + return eServerPacketType_qfProcessInfo; + if (PACKET_STARTS_WITH("qfThreadInfo")) + return eServerPacketType_qfThreadInfo; + break; + + case 'C': + if (packet_size == 2) + return eServerPacketType_qC; + break; -StringExtractorGDBRemote::ServerPacketType -StringExtractorGDBRemote::GetServerPacketType () const -{ -#define PACKET_MATCHES(s) ((packet_size == (sizeof(s)-1)) && (strcmp((packet_cstr),(s)) == 0)) -#define PACKET_STARTS_WITH(s) ((packet_size >= (sizeof(s)-1)) && ::strncmp(packet_cstr, s, (sizeof(s)-1))==0) - - // Empty is not a supported packet... - if (m_packet.empty()) - return eServerPacketType_invalid; - - const size_t packet_size = m_packet.size(); - const char *packet_cstr = m_packet.c_str(); - switch (m_packet[0]) - { - - case '%': - return eServerPacketType_notify; - - case '\x03': - if (packet_size == 1) return eServerPacketType_interrupt; - break; - - case '-': - if (packet_size == 1) return eServerPacketType_nack; - break; - - case '+': - if (packet_size == 1) return eServerPacketType_ack; - break; - - case 'A': - return eServerPacketType_A; + case 'E': + if (PACKET_STARTS_WITH("qEcho:")) + return eServerPacketType_qEcho; + break; + + case 'F': + if (PACKET_STARTS_WITH("qFileLoadAddress:")) + return eServerPacketType_qFileLoadAddress; + break; + + case 'G': + if (PACKET_STARTS_WITH("qGroupName:")) + return eServerPacketType_qGroupName; + if (PACKET_MATCHES("qGetWorkingDir")) + return eServerPacketType_qGetWorkingDir; + if (PACKET_MATCHES("qGetPid")) + return eServerPacketType_qGetPid; + if (PACKET_STARTS_WITH("qGetProfileData;")) + return eServerPacketType_qGetProfileData; + if (PACKET_MATCHES("qGDBServerVersion")) + return eServerPacketType_qGDBServerVersion; + break; + + case 'H': + if (PACKET_MATCHES("qHostInfo")) + return eServerPacketType_qHostInfo; + break; + + case 'K': + if (PACKET_STARTS_WITH("qKillSpawnedProcess")) + return eServerPacketType_qKillSpawnedProcess; + break; + + case 'L': + if (PACKET_STARTS_WITH("qLaunchGDBServer")) + return eServerPacketType_qLaunchGDBServer; + if (PACKET_MATCHES("qLaunchSuccess")) + return eServerPacketType_qLaunchSuccess; + break; + + case 'M': + if (PACKET_STARTS_WITH("qMemoryRegionInfo:")) + return eServerPacketType_qMemoryRegionInfo; + if (PACKET_MATCHES("qMemoryRegionInfo")) + return eServerPacketType_qMemoryRegionInfoSupported; + if (PACKET_STARTS_WITH("qModuleInfo:")) + return eServerPacketType_qModuleInfo; + break; + + case 'P': + if (PACKET_STARTS_WITH("qProcessInfoPID:")) + return eServerPacketType_qProcessInfoPID; + if (PACKET_STARTS_WITH("qPlatform_shell:")) + return eServerPacketType_qPlatform_shell; + if (PACKET_STARTS_WITH("qPlatform_mkdir:")) + return eServerPacketType_qPlatform_mkdir; + if (PACKET_STARTS_WITH("qPlatform_chmod:")) + return eServerPacketType_qPlatform_chmod; + if (PACKET_MATCHES("qProcessInfo")) + return eServerPacketType_qProcessInfo; + break; case 'Q': - - switch (packet_cstr[1]) - { - case 'E': - if (PACKET_STARTS_WITH ("QEnvironment:")) return eServerPacketType_QEnvironment; - if (PACKET_STARTS_WITH ("QEnvironmentHexEncoded:")) return eServerPacketType_QEnvironmentHexEncoded; - break; - - case 'S': - if (PACKET_MATCHES ("QStartNoAckMode")) return eServerPacketType_QStartNoAckMode; - if (PACKET_STARTS_WITH ("QSaveRegisterState")) return eServerPacketType_QSaveRegisterState; - if (PACKET_STARTS_WITH ("QSetDisableASLR:")) return eServerPacketType_QSetDisableASLR; - if (PACKET_STARTS_WITH ("QSetDetachOnError:")) return eServerPacketType_QSetDetachOnError; - if (PACKET_STARTS_WITH ("QSetSTDIN:")) return eServerPacketType_QSetSTDIN; - if (PACKET_STARTS_WITH ("QSetSTDOUT:")) return eServerPacketType_QSetSTDOUT; - if (PACKET_STARTS_WITH ("QSetSTDERR:")) return eServerPacketType_QSetSTDERR; - if (PACKET_STARTS_WITH ("QSetWorkingDir:")) return eServerPacketType_QSetWorkingDir; - if (PACKET_STARTS_WITH ("QSetLogging:")) return eServerPacketType_QSetLogging; - if (PACKET_STARTS_WITH ("QSetMaxPacketSize:")) return eServerPacketType_QSetMaxPacketSize; - if (PACKET_STARTS_WITH ("QSetMaxPayloadSize:")) return eServerPacketType_QSetMaxPayloadSize; - if (PACKET_STARTS_WITH ("QSetEnableAsyncProfiling;")) return eServerPacketType_QSetEnableAsyncProfiling; - if (PACKET_STARTS_WITH ("QSyncThreadState:")) return eServerPacketType_QSyncThreadState; - break; - - case 'L': - if (PACKET_STARTS_WITH ("QLaunchArch:")) return eServerPacketType_QLaunchArch; - if (PACKET_MATCHES("QListThreadsInStopReply")) return eServerPacketType_QListThreadsInStopReply; - break; - - case 'R': - if (PACKET_STARTS_WITH ("QRestoreRegisterState:")) return eServerPacketType_QRestoreRegisterState; - break; - - case 'T': - if (PACKET_MATCHES ("QThreadSuffixSupported")) return eServerPacketType_QThreadSuffixSupported; - break; - } - break; - - case 'q': - switch (packet_cstr[1]) - { - case 's': - if (PACKET_MATCHES ("qsProcessInfo")) return eServerPacketType_qsProcessInfo; - if (PACKET_MATCHES ("qsThreadInfo")) return eServerPacketType_qsThreadInfo; - break; - - case 'f': - if (PACKET_STARTS_WITH ("qfProcessInfo")) return eServerPacketType_qfProcessInfo; - if (PACKET_STARTS_WITH ("qfThreadInfo")) return eServerPacketType_qfThreadInfo; - break; - - case 'C': - if (packet_size == 2) return eServerPacketType_qC; - break; - - case 'E': - if (PACKET_STARTS_WITH ("qEcho:")) return eServerPacketType_qEcho; - break; - - case 'F': - if (PACKET_STARTS_WITH ("qFileLoadAddress:")) return eServerPacketType_qFileLoadAddress; - break; - - case 'G': - if (PACKET_STARTS_WITH ("qGroupName:")) return eServerPacketType_qGroupName; - if (PACKET_MATCHES ("qGetWorkingDir")) return eServerPacketType_qGetWorkingDir; - if (PACKET_MATCHES ("qGetPid")) return eServerPacketType_qGetPid; - if (PACKET_STARTS_WITH ("qGetProfileData;")) return eServerPacketType_qGetProfileData; - if (PACKET_MATCHES ("qGDBServerVersion")) return eServerPacketType_qGDBServerVersion; - break; - - case 'H': - if (PACKET_MATCHES ("qHostInfo")) return eServerPacketType_qHostInfo; - break; - - case 'K': - if (PACKET_STARTS_WITH ("qKillSpawnedProcess")) return eServerPacketType_qKillSpawnedProcess; - break; - - case 'L': - if (PACKET_STARTS_WITH ("qLaunchGDBServer")) return eServerPacketType_qLaunchGDBServer; - if (PACKET_MATCHES ("qLaunchSuccess")) return eServerPacketType_qLaunchSuccess; - break; - - case 'M': - if (PACKET_STARTS_WITH ("qMemoryRegionInfo:")) return eServerPacketType_qMemoryRegionInfo; - if (PACKET_MATCHES ("qMemoryRegionInfo")) return eServerPacketType_qMemoryRegionInfoSupported; - if (PACKET_STARTS_WITH ("qModuleInfo:")) return eServerPacketType_qModuleInfo; - break; - - case 'P': - if (PACKET_STARTS_WITH ("qProcessInfoPID:")) return eServerPacketType_qProcessInfoPID; - if (PACKET_STARTS_WITH ("qPlatform_shell:")) return eServerPacketType_qPlatform_shell; - if (PACKET_STARTS_WITH ("qPlatform_mkdir:")) return eServerPacketType_qPlatform_mkdir; - if (PACKET_STARTS_WITH ("qPlatform_chmod:")) return eServerPacketType_qPlatform_chmod; - if (PACKET_MATCHES ("qProcessInfo")) return eServerPacketType_qProcessInfo; - break; - - case 'Q': - if (PACKET_MATCHES ("qQueryGDBServer")) return eServerPacketType_qQueryGDBServer; - break; - - case 'R': - if (PACKET_STARTS_WITH ("qRcmd,")) return eServerPacketType_qRcmd; - if (PACKET_STARTS_WITH ("qRegisterInfo")) return eServerPacketType_qRegisterInfo; - break; - - case 'S': - if (PACKET_STARTS_WITH ("qSpeedTest:")) return eServerPacketType_qSpeedTest; - if (PACKET_MATCHES ("qShlibInfoAddr")) return eServerPacketType_qShlibInfoAddr; - if (PACKET_MATCHES ("qStepPacketSupported")) return eServerPacketType_qStepPacketSupported; - if (PACKET_STARTS_WITH ("qSupported")) return eServerPacketType_qSupported; - if (PACKET_MATCHES ("qSyncThreadStateSupported")) return eServerPacketType_qSyncThreadStateSupported; - break; - - case 'T': - if (PACKET_STARTS_WITH ("qThreadExtraInfo,")) return eServerPacketType_qThreadExtraInfo; - if (PACKET_STARTS_WITH ("qThreadStopInfo")) return eServerPacketType_qThreadStopInfo; - break; - - case 'U': - if (PACKET_STARTS_WITH ("qUserName:")) return eServerPacketType_qUserName; - break; - - case 'V': - if (PACKET_MATCHES ("qVAttachOrWaitSupported")) return eServerPacketType_qVAttachOrWaitSupported; - break; - - case 'W': - if (PACKET_STARTS_WITH ("qWatchpointSupportInfo:")) return eServerPacketType_qWatchpointSupportInfo; - if (PACKET_MATCHES ("qWatchpointSupportInfo")) return eServerPacketType_qWatchpointSupportInfoSupported; - break; - - case 'X': - if (PACKET_STARTS_WITH ("qXfer:auxv:read::")) return eServerPacketType_qXfer_auxv_read; - break; - } - break; - - case 'j': - if (PACKET_MATCHES("jSignalsInfo")) return eServerPacketType_jSignalsInfo; - if (PACKET_MATCHES("jThreadsInfo")) return eServerPacketType_jThreadsInfo; - break; - - case 'v': - if (PACKET_STARTS_WITH("vFile:")) - { - if (PACKET_STARTS_WITH("vFile:open:")) return eServerPacketType_vFile_open; - else if (PACKET_STARTS_WITH("vFile:close:")) return eServerPacketType_vFile_close; - else if (PACKET_STARTS_WITH("vFile:pread")) return eServerPacketType_vFile_pread; - else if (PACKET_STARTS_WITH("vFile:pwrite")) return eServerPacketType_vFile_pwrite; - else if (PACKET_STARTS_WITH("vFile:size")) return eServerPacketType_vFile_size; - else if (PACKET_STARTS_WITH("vFile:exists")) return eServerPacketType_vFile_exists; - else if (PACKET_STARTS_WITH("vFile:stat")) return eServerPacketType_vFile_stat; - else if (PACKET_STARTS_WITH("vFile:mode")) return eServerPacketType_vFile_mode; - else if (PACKET_STARTS_WITH("vFile:MD5")) return eServerPacketType_vFile_md5; - else if (PACKET_STARTS_WITH("vFile:symlink")) return eServerPacketType_vFile_symlink; - else if (PACKET_STARTS_WITH("vFile:unlink")) return eServerPacketType_vFile_unlink; - - } else { - if (PACKET_STARTS_WITH ("vAttach;")) return eServerPacketType_vAttach; - if (PACKET_STARTS_WITH ("vAttachWait;")) return eServerPacketType_vAttachWait; - if (PACKET_STARTS_WITH ("vAttachOrWait;")) return eServerPacketType_vAttachOrWait; - if (PACKET_STARTS_WITH ("vAttachName;")) return eServerPacketType_vAttachName; - if (PACKET_STARTS_WITH("vCont;")) return eServerPacketType_vCont; - if (PACKET_MATCHES ("vCont?")) return eServerPacketType_vCont_actions; - } - break; - case '_': - switch (packet_cstr[1]) - { - case 'M': - return eServerPacketType__M; - - case 'm': - return eServerPacketType__m; - } - break; - - case '?': - if (packet_size == 1) return eServerPacketType_stop_reason; - break; - - case 'c': - return eServerPacketType_c; - - case 'C': - return eServerPacketType_C; - - case 'D': - if (packet_size == 1) return eServerPacketType_D; - break; - - case 'g': - if (packet_size == 1) return eServerPacketType_g; - break; - - case 'G': - return eServerPacketType_G; - - case 'H': - return eServerPacketType_H; - - case 'I': - return eServerPacketType_I; - - case 'k': - if (packet_size == 1) return eServerPacketType_k; - break; - - case 'm': - return eServerPacketType_m; - - case 'M': - return eServerPacketType_M; - - case 'p': - return eServerPacketType_p; - - case 'P': - return eServerPacketType_P; - - case 's': - if (packet_size == 1) return eServerPacketType_s; - break; - - case 'S': - return eServerPacketType_S; - - case 'x': - return eServerPacketType_x; - - case 'X': - return eServerPacketType_X; - - case 'T': - return eServerPacketType_T; - - case 'z': - if (packet_cstr[1] >= '0' && packet_cstr[1] <= '4') - return eServerPacketType_z; - break; - - case 'Z': - if (packet_cstr[1] >= '0' && packet_cstr[1] <= '4') - return eServerPacketType_Z; - break; + if (PACKET_MATCHES("qQueryGDBServer")) + return eServerPacketType_qQueryGDBServer; + break; + + case 'R': + if (PACKET_STARTS_WITH("qRcmd,")) + return eServerPacketType_qRcmd; + if (PACKET_STARTS_WITH("qRegisterInfo")) + return eServerPacketType_qRegisterInfo; + break; + + case 'S': + if (PACKET_STARTS_WITH("qSpeedTest:")) + return eServerPacketType_qSpeedTest; + if (PACKET_MATCHES("qShlibInfoAddr")) + return eServerPacketType_qShlibInfoAddr; + if (PACKET_MATCHES("qStepPacketSupported")) + return eServerPacketType_qStepPacketSupported; + if (PACKET_STARTS_WITH("qSupported")) + return eServerPacketType_qSupported; + if (PACKET_MATCHES("qSyncThreadStateSupported")) + return eServerPacketType_qSyncThreadStateSupported; + break; + + case 'T': + if (PACKET_STARTS_WITH("qThreadExtraInfo,")) + return eServerPacketType_qThreadExtraInfo; + if (PACKET_STARTS_WITH("qThreadStopInfo")) + return eServerPacketType_qThreadStopInfo; + break; + + case 'U': + if (PACKET_STARTS_WITH("qUserName:")) + return eServerPacketType_qUserName; + break; + + case 'V': + if (PACKET_MATCHES("qVAttachOrWaitSupported")) + return eServerPacketType_qVAttachOrWaitSupported; + break; + + case 'W': + if (PACKET_STARTS_WITH("qWatchpointSupportInfo:")) + return eServerPacketType_qWatchpointSupportInfo; + if (PACKET_MATCHES("qWatchpointSupportInfo")) + return eServerPacketType_qWatchpointSupportInfoSupported; + break; + + case 'X': + if (PACKET_STARTS_WITH("qXfer:auxv:read::")) + return eServerPacketType_qXfer_auxv_read; + break; } - return eServerPacketType_unimplemented; -} + break; + + case 'j': + if (PACKET_MATCHES("jSignalsInfo")) + return eServerPacketType_jSignalsInfo; + if (PACKET_MATCHES("jThreadsInfo")) + return eServerPacketType_jThreadsInfo; + break; + + case 'v': + if (PACKET_STARTS_WITH("vFile:")) { + if (PACKET_STARTS_WITH("vFile:open:")) + return eServerPacketType_vFile_open; + else if (PACKET_STARTS_WITH("vFile:close:")) + return eServerPacketType_vFile_close; + else if (PACKET_STARTS_WITH("vFile:pread")) + return eServerPacketType_vFile_pread; + else if (PACKET_STARTS_WITH("vFile:pwrite")) + return eServerPacketType_vFile_pwrite; + else if (PACKET_STARTS_WITH("vFile:size")) + return eServerPacketType_vFile_size; + else if (PACKET_STARTS_WITH("vFile:exists")) + return eServerPacketType_vFile_exists; + else if (PACKET_STARTS_WITH("vFile:stat")) + return eServerPacketType_vFile_stat; + else if (PACKET_STARTS_WITH("vFile:mode")) + return eServerPacketType_vFile_mode; + else if (PACKET_STARTS_WITH("vFile:MD5")) + return eServerPacketType_vFile_md5; + else if (PACKET_STARTS_WITH("vFile:symlink")) + return eServerPacketType_vFile_symlink; + else if (PACKET_STARTS_WITH("vFile:unlink")) + return eServerPacketType_vFile_unlink; + + } else { + if (PACKET_STARTS_WITH("vAttach;")) + return eServerPacketType_vAttach; + if (PACKET_STARTS_WITH("vAttachWait;")) + return eServerPacketType_vAttachWait; + if (PACKET_STARTS_WITH("vAttachOrWait;")) + return eServerPacketType_vAttachOrWait; + if (PACKET_STARTS_WITH("vAttachName;")) + return eServerPacketType_vAttachName; + if (PACKET_STARTS_WITH("vCont;")) + return eServerPacketType_vCont; + if (PACKET_MATCHES("vCont?")) + return eServerPacketType_vCont_actions; + } + break; + case '_': + switch (packet_cstr[1]) { + case 'M': + return eServerPacketType__M; + + case 'm': + return eServerPacketType__m; + } + break; + + case '?': + if (packet_size == 1) + return eServerPacketType_stop_reason; + break; + + case 'c': + return eServerPacketType_c; + + case 'C': + return eServerPacketType_C; + + case 'D': + if (packet_size == 1) + return eServerPacketType_D; + break; -bool -StringExtractorGDBRemote::IsOKResponse() const -{ - return GetResponseType () == eOK; + case 'g': + if (packet_size == 1) + return eServerPacketType_g; + break; + + case 'G': + return eServerPacketType_G; + + case 'H': + return eServerPacketType_H; + + case 'I': + return eServerPacketType_I; + + case 'k': + if (packet_size == 1) + return eServerPacketType_k; + break; + + case 'm': + return eServerPacketType_m; + + case 'M': + return eServerPacketType_M; + + case 'p': + return eServerPacketType_p; + + case 'P': + return eServerPacketType_P; + + case 's': + if (packet_size == 1) + return eServerPacketType_s; + break; + + case 'S': + return eServerPacketType_S; + + case 'x': + return eServerPacketType_x; + + case 'X': + return eServerPacketType_X; + + case 'T': + return eServerPacketType_T; + + case 'z': + if (packet_cstr[1] >= '0' && packet_cstr[1] <= '4') + return eServerPacketType_z; + break; + + case 'Z': + if (packet_cstr[1] >= '0' && packet_cstr[1] <= '4') + return eServerPacketType_Z; + break; + } + return eServerPacketType_unimplemented; } +bool StringExtractorGDBRemote::IsOKResponse() const { + return GetResponseType() == eOK; +} -bool -StringExtractorGDBRemote::IsUnsupportedResponse() const -{ - return GetResponseType () == eUnsupported; +bool StringExtractorGDBRemote::IsUnsupportedResponse() const { + return GetResponseType() == eUnsupported; } -bool -StringExtractorGDBRemote::IsNormalResponse() const -{ - return GetResponseType () == eResponse; +bool StringExtractorGDBRemote::IsNormalResponse() const { + return GetResponseType() == eResponse; } -bool -StringExtractorGDBRemote::IsErrorResponse() const -{ - return GetResponseType () == eError && - m_packet.size() == 3 && - isxdigit(m_packet[1]) && - isxdigit(m_packet[2]); +bool StringExtractorGDBRemote::IsErrorResponse() const { + return GetResponseType() == eError && m_packet.size() == 3 && + isxdigit(m_packet[1]) && isxdigit(m_packet[2]); } -uint8_t -StringExtractorGDBRemote::GetError () -{ - if (GetResponseType() == eError) - { - SetFilePos(1); - return GetHexU8(255); - } - return 0; +uint8_t StringExtractorGDBRemote::GetError() { + if (GetResponseType() == eError) { + SetFilePos(1); + return GetHexU8(255); + } + return 0; } -size_t -StringExtractorGDBRemote::GetEscapedBinaryData (std::string &str) -{ - // Just get the data bytes in the string as GDBRemoteCommunication::CheckForPacket() - // already removes any 0x7d escaped characters. If any 0x7d characters are left in - // the packet, then they are supposed to be there... - str.clear(); - const size_t bytes_left = GetBytesLeft(); - if (bytes_left > 0) - { - str.assign(m_packet, m_index, bytes_left); - m_index += bytes_left; - } - return str.size(); +size_t StringExtractorGDBRemote::GetEscapedBinaryData(std::string &str) { + // Just get the data bytes in the string as + // GDBRemoteCommunication::CheckForPacket() + // already removes any 0x7d escaped characters. If any 0x7d characters are + // left in + // the packet, then they are supposed to be there... + str.clear(); + const size_t bytes_left = GetBytesLeft(); + if (bytes_left > 0) { + str.assign(m_packet, m_index, bytes_left); + m_index += bytes_left; + } + return str.size(); } static bool -OKErrorNotSupportedResponseValidator(void *, const StringExtractorGDBRemote &response) -{ - switch (response.GetResponseType()) - { - case StringExtractorGDBRemote::eOK: - case StringExtractorGDBRemote::eError: - case StringExtractorGDBRemote::eUnsupported: - return true; - - case StringExtractorGDBRemote::eAck: - case StringExtractorGDBRemote::eNack: - case StringExtractorGDBRemote::eResponse: - break; - } - return false; +OKErrorNotSupportedResponseValidator(void *, + const StringExtractorGDBRemote &response) { + switch (response.GetResponseType()) { + case StringExtractorGDBRemote::eOK: + case StringExtractorGDBRemote::eError: + case StringExtractorGDBRemote::eUnsupported: + return true; + + case StringExtractorGDBRemote::eAck: + case StringExtractorGDBRemote::eNack: + case StringExtractorGDBRemote::eResponse: + break; + } + return false; } -static bool -JSONResponseValidator(void *, const StringExtractorGDBRemote &response) -{ - switch (response.GetResponseType()) - { - case StringExtractorGDBRemote::eUnsupported: - case StringExtractorGDBRemote::eError: - return true; // Accept unsupported or EXX as valid responses - - case StringExtractorGDBRemote::eOK: - case StringExtractorGDBRemote::eAck: - case StringExtractorGDBRemote::eNack: - break; - - case StringExtractorGDBRemote::eResponse: - // JSON that is returned in from JSON query packets is currently always - // either a dictionary which starts with a '{', or an array which - // starts with a '['. This is a quick validator to just make sure the - // response could be valid JSON without having to validate all of the - // JSON content. - switch (response.GetStringRef()[0]) - { - case '{': return true; - case '[': return true; - default: - break; - } - break; +static bool JSONResponseValidator(void *, + const StringExtractorGDBRemote &response) { + switch (response.GetResponseType()) { + case StringExtractorGDBRemote::eUnsupported: + case StringExtractorGDBRemote::eError: + return true; // Accept unsupported or EXX as valid responses + + case StringExtractorGDBRemote::eOK: + case StringExtractorGDBRemote::eAck: + case StringExtractorGDBRemote::eNack: + break; + + case StringExtractorGDBRemote::eResponse: + // JSON that is returned in from JSON query packets is currently always + // either a dictionary which starts with a '{', or an array which + // starts with a '['. This is a quick validator to just make sure the + // response could be valid JSON without having to validate all of the + // JSON content. + switch (response.GetStringRef()[0]) { + case '{': + return true; + case '[': + return true; + default: + break; } - return false; + break; + } + return false; } static bool -ASCIIHexBytesResponseValidator(void *, const StringExtractorGDBRemote &response) -{ - switch (response.GetResponseType()) - { - case StringExtractorGDBRemote::eUnsupported: - case StringExtractorGDBRemote::eError: - return true; // Accept unsupported or EXX as valid responses - - case StringExtractorGDBRemote::eOK: - case StringExtractorGDBRemote::eAck: - case StringExtractorGDBRemote::eNack: - break; - - case StringExtractorGDBRemote::eResponse: - { - uint32_t valid_count = 0; - for (const char ch : response.GetStringRef()) - { - if (!isxdigit(ch)) - { - return false; - } - if (++valid_count >= 16) - break; // Don't validate all the characters in case the packet is very large - } - return true; - } - break; +ASCIIHexBytesResponseValidator(void *, + const StringExtractorGDBRemote &response) { + switch (response.GetResponseType()) { + case StringExtractorGDBRemote::eUnsupported: + case StringExtractorGDBRemote::eError: + return true; // Accept unsupported or EXX as valid responses + + case StringExtractorGDBRemote::eOK: + case StringExtractorGDBRemote::eAck: + case StringExtractorGDBRemote::eNack: + break; + + case StringExtractorGDBRemote::eResponse: { + uint32_t valid_count = 0; + for (const char ch : response.GetStringRef()) { + if (!isxdigit(ch)) { + return false; + } + if (++valid_count >= 16) + break; // Don't validate all the characters in case the packet is very + // large } - return false; + return true; + } break; + } + return false; } -void -StringExtractorGDBRemote::CopyResponseValidator(const StringExtractorGDBRemote& rhs) -{ - m_validator = rhs.m_validator; - m_validator_baton = rhs.m_validator_baton; +void StringExtractorGDBRemote::CopyResponseValidator( + const StringExtractorGDBRemote &rhs) { + m_validator = rhs.m_validator; + m_validator_baton = rhs.m_validator_baton; } -void -StringExtractorGDBRemote::SetResponseValidator(ResponseValidatorCallback callback, void *baton) -{ - m_validator = callback; - m_validator_baton = baton; +void StringExtractorGDBRemote::SetResponseValidator( + ResponseValidatorCallback callback, void *baton) { + m_validator = callback; + m_validator_baton = baton; } -void -StringExtractorGDBRemote::SetResponseValidatorToOKErrorNotSupported() -{ - m_validator = OKErrorNotSupportedResponseValidator; - m_validator_baton = nullptr; +void StringExtractorGDBRemote::SetResponseValidatorToOKErrorNotSupported() { + m_validator = OKErrorNotSupportedResponseValidator; + m_validator_baton = nullptr; } -void -StringExtractorGDBRemote::SetResponseValidatorToASCIIHexBytes() -{ - m_validator = ASCIIHexBytesResponseValidator; - m_validator_baton = nullptr; +void StringExtractorGDBRemote::SetResponseValidatorToASCIIHexBytes() { + m_validator = ASCIIHexBytesResponseValidator; + m_validator_baton = nullptr; } -void -StringExtractorGDBRemote::SetResponseValidatorToJSON() -{ - m_validator = JSONResponseValidator; - m_validator_baton = nullptr; +void StringExtractorGDBRemote::SetResponseValidatorToJSON() { + m_validator = JSONResponseValidator; + m_validator_baton = nullptr; } -bool -StringExtractorGDBRemote::ValidateResponse() const -{ - // If we have a validator callback, try to validate the callback - if (m_validator) - return m_validator(m_validator_baton, *this); - else - return true; // No validator, so response is valid +bool StringExtractorGDBRemote::ValidateResponse() const { + // If we have a validator callback, try to validate the callback + if (m_validator) + return m_validator(m_validator_baton, *this); + else + return true; // No validator, so response is valid } - - diff --git a/lldb/source/Utility/StringExtractorGDBRemote.h b/lldb/source/Utility/StringExtractorGDBRemote.h index 9e50944..f63e72f 100644 --- a/lldb/source/Utility/StringExtractorGDBRemote.h +++ b/lldb/source/Utility/StringExtractorGDBRemote.h @@ -17,209 +17,175 @@ // Project includes #include "lldb/Utility/StringExtractor.h" -class StringExtractorGDBRemote : public StringExtractor -{ +class StringExtractorGDBRemote : public StringExtractor { public: - typedef bool (*ResponseValidatorCallback)(void * baton, const StringExtractorGDBRemote &response); - - StringExtractorGDBRemote() : - StringExtractor(), - m_validator(nullptr) - { - } - - StringExtractorGDBRemote(llvm::StringRef str) : StringExtractor(str), m_validator(nullptr) {} - - StringExtractorGDBRemote(const char *cstr) : - StringExtractor(cstr), - m_validator(nullptr) - { - } - - StringExtractorGDBRemote(const StringExtractorGDBRemote& rhs) : - StringExtractor(rhs), - m_validator(rhs.m_validator) - { - } - - virtual ~StringExtractorGDBRemote() - { - } - - bool - ValidateResponse() const; - - void - CopyResponseValidator(const StringExtractorGDBRemote& rhs); - - void - SetResponseValidator(ResponseValidatorCallback callback, void *baton); - - void - SetResponseValidatorToOKErrorNotSupported(); - - void - SetResponseValidatorToASCIIHexBytes(); - - void - SetResponseValidatorToJSON(); - - enum ServerPacketType - { - eServerPacketType_nack = 0, - eServerPacketType_ack, - eServerPacketType_invalid, - eServerPacketType_unimplemented, - eServerPacketType_interrupt, // CTRL+c packet or "\x03" - eServerPacketType_A, // Program arguments packet - eServerPacketType_qfProcessInfo, - eServerPacketType_qsProcessInfo, - eServerPacketType_qC, - eServerPacketType_qEcho, - eServerPacketType_qGroupName, - eServerPacketType_qHostInfo, - eServerPacketType_qLaunchGDBServer, - eServerPacketType_qQueryGDBServer, - eServerPacketType_qKillSpawnedProcess, - eServerPacketType_qLaunchSuccess, - eServerPacketType_qModuleInfo, - eServerPacketType_qProcessInfoPID, - eServerPacketType_qSpeedTest, - eServerPacketType_qUserName, - eServerPacketType_qGetWorkingDir, - eServerPacketType_qFileLoadAddress, - eServerPacketType_QEnvironment, - eServerPacketType_QLaunchArch, - eServerPacketType_QSetDisableASLR, - eServerPacketType_QSetDetachOnError, - eServerPacketType_QSetSTDIN, - eServerPacketType_QSetSTDOUT, - eServerPacketType_QSetSTDERR, - eServerPacketType_QSetWorkingDir, - eServerPacketType_QStartNoAckMode, - eServerPacketType_qPlatform_shell, - eServerPacketType_qPlatform_mkdir, - eServerPacketType_qPlatform_chmod, - eServerPacketType_vFile_open, - eServerPacketType_vFile_close, - eServerPacketType_vFile_pread, - eServerPacketType_vFile_pwrite, - eServerPacketType_vFile_size, - eServerPacketType_vFile_mode, - eServerPacketType_vFile_exists, - eServerPacketType_vFile_md5, - eServerPacketType_vFile_stat, - eServerPacketType_vFile_symlink, - eServerPacketType_vFile_unlink, - // debug server packages - eServerPacketType_QEnvironmentHexEncoded, - eServerPacketType_QListThreadsInStopReply, - eServerPacketType_QRestoreRegisterState, - eServerPacketType_QSaveRegisterState, - eServerPacketType_QSetLogging, - eServerPacketType_QSetMaxPacketSize, - eServerPacketType_QSetMaxPayloadSize, - eServerPacketType_QSetEnableAsyncProfiling, - eServerPacketType_QSyncThreadState, - eServerPacketType_QThreadSuffixSupported, - - eServerPacketType_jThreadsInfo, - eServerPacketType_qsThreadInfo, - eServerPacketType_qfThreadInfo, - eServerPacketType_qGetPid, - eServerPacketType_qGetProfileData, - eServerPacketType_qGDBServerVersion, - eServerPacketType_qMemoryRegionInfo, - eServerPacketType_qMemoryRegionInfoSupported, - eServerPacketType_qProcessInfo, - eServerPacketType_qRcmd, - eServerPacketType_qRegisterInfo, - eServerPacketType_qShlibInfoAddr, - eServerPacketType_qStepPacketSupported, - eServerPacketType_qSupported, - eServerPacketType_qSyncThreadStateSupported, - eServerPacketType_qThreadExtraInfo, - eServerPacketType_qThreadStopInfo, - eServerPacketType_qVAttachOrWaitSupported, - eServerPacketType_qWatchpointSupportInfo, - eServerPacketType_qWatchpointSupportInfoSupported, - eServerPacketType_qXfer_auxv_read, - - eServerPacketType_jSignalsInfo, - - eServerPacketType_vAttach, - eServerPacketType_vAttachWait, - eServerPacketType_vAttachOrWait, - eServerPacketType_vAttachName, - eServerPacketType_vCont, - eServerPacketType_vCont_actions, // vCont? - - eServerPacketType_stop_reason, // '?' - - eServerPacketType_c, - eServerPacketType_C, - eServerPacketType_D, - eServerPacketType_g, - eServerPacketType_G, - eServerPacketType_H, - eServerPacketType_I, // stdin notification - eServerPacketType_k, - eServerPacketType_m, - eServerPacketType_M, - eServerPacketType_p, - eServerPacketType_P, - eServerPacketType_s, - eServerPacketType_S, - eServerPacketType_T, - eServerPacketType_x, - eServerPacketType_X, - eServerPacketType_Z, - eServerPacketType_z, - - eServerPacketType__M, - eServerPacketType__m, - eServerPacketType_notify, // '%' notification - }; - - ServerPacketType - GetServerPacketType () const; - - enum ResponseType - { - eUnsupported = 0, - eAck, - eNack, - eError, - eOK, - eResponse - }; - - ResponseType - GetResponseType () const; - - bool - IsOKResponse() const; - - bool - IsUnsupportedResponse() const; - - bool - IsNormalResponse () const; - - bool - IsErrorResponse() const; - - // Returns zero if the packet isn't a EXX packet where XX are two hex - // digits. Otherwise the error encoded in XX is returned. - uint8_t - GetError(); - - size_t - GetEscapedBinaryData (std::string &str); + typedef bool (*ResponseValidatorCallback)( + void *baton, const StringExtractorGDBRemote &response); + + StringExtractorGDBRemote() : StringExtractor(), m_validator(nullptr) {} + + StringExtractorGDBRemote(llvm::StringRef str) + : StringExtractor(str), m_validator(nullptr) {} + + StringExtractorGDBRemote(const char *cstr) + : StringExtractor(cstr), m_validator(nullptr) {} + + StringExtractorGDBRemote(const StringExtractorGDBRemote &rhs) + : StringExtractor(rhs), m_validator(rhs.m_validator) {} + + virtual ~StringExtractorGDBRemote() {} + + bool ValidateResponse() const; + + void CopyResponseValidator(const StringExtractorGDBRemote &rhs); + + void SetResponseValidator(ResponseValidatorCallback callback, void *baton); + + void SetResponseValidatorToOKErrorNotSupported(); + + void SetResponseValidatorToASCIIHexBytes(); + + void SetResponseValidatorToJSON(); + + enum ServerPacketType { + eServerPacketType_nack = 0, + eServerPacketType_ack, + eServerPacketType_invalid, + eServerPacketType_unimplemented, + eServerPacketType_interrupt, // CTRL+c packet or "\x03" + eServerPacketType_A, // Program arguments packet + eServerPacketType_qfProcessInfo, + eServerPacketType_qsProcessInfo, + eServerPacketType_qC, + eServerPacketType_qEcho, + eServerPacketType_qGroupName, + eServerPacketType_qHostInfo, + eServerPacketType_qLaunchGDBServer, + eServerPacketType_qQueryGDBServer, + eServerPacketType_qKillSpawnedProcess, + eServerPacketType_qLaunchSuccess, + eServerPacketType_qModuleInfo, + eServerPacketType_qProcessInfoPID, + eServerPacketType_qSpeedTest, + eServerPacketType_qUserName, + eServerPacketType_qGetWorkingDir, + eServerPacketType_qFileLoadAddress, + eServerPacketType_QEnvironment, + eServerPacketType_QLaunchArch, + eServerPacketType_QSetDisableASLR, + eServerPacketType_QSetDetachOnError, + eServerPacketType_QSetSTDIN, + eServerPacketType_QSetSTDOUT, + eServerPacketType_QSetSTDERR, + eServerPacketType_QSetWorkingDir, + eServerPacketType_QStartNoAckMode, + eServerPacketType_qPlatform_shell, + eServerPacketType_qPlatform_mkdir, + eServerPacketType_qPlatform_chmod, + eServerPacketType_vFile_open, + eServerPacketType_vFile_close, + eServerPacketType_vFile_pread, + eServerPacketType_vFile_pwrite, + eServerPacketType_vFile_size, + eServerPacketType_vFile_mode, + eServerPacketType_vFile_exists, + eServerPacketType_vFile_md5, + eServerPacketType_vFile_stat, + eServerPacketType_vFile_symlink, + eServerPacketType_vFile_unlink, + // debug server packages + eServerPacketType_QEnvironmentHexEncoded, + eServerPacketType_QListThreadsInStopReply, + eServerPacketType_QRestoreRegisterState, + eServerPacketType_QSaveRegisterState, + eServerPacketType_QSetLogging, + eServerPacketType_QSetMaxPacketSize, + eServerPacketType_QSetMaxPayloadSize, + eServerPacketType_QSetEnableAsyncProfiling, + eServerPacketType_QSyncThreadState, + eServerPacketType_QThreadSuffixSupported, + + eServerPacketType_jThreadsInfo, + eServerPacketType_qsThreadInfo, + eServerPacketType_qfThreadInfo, + eServerPacketType_qGetPid, + eServerPacketType_qGetProfileData, + eServerPacketType_qGDBServerVersion, + eServerPacketType_qMemoryRegionInfo, + eServerPacketType_qMemoryRegionInfoSupported, + eServerPacketType_qProcessInfo, + eServerPacketType_qRcmd, + eServerPacketType_qRegisterInfo, + eServerPacketType_qShlibInfoAddr, + eServerPacketType_qStepPacketSupported, + eServerPacketType_qSupported, + eServerPacketType_qSyncThreadStateSupported, + eServerPacketType_qThreadExtraInfo, + eServerPacketType_qThreadStopInfo, + eServerPacketType_qVAttachOrWaitSupported, + eServerPacketType_qWatchpointSupportInfo, + eServerPacketType_qWatchpointSupportInfoSupported, + eServerPacketType_qXfer_auxv_read, + + eServerPacketType_jSignalsInfo, + + eServerPacketType_vAttach, + eServerPacketType_vAttachWait, + eServerPacketType_vAttachOrWait, + eServerPacketType_vAttachName, + eServerPacketType_vCont, + eServerPacketType_vCont_actions, // vCont? + + eServerPacketType_stop_reason, // '?' + + eServerPacketType_c, + eServerPacketType_C, + eServerPacketType_D, + eServerPacketType_g, + eServerPacketType_G, + eServerPacketType_H, + eServerPacketType_I, // stdin notification + eServerPacketType_k, + eServerPacketType_m, + eServerPacketType_M, + eServerPacketType_p, + eServerPacketType_P, + eServerPacketType_s, + eServerPacketType_S, + eServerPacketType_T, + eServerPacketType_x, + eServerPacketType_X, + eServerPacketType_Z, + eServerPacketType_z, + + eServerPacketType__M, + eServerPacketType__m, + eServerPacketType_notify, // '%' notification + }; + + ServerPacketType GetServerPacketType() const; + + enum ResponseType { eUnsupported = 0, eAck, eNack, eError, eOK, eResponse }; + + ResponseType GetResponseType() const; + + bool IsOKResponse() const; + + bool IsUnsupportedResponse() const; + + bool IsNormalResponse() const; + + bool IsErrorResponse() const; + + // Returns zero if the packet isn't a EXX packet where XX are two hex + // digits. Otherwise the error encoded in XX is returned. + uint8_t GetError(); + + size_t GetEscapedBinaryData(std::string &str); protected: - ResponseValidatorCallback m_validator; - void *m_validator_baton; + ResponseValidatorCallback m_validator; + void *m_validator_baton; }; -#endif // utility_StringExtractorGDBRemote_h_ +#endif // utility_StringExtractorGDBRemote_h_ diff --git a/lldb/source/Utility/StringLexer.cpp b/lldb/source/Utility/StringLexer.cpp index 2f62d2c..ec18f04 100644 --- a/lldb/source/Utility/StringLexer.cpp +++ b/lldb/source/Utility/StringLexer.cpp @@ -1,4 +1,5 @@ -//===--------------------- StringLexer.cpp -----------------------*- C++ -*-===// +//===--------------------- StringLexer.cpp -----------------------*- C++ +//-*-===// // // The LLVM Compiler Infrastructure // @@ -14,116 +15,79 @@ using namespace lldb_utility; -StringLexer::StringLexer (std::string s) : - m_data(s), - m_position(0) -{ } +StringLexer::StringLexer(std::string s) : m_data(s), m_position(0) {} -StringLexer::StringLexer (const StringLexer& rhs) : - m_data(rhs.m_data), - m_position(rhs.m_position) -{ } +StringLexer::StringLexer(const StringLexer &rhs) + : m_data(rhs.m_data), m_position(rhs.m_position) {} -StringLexer::Character -StringLexer::Peek () -{ - return m_data[m_position]; -} +StringLexer::Character StringLexer::Peek() { return m_data[m_position]; } -bool -StringLexer::NextIf (Character c) -{ - auto val = Peek(); - if (val == c) - { - Next(); - return true; - } - return false; +bool StringLexer::NextIf(Character c) { + auto val = Peek(); + if (val == c) { + Next(); + return true; + } + return false; } std::pair<bool, StringLexer::Character> -StringLexer::NextIf (std::initializer_list<Character> cs) -{ - auto val = Peek(); - for (auto c : cs) - { - if (val == c) - { - Next(); - return {true,c}; - } +StringLexer::NextIf(std::initializer_list<Character> cs) { + auto val = Peek(); + for (auto c : cs) { + if (val == c) { + Next(); + return {true, c}; } - return {false,0}; + } + return {false, 0}; } -bool -StringLexer::AdvanceIf (const std::string& token) -{ - auto pos = m_position; - bool matches = true; - for (auto c : token) - { - if (!NextIf(c)) - { - matches = false; - break; - } - } - if (!matches) - { - m_position = pos; - return false; +bool StringLexer::AdvanceIf(const std::string &token) { + auto pos = m_position; + bool matches = true; + for (auto c : token) { + if (!NextIf(c)) { + matches = false; + break; } - return true; + } + if (!matches) { + m_position = pos; + return false; + } + return true; } -StringLexer::Character -StringLexer::Next () -{ - auto val = Peek(); - Consume(); - return val; +StringLexer::Character StringLexer::Next() { + auto val = Peek(); + Consume(); + return val; } -bool -StringLexer::HasAtLeast (Size s) -{ - return (m_data.size() - m_position) >= s; +bool StringLexer::HasAtLeast(Size s) { + return (m_data.size() - m_position) >= s; } -void -StringLexer::PutBack (Size s) -{ - assert (m_position >= s); - m_position -= s; +void StringLexer::PutBack(Size s) { + assert(m_position >= s); + m_position -= s; } -bool -StringLexer::HasAny (Character c) -{ - return m_data.find(c, m_position) != std::string::npos; +bool StringLexer::HasAny(Character c) { + return m_data.find(c, m_position) != std::string::npos; } -std::string -StringLexer::GetUnlexed () -{ - return std::string(m_data, m_position); +std::string StringLexer::GetUnlexed() { + return std::string(m_data, m_position); } -void -StringLexer::Consume() -{ - m_position++; -} +void StringLexer::Consume() { m_position++; } -StringLexer& -StringLexer::operator = (const StringLexer& rhs) -{ - if (this != &rhs) - { - m_data = rhs.m_data; - m_position = rhs.m_position; - } - return *this; +StringLexer &StringLexer::operator=(const StringLexer &rhs) { + if (this != &rhs) { + m_data = rhs.m_data; + m_position = rhs.m_position; + } + return *this; } diff --git a/lldb/source/Utility/TaskPool.cpp b/lldb/source/Utility/TaskPool.cpp index c5c63a2..f66f7bf 100644 --- a/lldb/source/Utility/TaskPool.cpp +++ b/lldb/source/Utility/TaskPool.cpp @@ -9,81 +9,63 @@ #include "lldb/Utility/TaskPool.h" -namespace -{ - class TaskPoolImpl - { - public: - static TaskPoolImpl& - GetInstance(); +namespace { +class TaskPoolImpl { +public: + static TaskPoolImpl &GetInstance(); - void - AddTask(std::function<void()>&& task_fn); + void AddTask(std::function<void()> &&task_fn); - private: - TaskPoolImpl(); +private: + TaskPoolImpl(); - static void - Worker(TaskPoolImpl* pool); + static void Worker(TaskPoolImpl *pool); - std::queue<std::function<void()>> m_tasks; - std::mutex m_tasks_mutex; - uint32_t m_thread_count; - }; + std::queue<std::function<void()>> m_tasks; + std::mutex m_tasks_mutex; + uint32_t m_thread_count; +}; } // end of anonymous namespace -TaskPoolImpl& -TaskPoolImpl::GetInstance() -{ - static TaskPoolImpl g_task_pool_impl; - return g_task_pool_impl; +TaskPoolImpl &TaskPoolImpl::GetInstance() { + static TaskPoolImpl g_task_pool_impl; + return g_task_pool_impl; } -void -TaskPool::AddTaskImpl(std::function<void()>&& task_fn) -{ - TaskPoolImpl::GetInstance().AddTask(std::move(task_fn)); +void TaskPool::AddTaskImpl(std::function<void()> &&task_fn) { + TaskPoolImpl::GetInstance().AddTask(std::move(task_fn)); } -TaskPoolImpl::TaskPoolImpl() : - m_thread_count(0) -{ -} +TaskPoolImpl::TaskPoolImpl() : m_thread_count(0) {} -void -TaskPoolImpl::AddTask(std::function<void()>&& task_fn) -{ - static const uint32_t max_threads = std::thread::hardware_concurrency(); +void TaskPoolImpl::AddTask(std::function<void()> &&task_fn) { + static const uint32_t max_threads = std::thread::hardware_concurrency(); - std::unique_lock<std::mutex> lock(m_tasks_mutex); - m_tasks.emplace(std::move(task_fn)); - if (m_thread_count < max_threads) - { - m_thread_count++; - // Note that this detach call needs to happen with the m_tasks_mutex held. This prevents the thread - // from exiting prematurely and triggering a linux libc bug - // (https://sourceware.org/bugzilla/show_bug.cgi?id=19951). - std::thread (Worker, this).detach(); - } + std::unique_lock<std::mutex> lock(m_tasks_mutex); + m_tasks.emplace(std::move(task_fn)); + if (m_thread_count < max_threads) { + m_thread_count++; + // Note that this detach call needs to happen with the m_tasks_mutex held. + // This prevents the thread + // from exiting prematurely and triggering a linux libc bug + // (https://sourceware.org/bugzilla/show_bug.cgi?id=19951). + std::thread(Worker, this).detach(); + } } -void -TaskPoolImpl::Worker(TaskPoolImpl* pool) -{ - while (true) - { - std::unique_lock<std::mutex> lock(pool->m_tasks_mutex); - if (pool->m_tasks.empty()) - { - pool->m_thread_count--; - break; - } +void TaskPoolImpl::Worker(TaskPoolImpl *pool) { + while (true) { + std::unique_lock<std::mutex> lock(pool->m_tasks_mutex); + if (pool->m_tasks.empty()) { + pool->m_thread_count--; + break; + } - std::function<void()> f = pool->m_tasks.front(); - pool->m_tasks.pop(); - lock.unlock(); + std::function<void()> f = pool->m_tasks.front(); + pool->m_tasks.pop(); + lock.unlock(); - f(); - } + f(); + } } diff --git a/lldb/source/Utility/TimeSpecTimeout.cpp b/lldb/source/Utility/TimeSpecTimeout.cpp index 33b3b4e..b92b028 100644 --- a/lldb/source/Utility/TimeSpecTimeout.cpp +++ b/lldb/source/Utility/TimeSpecTimeout.cpp @@ -12,37 +12,27 @@ using namespace lldb_private; const struct timespec * -TimeSpecTimeout::SetAbsoluteTimeoutMircoSeconds32 (uint32_t timeout_usec) -{ - if (timeout_usec == UINT32_MAX) - { - m_infinite = true; - } - else - { - m_infinite = false; - TimeValue time_value(TimeValue::Now()); - time_value.OffsetWithMicroSeconds(timeout_usec); - m_timespec = time_value.GetAsTimeSpec(); - } - return GetTimeSpecPtr (); +TimeSpecTimeout::SetAbsoluteTimeoutMircoSeconds32(uint32_t timeout_usec) { + if (timeout_usec == UINT32_MAX) { + m_infinite = true; + } else { + m_infinite = false; + TimeValue time_value(TimeValue::Now()); + time_value.OffsetWithMicroSeconds(timeout_usec); + m_timespec = time_value.GetAsTimeSpec(); + } + return GetTimeSpecPtr(); } const struct timespec * -TimeSpecTimeout::SetRelativeTimeoutMircoSeconds32 (uint32_t timeout_usec) -{ - if (timeout_usec == UINT32_MAX) - { - m_infinite = true; - } - else - { - m_infinite = false; - TimeValue time_value; - time_value.OffsetWithMicroSeconds(timeout_usec); - m_timespec = time_value.GetAsTimeSpec(); - } - return GetTimeSpecPtr (); +TimeSpecTimeout::SetRelativeTimeoutMircoSeconds32(uint32_t timeout_usec) { + if (timeout_usec == UINT32_MAX) { + m_infinite = true; + } else { + m_infinite = false; + TimeValue time_value; + time_value.OffsetWithMicroSeconds(timeout_usec); + m_timespec = time_value.GetAsTimeSpec(); + } + return GetTimeSpecPtr(); } - - diff --git a/lldb/source/Utility/TimeSpecTimeout.h b/lldb/source/Utility/TimeSpecTimeout.h index 8f809ac..60ec338 100644 --- a/lldb/source/Utility/TimeSpecTimeout.h +++ b/lldb/source/Utility/TimeSpecTimeout.h @@ -15,75 +15,68 @@ namespace lldb_private { -class TimeSpecTimeout -{ +class TimeSpecTimeout { public: - TimeSpecTimeout() : - m_infinite (false) - { - m_timespec.tv_sec = 0; - m_timespec.tv_nsec = 0; - } - ~TimeSpecTimeout() - { - } + TimeSpecTimeout() : m_infinite(false) { + m_timespec.tv_sec = 0; + m_timespec.tv_nsec = 0; + } + ~TimeSpecTimeout() {} - //---------------------------------------------------------------------- - /// Sets the timespec pointer correctly given a timeout relative to the - /// current time. This function should be called immediately prior to - /// calling the function you will use this timeout with since time can - /// elapse between when this function is called and when the timeout is - /// used. - /// - /// @param[in] timeout_usec - /// The timeout in micro seconds. If timeout_usec is UINT32_MAX, the - /// timeout should be set to INFINITE. Otherwise the current time is - /// filled into the timespec and \a timeout_usec is added to the - /// current time. - /// - /// @return - /// If the timeout is INFINITE, then return NULL, otherwise return - /// a pointer to the timespec with the appropriate timeout value. - //---------------------------------------------------------------------- - const struct timespec * - SetAbsoluteTimeoutMircoSeconds32 (uint32_t timeout_usec); + //---------------------------------------------------------------------- + /// Sets the timespec pointer correctly given a timeout relative to the + /// current time. This function should be called immediately prior to + /// calling the function you will use this timeout with since time can + /// elapse between when this function is called and when the timeout is + /// used. + /// + /// @param[in] timeout_usec + /// The timeout in micro seconds. If timeout_usec is UINT32_MAX, the + /// timeout should be set to INFINITE. Otherwise the current time is + /// filled into the timespec and \a timeout_usec is added to the + /// current time. + /// + /// @return + /// If the timeout is INFINITE, then return NULL, otherwise return + /// a pointer to the timespec with the appropriate timeout value. + //---------------------------------------------------------------------- + const struct timespec * + SetAbsoluteTimeoutMircoSeconds32(uint32_t timeout_usec); - //---------------------------------------------------------------------- - /// Sets the timespec pointer correctly given a relative time in micro - /// seconds. - /// - /// @param[in] timeout_usec - /// The timeout in micro seconds. If timeout_usec is UINT32_MAX, the - /// timeout should be set to INFINITE. Otherwise \a timeout_usec - /// is correctly placed into the timespec. - /// - /// @return - /// If the timeout is INFINITE, then return NULL, otherwise return - /// a pointer to the timespec with the appropriate timeout value. - //---------------------------------------------------------------------- - const struct timespec * - SetRelativeTimeoutMircoSeconds32 (uint32_t timeout_usec); + //---------------------------------------------------------------------- + /// Sets the timespec pointer correctly given a relative time in micro + /// seconds. + /// + /// @param[in] timeout_usec + /// The timeout in micro seconds. If timeout_usec is UINT32_MAX, the + /// timeout should be set to INFINITE. Otherwise \a timeout_usec + /// is correctly placed into the timespec. + /// + /// @return + /// If the timeout is INFINITE, then return NULL, otherwise return + /// a pointer to the timespec with the appropriate timeout value. + //---------------------------------------------------------------------- + const struct timespec * + SetRelativeTimeoutMircoSeconds32(uint32_t timeout_usec); + + //---------------------------------------------------------------------- + /// Gets the timespec pointer that is appropriate for the timeout + /// specified. This function should only be used after a call to + /// SetRelativeTimeoutXXX() functions. + /// + /// @return + /// If the timeout is INFINITE, then return NULL, otherwise return + /// a pointer to the timespec with the appropriate timeout value. + //---------------------------------------------------------------------- + const struct timespec *GetTimeSpecPtr() const { + if (m_infinite) + return nullptr; + return &m_timespec; + } - //---------------------------------------------------------------------- - /// Gets the timespec pointer that is appropriate for the timeout - /// specified. This function should only be used after a call to - /// SetRelativeTimeoutXXX() functions. - /// - /// @return - /// If the timeout is INFINITE, then return NULL, otherwise return - /// a pointer to the timespec with the appropriate timeout value. - //---------------------------------------------------------------------- - const struct timespec * - GetTimeSpecPtr () const - { - if (m_infinite) - return nullptr; - return &m_timespec; - } - protected: - struct timespec m_timespec; - bool m_infinite; + struct timespec m_timespec; + bool m_infinite; }; } // namespace lldb_private diff --git a/lldb/source/Utility/UriParser.cpp b/lldb/source/Utility/UriParser.cpp index 77e16b0..6a1f030 100644 --- a/lldb/source/Utility/UriParser.cpp +++ b/lldb/source/Utility/UriParser.cpp @@ -23,72 +23,63 @@ using namespace lldb_private; //---------------------------------------------------------------------- // UriParser::Parse //---------------------------------------------------------------------- -bool -UriParser::Parse(const std::string& uri, - std::string& scheme, - std::string& hostname, - int& port, - std::string& path) -{ - std::string tmp_scheme, tmp_hostname, tmp_port, tmp_path; +bool UriParser::Parse(const std::string &uri, std::string &scheme, + std::string &hostname, int &port, std::string &path) { + std::string tmp_scheme, tmp_hostname, tmp_port, tmp_path; - static const char* kSchemeSep = "://"; - auto pos = uri.find(kSchemeSep); - if (pos == std::string::npos) - return false; + static const char *kSchemeSep = "://"; + auto pos = uri.find(kSchemeSep); + if (pos == std::string::npos) + return false; - // Extract path. - tmp_scheme = uri.substr(0, pos); - auto host_pos = pos + strlen(kSchemeSep); - auto path_pos = uri.find('/', host_pos); - if (path_pos != std::string::npos) - tmp_path = uri.substr(path_pos); - else - tmp_path = "/"; + // Extract path. + tmp_scheme = uri.substr(0, pos); + auto host_pos = pos + strlen(kSchemeSep); + auto path_pos = uri.find('/', host_pos); + if (path_pos != std::string::npos) + tmp_path = uri.substr(path_pos); + else + tmp_path = "/"; - auto host_port = uri.substr( - host_pos, ((path_pos != std::string::npos) ? path_pos : uri.size()) - host_pos); + auto host_port = uri.substr( + host_pos, + ((path_pos != std::string::npos) ? path_pos : uri.size()) - host_pos); - // Extract hostname - if (host_port[0] == '[') - { - // hostname is enclosed with square brackets. - pos = host_port.find(']'); - if (pos == std::string::npos) - return false; + // Extract hostname + if (host_port[0] == '[') { + // hostname is enclosed with square brackets. + pos = host_port.find(']'); + if (pos == std::string::npos) + return false; - tmp_hostname = host_port.substr(1, pos - 1); - host_port.erase(0, pos + 1); - } - else - { - pos = host_port.find(':'); - tmp_hostname = host_port.substr(0, (pos != std::string::npos) ? pos : host_port.size()); - host_port.erase(0, (pos != std::string::npos) ? pos : host_port.size()); - } + tmp_hostname = host_port.substr(1, pos - 1); + host_port.erase(0, pos + 1); + } else { + pos = host_port.find(':'); + tmp_hostname = host_port.substr( + 0, (pos != std::string::npos) ? pos : host_port.size()); + host_port.erase(0, (pos != std::string::npos) ? pos : host_port.size()); + } - // Extract port - tmp_port = host_port; - if (!tmp_port.empty()) - { - if (tmp_port[0] != ':') - return false; - tmp_port = tmp_port.substr(1); - bool success = false; - auto port_tmp = StringConvert::ToUInt32(tmp_port.c_str(), UINT32_MAX, 10, &success); - if (!success || port_tmp > 65535) - { - // there are invalid characters in port_buf - return false; - } - port = port_tmp; + // Extract port + tmp_port = host_port; + if (!tmp_port.empty()) { + if (tmp_port[0] != ':') + return false; + tmp_port = tmp_port.substr(1); + bool success = false; + auto port_tmp = + StringConvert::ToUInt32(tmp_port.c_str(), UINT32_MAX, 10, &success); + if (!success || port_tmp > 65535) { + // there are invalid characters in port_buf + return false; } - else - port = -1; + port = port_tmp; + } else + port = -1; - scheme = tmp_scheme; - hostname = tmp_hostname; - path = tmp_path; - return true; + scheme = tmp_scheme; + hostname = tmp_hostname; + path = tmp_path; + return true; } - diff --git a/lldb/source/Utility/UriParser.h b/lldb/source/Utility/UriParser.h index 8cbaaea..56bd194 100644 --- a/lldb/source/Utility/UriParser.h +++ b/lldb/source/Utility/UriParser.h @@ -17,23 +17,18 @@ // Other libraries and framework includes // Project includes -class UriParser -{ +class UriParser { public: - // Parses - // RETURN VALUE - // if url is valid, function returns true and - // scheme/hostname/port/path are set to the parsed values - // port it set to -1 if it is not included in the URL - // - // if the url is invalid, function returns false and - // output parameters remain unchanged - static bool - Parse(const std::string& uri, - std::string& scheme, - std::string& hostname, - int& port, - std::string& path); + // Parses + // RETURN VALUE + // if url is valid, function returns true and + // scheme/hostname/port/path are set to the parsed values + // port it set to -1 if it is not included in the URL + // + // if the url is invalid, function returns false and + // output parameters remain unchanged + static bool Parse(const std::string &uri, std::string &scheme, + std::string &hostname, int &port, std::string &path); }; -#endif // utility_UriParser_h_ +#endif // utility_UriParser_h_ |