[haiku-commits] r33589 - haiku/trunk/src/apps/debugger/model

  • From: ingo_weinhold@xxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Thu, 15 Oct 2009 06:34:59 +0200 (CEST)

Author: bonefish
Date: 2009-10-15 06:34:59 +0200 (Thu, 15 Oct 2009)
New Revision: 33589
Changeset: http://dev.haiku-os.org/changeset/33589/haiku

Modified:
   haiku/trunk/src/apps/debugger/model/TeamMemory.cpp
   haiku/trunk/src/apps/debugger/model/TeamMemory.h
Log:
Added ReadMemoryString(), reading a string from the team's memory.


Modified: haiku/trunk/src/apps/debugger/model/TeamMemory.cpp
===================================================================
--- haiku/trunk/src/apps/debugger/model/TeamMemory.cpp  2009-10-15 04:33:26 UTC 
(rev 33588)
+++ haiku/trunk/src/apps/debugger/model/TeamMemory.cpp  2009-10-15 04:34:59 UTC 
(rev 33589)
@@ -3,9 +3,52 @@
  * Distributed under the terms of the MIT License.
  */
 
+
 #include "TeamMemory.h"
 
+#include <algorithm>
 
+#include <OS.h>
+#include <String.h>
+
+
 TeamMemory::~TeamMemory()
 {
 }
+
+
+status_t
+TeamMemory::ReadMemoryString(target_addr_t address, size_t maxLength,
+       BString& _string)
+{
+       char buffer[B_PAGE_SIZE];
+
+       BString string;
+
+       while (maxLength > 0) {
+               // read at max maxLength bytes, but don't read across page 
bounds
+               size_t toRead = std::min(maxLength,
+                       B_PAGE_SIZE - size_t(address % B_PAGE_SIZE));
+
+               ssize_t bytesRead = ReadMemory(address, buffer, toRead);
+               if (bytesRead < 0)
+                       return string.Length() == 0 ? bytesRead : B_OK;
+
+               if (bytesRead == 0)
+                       return string.Length() == 0 ? B_BAD_ADDRESS : B_OK;
+
+               // append the bytes read
+               size_t length = strnlen(buffer, bytesRead);
+               string.Append(buffer, length);
+
+               // stop at end of string
+               if (length < (size_t)bytesRead)
+                       return B_OK;
+
+               address += bytesRead;
+               maxLength -= bytesRead;
+       }
+
+       return B_OK;
+}
+

Modified: haiku/trunk/src/apps/debugger/model/TeamMemory.h
===================================================================
--- haiku/trunk/src/apps/debugger/model/TeamMemory.h    2009-10-15 04:33:26 UTC 
(rev 33588)
+++ haiku/trunk/src/apps/debugger/model/TeamMemory.h    2009-10-15 04:34:59 UTC 
(rev 33589)
@@ -5,9 +5,13 @@
 #ifndef TEAM_MEMORY_H
 #define TEAM_MEMORY_H
 
+
 #include "TargetAddressRange.h"
 
 
+class BString;
+
+
 class TeamMemory {
 public:
        virtual                                         ~TeamMemory();
@@ -15,6 +19,8 @@
 
        virtual ssize_t                         ReadMemory(target_addr_t 
address, void* buffer,
                                                                        size_t 
size) = 0;
+       virtual status_t                        ReadMemoryString(target_addr_t 
address,
+                                                                       size_t 
maxLength, BString& _string);
 };
 
 


Other related posts:

  • » [haiku-commits] r33589 - haiku/trunk/src/apps/debugger/model - ingo_weinhold