[Lldb-commits] [lldb] [lldb][API] Add Find(Ranges)InMemory() to Process SB API (PR #95007)

Greg Clayton via lldb-commits lldb-commits at lists.llvm.org
Mon Jun 10 14:04:34 PDT 2024


================
@@ -0,0 +1,21 @@
+#include <cstring>
+
+int main() {
+  constexpr char SINGLE_INSTANCE_STRING[] = "there_is_only_one_of_me";
+  constexpr size_t single_instance_size = sizeof(SINGLE_INSTANCE_STRING) + 1;
+  char *single_instance = new char[single_instance_size];
+  strcpy(single_instance, SINGLE_INSTANCE_STRING);
+
+  constexpr char DOUBLE_INSTANCE_STRING[] = "there_is_exactly_two_of_me";
+  constexpr size_t double_instance_size = sizeof(DOUBLE_INSTANCE_STRING) + 1;
+  char *double_instance = new char[double_instance_size];
+  char *double_instance_copy = new char[double_instance_size];
+  strcpy(double_instance, DOUBLE_INSTANCE_STRING);
+  strcpy(double_instance_copy, DOUBLE_INSTANCE_STRING);
----------------
clayborg wrote:

might be easier to use std::string here?
```
std::string str1("there_is_exactly_two_of_me");
std::string str2("there_is_exactly_two_of_me");
```
As long as more that 22 bytes are in the std::string, the string will live on the heap. Then you don't need to manually call strcpy and/or free it later.

https://github.com/llvm/llvm-project/pull/95007


More information about the lldb-commits mailing list