[Lldb-commits] [PATCH] D54886: Add support for the Dylan language to ClangASTContext

2018-11-26 Thread Peter S. Housel via Phabricator via lldb-commits
housel updated this revision to Diff 175385.
housel added a comment.

Adds an inline comment about Open Dylan debug info


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D54886/new/

https://reviews.llvm.org/D54886

Files:
  source/Symbol/ClangASTContext.cpp


Index: source/Symbol/ClangASTContext.cpp
===
--- source/Symbol/ClangASTContext.cpp
+++ source/Symbol/ClangASTContext.cpp
@@ -119,7 +119,9 @@
  language == eLanguageTypeRust ||
  language == eLanguageTypeExtRenderScript ||
  // Use Clang for D until there is a proper language plugin for it
- language == eLanguageTypeD;
+ language == eLanguageTypeD ||
+ // Open Dylan compiler debug info is designed to be Clang-compatible
+ language == eLanguageTypeDylan;
 }
 
 // Checks whether m1 is an overload of m2 (as opposed to an override). This is


Index: source/Symbol/ClangASTContext.cpp
===
--- source/Symbol/ClangASTContext.cpp
+++ source/Symbol/ClangASTContext.cpp
@@ -119,7 +119,9 @@
  language == eLanguageTypeRust ||
  language == eLanguageTypeExtRenderScript ||
  // Use Clang for D until there is a proper language plugin for it
- language == eLanguageTypeD;
+ language == eLanguageTypeD ||
+ // Open Dylan compiler debug info is designed to be Clang-compatible
+ language == eLanguageTypeDylan;
 }
 
 // Checks whether m1 is an overload of m2 (as opposed to an override). This is
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D54886: Add support for the Dylan language to ClangASTContext

2018-11-26 Thread Peter S. Housel via Phabricator via lldb-commits
housel added a comment.

I don't have commit access; could someone land this please? Thanks.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D54886/new/

https://reviews.llvm.org/D54886



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D54886: Add support for the Dylan language to ClangASTContext

2018-11-26 Thread Peter S. Housel via Phabricator via lldb-commits
housel updated this revision to Diff 175391.
housel added a comment.

Updated against r347619


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D54886/new/

https://reviews.llvm.org/D54886

Files:
  source/Symbol/ClangASTContext.cpp


Index: source/Symbol/ClangASTContext.cpp
===
--- source/Symbol/ClangASTContext.cpp
+++ source/Symbol/ClangASTContext.cpp
@@ -119,7 +119,9 @@
  language == eLanguageTypeRust ||
  language == eLanguageTypeExtRenderScript ||
  // Use Clang for D until there is a proper language plugin for it
- language == eLanguageTypeD;
+ language == eLanguageTypeD ||
+ // Open Dylan compiler debug info is designed to be Clang-compatible
+ language == eLanguageTypeDylan;
 }
 
 // Checks whether m1 is an overload of m2 (as opposed to an override). This is


Index: source/Symbol/ClangASTContext.cpp
===
--- source/Symbol/ClangASTContext.cpp
+++ source/Symbol/ClangASTContext.cpp
@@ -119,7 +119,9 @@
  language == eLanguageTypeRust ||
  language == eLanguageTypeExtRenderScript ||
  // Use Clang for D until there is a proper language plugin for it
- language == eLanguageTypeD;
+ language == eLanguageTypeD ||
+ // Open Dylan compiler debug info is designed to be Clang-compatible
+ language == eLanguageTypeDylan;
 }
 
 // Checks whether m1 is an overload of m2 (as opposed to an override). This is
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D105389: [lldb] Add AllocateMemory/DeallocateMemory to the SBProcess API

2021-07-02 Thread Peter S. Housel via Phabricator via lldb-commits
housel created this revision.
housel added a reviewer: clayborg.
housel requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

This change adds AllocateMemory and DeallocateMemory methods to the SBProcess 
API, so that clients can allocate and deallocate memory blocks within the 
process being debugged (for storing JIT-compiled code or other uses).

