diff --git a/lldb/bindings/interface/SBStructuredData.i b/lldb/bindings/interface/SBStructuredData.i --- a/lldb/bindings/interface/SBStructuredData.i +++ b/lldb/bindings/interface/SBStructuredData.i @@ -49,7 +49,7 @@ bool GetBooleanValue(bool fail_value = false) const; - size_t GetStringValue(char *dst, size_t dst_len) const; + const char *GetStringValue(const char *fail_value = nullptr) const; lldb::SBError GetAsJSON(lldb::SBStream &stream) const; diff --git a/lldb/examples/python/in_call_stack.py b/lldb/examples/python/in_call_stack.py --- a/lldb/examples/python/in_call_stack.py +++ b/lldb/examples/python/in_call_stack.py @@ -9,7 +9,7 @@ def in_call_stack(frame, bp_loc, arg_dict, _): """Only break if the given name is in the current call stack.""" - name = arg_dict.GetValueForKey('name').GetStringValue(1000) + name = arg_dict.GetValueForKey('name').GetStringValue() thread = frame.GetThread() found = False for frame in thread.frames: diff --git a/lldb/include/lldb/API/SBStructuredData.h b/lldb/include/lldb/API/SBStructuredData.h --- a/lldb/include/lldb/API/SBStructuredData.h +++ b/lldb/include/lldb/API/SBStructuredData.h @@ -70,22 +70,8 @@ /// Return the boolean value if this data structure is a boolean type. bool GetBooleanValue(bool fail_value = false) const; - /// Provides the string value if this data structure is a string type. - /// - /// \param[out] dst - /// pointer where the string value will be written. In case it is null, - /// nothing will be written at \a dst. - /// - /// \param[in] dst_len - /// max number of characters that can be written at \a dst. In case it is - /// zero, nothing will be written at \a dst. If this length is not enough - /// to write the complete string value, (\a dst_len - 1) bytes of the - /// string value will be written at \a dst followed by a null character. - /// - /// \return - /// Returns the byte size needed to completely write the string value at - /// \a dst in all cases. - size_t GetStringValue(char *dst, size_t dst_len) const; + /// Return the string value if this data structure is a string type. + const char *GetStringValue(const char *fail_value = nullptr) const; protected: friend class SBTraceOptions; diff --git a/lldb/include/lldb/Core/StructuredDataImpl.h b/lldb/include/lldb/Core/StructuredDataImpl.h --- a/lldb/include/lldb/Core/StructuredDataImpl.h +++ b/lldb/include/lldb/Core/StructuredDataImpl.h @@ -137,19 +137,9 @@ return (m_data_sp ? m_data_sp->GetBooleanValue(fail_value) : fail_value); } - size_t GetStringValue(char *dst, size_t dst_len) const { - if (!m_data_sp) - return 0; - - llvm::StringRef result = m_data_sp->GetStringValue(); - if (result.empty()) - return 0; - - if (!dst || !dst_len) { - char s[1]; - return (::snprintf(s, 1, "%s", result.data())); - } - return (::snprintf(dst, dst_len, "%s", result.data())); + const char *GetStringValue(const char *fail_value = nullptr) const { + return (m_data_sp ? m_data_sp->GetStringValue(fail_value).data() + : fail_value); } private: diff --git a/lldb/packages/Python/lldbsuite/test/decorators.py b/lldb/packages/Python/lldbsuite/test/decorators.py --- a/lldb/packages/Python/lldbsuite/test/decorators.py +++ b/lldb/packages/Python/lldbsuite/test/decorators.py @@ -852,7 +852,7 @@ targets = config.GetValueForKey("targets").GetValueForKey("value") found = False for i in range(targets.GetSize()): - if targets.GetItemAtIndex(i).GetStringValue(99) == target: + if targets.GetItemAtIndex(i).GetStringValue() == target: found = True break diff --git a/lldb/source/API/SBStructuredData.cpp b/lldb/source/API/SBStructuredData.cpp --- a/lldb/source/API/SBStructuredData.cpp +++ b/lldb/source/API/SBStructuredData.cpp @@ -195,11 +195,11 @@ return (m_impl_up ? m_impl_up->GetBooleanValue(fail_value) : fail_value); } -size_t SBStructuredData::GetStringValue(char *dst, size_t dst_len) const { - LLDB_RECORD_CHAR_PTR_METHOD_CONST(size_t, SBStructuredData, GetStringValue, - (char *, size_t), dst, "", dst_len); +const char *SBStructuredData::GetStringValue(const char *fail_value) const { + LLDB_RECORD_METHOD_CONST(const char *, SBStructuredData, GetStringValue, + (const char *), fail_value); - return (m_impl_up ? m_impl_up->GetStringValue(dst, dst_len) : 0); + return (m_impl_up ? m_impl_up->GetStringValue(fail_value) : fail_value); } namespace lldb_private { @@ -236,7 +236,8 @@ (uint64_t)); LLDB_REGISTER_METHOD_CONST(double, SBStructuredData, GetFloatValue, (double)); LLDB_REGISTER_METHOD_CONST(bool, SBStructuredData, GetBooleanValue, (bool)); - LLDB_REGISTER_CHAR_PTR_METHOD_CONST(size_t, SBStructuredData, GetStringValue); + LLDB_REGISTER_METHOD_CONST(const char *, SBStructuredData, GetStringValue, + (const char *)); } } // namespace repro diff --git a/lldb/test/API/commands/platform/basic/TestPlatformPython.py b/lldb/test/API/commands/platform/basic/TestPlatformPython.py --- a/lldb/test/API/commands/platform/basic/TestPlatformPython.py +++ b/lldb/test/API/commands/platform/basic/TestPlatformPython.py @@ -31,7 +31,7 @@ if platform_idx < 1: self.fail('No platforms other than host are available') platform_data = self.dbg.GetAvailablePlatformInfoAtIndex(platform_idx) - platform_name = platform_data.GetValueForKey('name').GetStringValue(100) + platform_name = platform_data.GetValueForKey('name').GetStringValue() self.assertNotEqual(platform_name, 'host') self.dbg.SetCurrentPlatform(platform_name) selected_platform = self.dbg.GetSelectedPlatform() diff --git a/lldb/test/API/commands/target/stop-hooks/stop_hook.py b/lldb/test/API/commands/target/stop-hooks/stop_hook.py --- a/lldb/test/API/commands/target/stop-hooks/stop_hook.py +++ b/lldb/test/API/commands/target/stop-hooks/stop_hook.py @@ -17,7 +17,7 @@ increment = 1 value = self.extra_args.GetValueForKey("increment") if value: - incr_as_str = value.GetStringValue(100) + incr_as_str = value.GetStringValue() increment = int(incr_as_str) else: stream.Print("Could not find increment in extra_args\n") diff --git a/lldb/test/API/functionalities/breakpoint/breakpoint_command/bktptcmd.py b/lldb/test/API/functionalities/breakpoint/breakpoint_command/bktptcmd.py --- a/lldb/test/API/functionalities/breakpoint/breakpoint_command/bktptcmd.py +++ b/lldb/test/API/functionalities/breakpoint/breakpoint_command/bktptcmd.py @@ -9,12 +9,12 @@ def another_function(frame, bp_loc, extra_args, dict): se_value = extra_args.GetValueForKey("side_effect") - se_string = se_value.GetStringValue(100) + se_string = se_value.GetStringValue() side_effect.fancy = se_string def a_third_function(frame, bp_loc, extra_args, dict): se_value = extra_args.GetValueForKey("side_effect") - se_string = se_value.GetStringValue(100) + se_string = se_value.GetStringValue() side_effect.fancier = se_string def empty_extra_args(frame, bp_loc, extra_args, dict): diff --git a/lldb/test/API/functionalities/breakpoint/scripted_bkpt/resolver.py b/lldb/test/API/functionalities/breakpoint/scripted_bkpt/resolver.py --- a/lldb/test/API/functionalities/breakpoint/scripted_bkpt/resolver.py +++ b/lldb/test/API/functionalities/breakpoint/scripted_bkpt/resolver.py @@ -15,7 +15,7 @@ sym_name = "not_a_real_function_name" sym_item = self.extra_args.GetValueForKey("symbol") if sym_item.IsValid(): - sym_name = sym_item.GetStringValue(1000) + sym_name = sym_item.GetStringValue() else: print("Didn't have a value for key 'symbol'") diff --git a/lldb/test/API/functionalities/breakpoint/serialize/TestBreakpointSerialization.py b/lldb/test/API/functionalities/breakpoint/serialize/TestBreakpointSerialization.py --- a/lldb/test/API/functionalities/breakpoint/serialize/TestBreakpointSerialization.py +++ b/lldb/test/API/functionalities/breakpoint/serialize/TestBreakpointSerialization.py @@ -407,7 +407,7 @@ for idx in range(0, orig_keys.GetSize()): key = orig_keys.GetStringAtIndex(idx) - copy_value = copy_extra_args.GetValueForKey(key).GetStringValue(100) + copy_value = copy_extra_args.GetValueForKey(key).GetStringValue() if key == "first_arg": self.assertEqual(copy_value, "first_value") diff --git a/lldb/test/API/functionalities/step_scripted/Steps.py b/lldb/test/API/functionalities/step_scripted/Steps.py --- a/lldb/test/API/functionalities/step_scripted/Steps.py +++ b/lldb/test/API/functionalities/step_scripted/Steps.py @@ -45,7 +45,7 @@ if not func_entry.IsValid(): print("Did not get a valid entry for variable_name") - func_name = func_entry.GetStringValue(100) + func_name = func_entry.GetStringValue() self.value = self.frame.FindVariable(func_name) if self.value.GetError().Fail(): @@ -88,7 +88,7 @@ def __init__(self, thread_plan, args_data, dict): self.thread_plan = thread_plan - self.key = args_data.GetValueForKey("token").GetStringValue(1000) + self.key = args_data.GetValueForKey("token").GetStringValue() def should_stop(self, event): self.thread_plan.SetPlanComplete(True) diff --git a/lldb/test/API/python_api/sbstructureddata/TestStructuredDataAPI.py b/lldb/test/API/python_api/sbstructureddata/TestStructuredDataAPI.py --- a/lldb/test/API/python_api/sbstructureddata/TestStructuredDataAPI.py +++ b/lldb/test/API/python_api/sbstructureddata/TestStructuredDataAPI.py @@ -100,7 +100,7 @@ self.fail("Wrong type returned: " + str(string_struct.GetType())) # Check API returning 'string' value - output = string_struct.GetStringValue(25) + output = string_struct.GetStringValue() if not "STRING" in output: self.fail("wrong output: " + output) @@ -131,7 +131,7 @@ # Calling wrong API on a SBStructuredData # (e.g. getting a string value from an integer type structure) - output = int_struct.GetStringValue(25) + output = int_struct.GetStringValue() if output: self.fail( "Valid string " + @@ -192,7 +192,7 @@ self.fail("A valid object should have been returned") if not string_struct.GetType() == lldb.eStructuredDataTypeString: self.fail("Wrong type returned: " + str(string_struct.GetType())) - output = string_struct.GetStringValue(5) + output = string_struct.GetStringValue() if not output == "23": self.fail("wrong output: " + str(output)) @@ -201,6 +201,6 @@ self.fail("A valid object should have been returned") if not string_struct.GetType() == lldb.eStructuredDataTypeString: self.fail("Wrong type returned: " + str(string_struct.GetType())) - output = string_struct.GetStringValue(5) + output = string_struct.GetStringValue() if not output == "arr": self.fail("wrong output: " + str(output))