aboutsummaryrefslogtreecommitdiff
path: root/src/client/minidump_file_writer.h
diff options
context:
space:
mode:
authorwaylonis <waylonis@4c0a9323-5329-0410-9bdc-e9ce6186880e>2006-12-16 01:01:19 +0000
committerwaylonis <waylonis@4c0a9323-5329-0410-9bdc-e9ce6186880e>2006-12-16 01:01:19 +0000
commita2fa3dda54c9684c3d85ed116ea8b916a8fe210e (patch)
treec54043dd88340ba1da031f28c802fa7d4cfed691 /src/client/minidump_file_writer.h
parentAdd unittest for minidump file writer. Fixes issue #85. (diff)
downloadbreakpad-a2fa3dda54c9684c3d85ed116ea8b916a8fe210e.tar.xz
Add better support for UTF character conversions. Fixes Issue 78.
git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@91 4c0a9323-5329-0410-9bdc-e9ce6186880e
Diffstat (limited to 'src/client/minidump_file_writer.h')
-rw-r--r--src/client/minidump_file_writer.h56
1 files changed, 44 insertions, 12 deletions
diff --git a/src/client/minidump_file_writer.h b/src/client/minidump_file_writer.h
index 9f270b1e..1f3a3680 100644
--- a/src/client/minidump_file_writer.h
+++ b/src/client/minidump_file_writer.h
@@ -27,7 +27,9 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// minidump_file_writer.h: Implements file-based minidump generation
+// minidump_file_writer.h: Implements file-based minidump generation. It's
+// intended to be used with the Google Airbag open source crash handling
+// project.
#ifndef CLIENT_MINIDUMP_FILE_WRITER_H__
#define CLIENT_MINIDUMP_FILE_WRITER_H__
@@ -38,11 +40,26 @@
namespace google_airbag {
+class UntypedMDRVA;
+template<typename MDType> class TypedMDRVA;
+
+// The user of this class can Open() a file and add minidump streams, data, and
+// strings using the definitions in minidump_format.h. Since this class is
+// expected to be used in a situation where the current process may be
+// damaged, it will not allocate heap memory.
+// Sample usage:
+// MinidumpFileWriter writer;
+// writer.Open("/tmp/minidump.dmp");
+// TypedMDRVA<MDRawHeader> header(&writer_);
+// header.Allocate();
+// header->get()->signature = MD_HEADER_SIGNATURE;
+// :
+// writer.Close();
class MinidumpFileWriter {
- public:
+public:
// Invalid MDRVA (Minidump Relative Virtual Address)
// returned on failed allocation
- static const MDRVA kInvalidMDRVA = static_cast<MDRVA>(-1);
+ static const MDRVA kInvalidMDRVA;
MinidumpFileWriter();
~MinidumpFileWriter();
@@ -50,13 +67,13 @@ class MinidumpFileWriter {
// Open |path| as the destination of the minidump data. Any existing file
// will be overwritten.
// Return true on success, or false on failure
- bool Open(const std::string &path);
+ bool Open(const char *path);
// Close the current file
// Return true on success, or false on failure
bool Close();
- // Write |str| to a MDString.
+ // Copy the contents of |str| to a MDString and write it to the file.
// |str| is expected to be either UTF-16 or UTF-32 depending on the size
// of wchar_t.
// Maximum |length| of characters to copy from |str|, or specify 0 to use the
@@ -66,7 +83,7 @@ class MinidumpFileWriter {
bool WriteString(const wchar_t *str, unsigned int length,
MDLocationDescriptor *location);
- // Similar to above with |str| as an UTF-8 encoded string
+ // Same as above, except with |str| as a UTF-8 string
bool WriteString(const char *str, unsigned int length,
MDLocationDescriptor *location);
@@ -79,7 +96,7 @@ class MinidumpFileWriter {
bool Copy(MDRVA position, const void *src, ssize_t size);
// Return the current position for writing to the minidump
- MDRVA position() const { return position_; }
+ inline MDRVA position() const { return position_; }
private:
friend class UntypedMDRVA;
@@ -97,6 +114,21 @@ class MinidumpFileWriter {
// Current allocated size
size_t size_;
+
+ // Copy |length| characters from |str| to |mdstring|. These are distinct
+ // because the underlying MDString is a UTF-16 based string. The wchar_t
+ // variant may need to create a MDString that has more characters than the
+ // source |str|, whereas the UTF-8 variant may coalesce characters to form
+ // a single UTF-16 character.
+ bool CopyStringToMDString(const wchar_t *str, unsigned int length,
+ TypedMDRVA<MDString> *mdstring);
+ bool CopyStringToMDString(const char *str, unsigned int length,
+ TypedMDRVA<MDString> *mdstring);
+
+ // The common templated code for writing a string
+ template <typename CharType>
+ bool WriteStringCore(const CharType *str, unsigned int length,
+ MDLocationDescriptor *location);
};
// Represents an untyped allocated chunk
@@ -112,13 +144,13 @@ class UntypedMDRVA {
bool Allocate(size_t size);
// Returns the current position or kInvalidMDRVA if allocation failed
- MDRVA position() const { return position_; }
+ inline MDRVA position() const { return position_; }
// Number of bytes allocated
- size_t size() const { return size_; }
+ inline size_t size() const { return size_; }
// Return size and position
- MDLocationDescriptor location() const {
+ inline MDLocationDescriptor location() const {
MDLocationDescriptor location = { size_, position_ };
return location;
}
@@ -128,7 +160,7 @@ class UntypedMDRVA {
bool Copy(MDRVA position, const void *src, size_t size);
// Copy |size| bytes from |src| to the current position
- bool Copy(const void *src, size_t size) {
+ inline bool Copy(const void *src, size_t size) {
return Copy(position_, src, size);
}
@@ -157,7 +189,7 @@ class TypedMDRVA : public UntypedMDRVA {
data_(),
allocation_state_(UNALLOCATED) {}
- ~TypedMDRVA() {
+ inline ~TypedMDRVA() {
// Ensure that the data_ object is written out
if (allocation_state_ != ARRAY)
Flush();