(I am developing a debugger + REPL using the API; it will need to store 
JIT-compiled code within the target.)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105389

Files:
  lldb/bindings/interface/SBProcess.i
  lldb/include/lldb/API/SBProcess.h
  lldb/source/API/SBProcess.cpp
  lldb/test/API/python_api/process/TestProcessAPI.py

Index: lldb/test/API/python_api/process/TestProcessAPI.py
===
--- lldb/test/API/python_api/process/TestProcessAPI.py
+++ lldb/test/API/python_api/process/TestProcessAPI.py
@@ -398,3 +398,55 @@
 "Process effective group ID is invalid")
 
 process_info.GetParentProcessID()
+
+def test_allocate_deallocate_memory(self):
+"""Test Python SBProcess.AllocateMemory() and SBProcess.DeallocateMemory() APIs."""
+self.build()
+exe = self.getBuildArtifact("a.out")
+
+target = self.dbg.CreateTarget(exe)
+self.assertTrue(target, VALID_TARGET)
+
+breakpoint = target.BreakpointCreateByLocation("main.cpp", self.line)
+self.assertTrue(breakpoint, VALID_BREAKPOINT)
+
+# Launch the process, and do not stop at the entry point.
+process = target.LaunchSimple(
+None, None, self.get_process_working_directory())
+
+thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint)
+self.assertTrue(
+thread.IsValid(),
+"There should be a thread stopped due to breakpoint")
+frame = thread.GetFrameAtIndex(0)
+
+# Allocate a block of memory in the target process
+error = lldb.SBError()
+addr = process.AllocateMemory(16384, lldb.ePermissionsWritable | lldb.ePermissionsReadable, error)
+if not error.Success() or addr == lldb.LLDB_INVALID_ADDRESS:
+self.fail("SBProcess.AllocateMemory() failed")
+
+# Now use WriteMemory() API to write 'a' into the allocated memory
+result = process.WriteMemory(addr, 'a', error)
+if not error.Success() or result != 1:
+self.fail("SBProcess.WriteMemory() failed")
+
+# Read from the memory location.  This time it should be 'a'.
+# Due to the typemap magic (see lldb.swig), we pass in 1 to ReadMemory and
+# expect to get a Python string as the result object!
+content = process.ReadMemory(addr, 1, error)
+if not error.Success():
+self.fail("SBProcess.ReadMemory() failed")
+if self.TraceOn():
+print("memory content:", content)
+
+self.expect(
+content,
+"Result from SBProcess.ReadMemory() matches our expected output: 'a'",
+exe=False,
+startstr=b'a')
+
+# Deallocate the memory
+error = process.DeallocateMemory(addr)
+if not error.Success():
+self.fail("SBProcess.DeallocateMemory() failed")
Index: lldb/source/API/SBProcess.cpp
===
--- lldb/source/API/SBProcess.cpp
+++ lldb/source/API/SBProcess.cpp
@@ -1288,6 +1288,50 @@
   return LLDB_RECORD_RESULT(sb_proc_info);
 }
 
