toolkit/crashreporter/mac_utils.mm

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/crashreporter/mac_utils.mm	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,41 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include <Foundation/Foundation.h>
    1.10 +
    1.11 +#include "mac_utils.h"
    1.12 +#include "nsXPCOM.h"
    1.13 +
    1.14 +void GetObjCExceptionInfo(void* inException, nsACString& outString)
    1.15 +{
    1.16 +  NSException* e = (NSException*)inException;
    1.17 +
    1.18 +  NSString* name = [e name];
    1.19 +  NSString* reason = [e reason];
    1.20 +  unsigned int nameLength = [name length];
    1.21 +  unsigned int reasonLength = [reason length];
    1.22 +
    1.23 +  unichar* nameBuffer = (unichar*)NS_Alloc(sizeof(unichar) * (nameLength + 1));
    1.24 +  if (!nameBuffer)
    1.25 +    return;
    1.26 +  unichar* reasonBuffer = (unichar*)NS_Alloc(sizeof(unichar) * (reasonLength + 1));
    1.27 +  if (!reasonBuffer) {
    1.28 +    NS_Free(nameBuffer);
    1.29 +    return;
    1.30 +  }
    1.31 +
    1.32 +  [name getCharacters:nameBuffer];
    1.33 +  [reason getCharacters:reasonBuffer];
    1.34 +  nameBuffer[nameLength] = '\0';
    1.35 +  reasonBuffer[reasonLength] = '\0';
    1.36 +
    1.37 +  outString.AssignLiteral("\nObj-C Exception data:\n");
    1.38 +  AppendUTF16toUTF8(reinterpret_cast<const char16_t*>(nameBuffer), outString);
    1.39 +  outString.AppendLiteral(": ");
    1.40 +  AppendUTF16toUTF8(reinterpret_cast<const char16_t*>(reasonBuffer), outString);
    1.41 +
    1.42 +  NS_Free(nameBuffer);
    1.43 +  NS_Free(reasonBuffer);
    1.44 +}

mercurial