+lldb::addr_t SBProcess::AllocateMemory(size_t size, uint32_t permissions, lldb::SBError &sb_error) {
+  LLDB_RECORD_METHOD(lldb::addr_t, SBProcess, AllocateMemory,
+ (size_t, uint32_t, lldb::SBError &), size, permissions, sb_error);
+
+  lldb::addr_t addr = LLDB_INVALID_ADDRESS;
+  ProcessSP process_sp(GetSP());
+  if (process_sp) {
+Process::StopLocker stop_locker;
+if (stop_locker.TryLock(&process_sp->GetRunLock())) {
+  std::lock_guard guard(
+  process_sp->GetTarget().GetAPIMutex());
+  addr = process_sp->AllocateMemory(size, permissions, sb_error.ref());
+} else {
+  sb_error.SetErrorString("process is running");
+}
+  } else {
+sb_error.SetErrorString("SBProcess is invalid");
+  }
+  return addr;
+}
+
+lldb::SBError SBProcess::DeallocateMemory(lldb::addr_t ptr) {
+  LLDB_RECORD_METHOD(lldb::SBError, SBProcess, DeallocateMemory, (lldb::addr_t),
+ ptr);
+
+  lldb::SBError sb_error;
+  ProcessSP process_sp(GetSP());
+  if (process_sp) {
+Process::StopLocker stop_locker;
+if (stop_locker.TryLock(&process_sp->GetRunLock())) {
+  std::lock_guard guard(
+  process_sp->GetTarget().GetAPIMutex());
+  Status error = process_sp->DeallocateMemory(ptr);
+  sb_error.SetError(error);
+} else {
+  sb_error.SetErrorString("process is running");
+}
+  } else {
+sb_error.SetError

[Lldb-commits] [PATCH] D105389: [lldb] Add AllocateMemory/DeallocateMemory to the SBProcess API

2021-07-02 Thread Peter S. Housel via Phabricator via lldb-commits
housel updated this revision to Diff 356324.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105389/new/

https://reviews.llvm.org/D105389

Files:
  lldb/bindings/interface/SBProcess.i
  lldb/include/lldb/API/SBProcess.h
  lldb/source/API/SBProcess.cpp
  lldb/test/API/python_api/process/TestProcessAPI.py

Index: lldb/test/API/python_api/process/TestProcessAPI.py
===
--- lldb/test/API/python_api/process/TestProcessAPI.py
+++ lldb/test/API/python_api/process/TestProcessAPI.py
@@ -398,3 +398,55 @@
 "Process effective group ID is invalid")
 
 process_info.GetParentProcessID()
+
+def test_allocate_deallocate_memory(self):
+"""Test Python SBProcess.AllocateMemory() and SBProcess.DeallocateMemory() APIs."""
+self.build()
+exe = self.getBuildArtifact("a.out")
+
+target = self.dbg.CreateTarget(exe)
+self.assertTrue(target, VALID_TARGET)
+
+breakpoint = target.BreakpointCreateByLocation("main.cpp", self.line)
+self.assertTrue(breakpoint, VALID_BREAKPOINT)
+
+# Launch the process, and do not stop at the entry point.
+process = target.LaunchSimple(
+None, None, self.get_process_working_directory())
+
+thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint)
+self.assertTrue(
+thread.IsValid(),
+"There should be a thread stopped due to breakpoint")
+frame = thread.GetFrameAtIndex(0)
+
+# Allocate a block of memory in the target process
+error = lldb.SBError()
+addr = process.AllocateMemory(16384, lldb.ePermissionsWritable | lldb.ePermissionsReadable, error)
+if not error.Success() or addr == lldb.LLDB_INVALID_ADDRESS:
+self.fail("SBProcess.AllocateMemory() failed")
+
+# Now use WriteMemory() API to write 'a' into the allocated memory
+result = process.WriteMemory(addr, 'a', error)
+if not error.Success() or result != 1:
+self.fail("SBProcess.WriteMemory() failed")
+
+# Read from the memory location.  This time it should be 'a'.
+# Due to the typemap magic (see lldb.swig), we pass in 1 to ReadMemory and
+# expect to get a Python string as the result object!
+content = process.ReadMemory(addr, 1, error)
+if not error.Success():
+self.fail("SBProcess.ReadMemory() failed")
+if self.TraceOn():
+print("memory content:", content)
+
+self.expect(
+content,
+"Result from SBProcess.ReadMemory() matches our expected output: 'a'",
+exe=False,
+startstr=b'a')
+
+# Deallocate the memory
+error = process.DeallocateMemory(addr)
+if not error.Success():
+self.fail("SBProcess.DeallocateMemory() failed")
Index: lldb/source/API/SBProcess.cpp
===
--- lldb/source/API/SBProcess.cpp
+++ lldb/source/API/SBProcess.cpp
@@ -1288,6 +1288,51 @@
   return LLDB_RECORD_RESULT(sb_proc_info);
 }
 
+lldb::addr_t SBProcess::AllocateMemory(size_t size, uint32_t permissions,
+   lldb::SBError &sb_error) {
+  LLDB_RECORD_METHOD(lldb::addr_t, SBProcess, AllocateMemory,
+ (size_t, uint32_t, lldb::SBError &), size, permissions,
+ sb_error);
+
+  lldb::addr_t addr = LLDB_INVALID_ADDRESS;
+  ProcessSP process_sp(GetSP());
+  if (process_sp) {
+Process::StopLocker stop_locker;
+if (stop_locker.TryLock(&process_sp->GetRunLock())) {
+  std::lock_guard guard(
+  process_sp->GetTarget().GetAPIMutex());
+  addr = process_sp->AllocateMemory(size, permissions, sb_error.ref());
+} else {
+  sb_error.SetErrorString("process is running");
+}
+  } else {
+sb_error.SetErrorString("SBProcess is invalid");
+  }
+  return addr;
+}
+
+lldb::SBError SBProcess::DeallocateMemory(lldb::addr_t ptr) {
+  LLDB_RECORD_METHOD(lldb::SBError, SBProcess, DeallocateMemory, (lldb::addr_t),
+ ptr);
+
+  lldb::SBError sb_error;
+  ProcessSP process_sp(GetSP());
+  if (process_sp) {
+Process::StopLocker stop_locker;
+if (stop_locker.TryLock(&process_sp->GetRunLock())) {
+  std::lock_guard guard(
+  process_sp->GetTarget().GetAPIMutex());
+  Status error = process_sp->DeallocateMemory(ptr);
+  sb_error.SetError(error);
+} else {
+  sb_error.SetErrorString("process is running");
+}
+  } else {
+sb_error.SetErrorString("SBProcess is invalid");
+  }
+  return sb_error;
+}
+
 namespace lldb_private {
 namespace repro {
 
@@ -1417,6 +1462,10 @@
   LLDB_REGISTER_METHOD(lldb::SBMemoryRegionInfoList, SBProcess,
GetMemoryRegions, ());
   LLDB_REGISTER_METHOD(lldb::SBProcessInfo, SBProcess, GetProcessInfo, ());
+  LLDB_REGISTER_METHOD(lldb::addr_t, SBProcess, AllocateMem

[Lldb-commits] [PATCH] D105389: [lldb] Add AllocateMemory/DeallocateMemory to the SBProcess API

2021-07-07 Thread Peter S. Housel via Phabricator via lldb-commits
housel updated this revision to Diff 357131.
housel added a comment.

Updated based on reviewer suggestions, thanks.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105389/new/

https://reviews.llvm.org/D105389

Files:
  lldb/bindings/interface/SBProcess.i
  lldb/include/lldb/API/SBProcess.h
  lldb/source/API/SBProcess.cpp
  lldb/test/API/python_api/process/TestProcessAPI.py
  lldb/test/API/python_api/process/main.cpp

Index: lldb/test/API/python_api/process/main.cpp
===
--- lldb/test/API/python_api/process/main.cpp
+++ lldb/test/API/python_api/process/main.cpp
@@ -21,3 +21,13 @@
 return 0; // Set break point at this line and check variable 'my_char'.
   // Use lldb Python API to set memory content for my_int and check the result.
 }
+
+char test_read (char *ptr)
+{
+return *ptr;
+}
+
+void test_write (char *ptr, char c)
+{
+*ptr = c;
+}
Index: lldb/test/API/python_api/process/TestProcessAPI.py
===
--- lldb/test/API/python_api/process/TestProcessAPI.py
+++ lldb/test/API/python_api/process/TestProcessAPI.py
@@ -398,3 +398,58 @@
 "Process effective group ID is invalid")
 
 process_info.GetParentProcessID()
+
+def test_allocate_deallocate_memory(self):
+"""Test Python SBProcess.AllocateMemory() and SBProcess.DeallocateMemory() APIs."""
+self.build()
+(target, process, main_thread, main_breakpoint) = lldbutil.run_to_source_breakpoint(
+self, "// Set break point at this line", lldb.SBFileSpec("main.cpp"))
+
+# Allocate a block of memory in the target process
+error = lldb.SBError()
+addr = process.AllocateMemory(16384, lldb.ePermissionsReadable, error)
+if not error.Success() or addr == lldb.LLDB_INVALID_ADDRESS:
+self.fail("SBProcess.AllocateMemory() failed")
+
+# Now use WriteMemory() API to write 'a' into the allocated
+# memory. Note that the debugger can do this even though the
+# block is not set writable.
+result = process.WriteMemory(addr, 'a', error)
+if not error.Success() or result != 1:
+self.fail("SBProcess.WriteMemory() failed")
+
+# Read from the memory location.  This time it should be 'a'.
+# Due to the typemap magic (see lldb.swig), we pass in 1 to ReadMemory and
+# expect to get a Python string as the result object!
+content = process.ReadMemory(addr, 1, error)
+if not error.Success():
+self.fail("SBProcess.ReadMemory() failed")
+if self.TraceOn():
+print("memory content:", content)
+
+self.expect(
+content,
+"Result from SBProcess.ReadMemory() matches our expected output: 'a'",
+exe=False,
+startstr=b'a')
+
+# Verify that the process itself can read the allocated memory
+frame = main_thread.GetFrameAtIndex(0)
+val = frame.EvaluateExpression(
+"test_read(reinterpret_cast({:#x}))".format(addr))
+self.expect(val.GetValue(),
+"Result of test_read() matches expected output 'a'",
+exe=False,
+startstr="'a'")
+
+# Verify that the process cannot write into the block
+val = frame.EvaluateExpression(
+"test_write(reinterpret_cast({:#x}), 'b')".format(addr))
+if val.GetError().Success():
+self.fail(
+"test_write() to allocated memory without write permission unexpectedly succeeded")
+
+# Deallocate the memory
+error = process.DeallocateMemory(addr)
+if not error.Success():
+self.fail("SBProcess.DeallocateMemory() failed")
Index: lldb/source/API/SBProcess.cpp
===
--- lldb/source/API/SBProcess.cpp
+++ lldb/source/API/SBProcess.cpp
@@ -1288,6 +1288,51 @@
   return LLDB_RECORD_RESULT(sb_proc_info);
 }
 
+lldb::addr_t SBProcess::AllocateMemory(size_t size, uint32_t permissions,
+   lldb::SBError &sb_error) {
+  LLDB_RECORD_METHOD(lldb::addr_t, SBProcess, AllocateMemory,
+ (size_t, uint32_t, lldb::SBError &), size, permissions,
+ sb_error);
+
+  lldb::addr_t addr = LLDB_INVALID_ADDRESS;
+  ProcessSP process_sp(GetSP());
+  if (process_sp) {
+Process::StopLocker stop_locker;
+if (stop_locker.TryLock(&process_sp->GetRunLock())) {
+  std::lock_guard guard(
+  process_sp->GetTarget().GetAPIMutex());
+  addr = process_sp->AllocateMemory(size, permissions, sb_error.ref());
+} else {
+  sb_error.SetErrorString("process is running");
+}
+  } else {
+sb_error.SetErrorString("SBProcess is invalid");
+  }
+  return addr;
+}
+
+lldb::SBError SBProcess::DeallocateMemory(lldb::addr_t ptr) {
+  LLDB_RECORD_

[Lldb-commits] [PATCH] D105389: [lldb] Add AllocateMemory/DeallocateMemory to the SBProcess API

2021-07-08 Thread Peter S. Housel via Phabricator via lldb-commits
housel added a comment.

In D105389#2864941 , @clayborg wrote:

> LGTM. Jim, chime in soon if you have any other objections!

I don't have commit access, could some one take care of committing this for me? 
Thanks!


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105389/new/

https://reviews.llvm.org/D105389

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits