2 Commits

  1. 19
      clipboard-osx.mm
  2. 12
      clipboard-win.cpp
  3. 2
      clipboard.cpp
  4. 11
      clipboard.h
  5. 42
      print.cpp

19
clipboard-osx.mm

@ -0,0 +1,19 @@
#include <AppKit/AppKit.h>
#include <Foundation/Foundation.h>
int Copy(const char* stuff) {
NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
NSInteger changeCount = [pasteboard clearContents];
NSString *nsstring = [NSString stringWithUTF8String:stuff];
NSArray *objectsToCopy = @[nsstring];
BOOL OK = [pasteboard writeObjects:objectsToCopy];
if (OK) {
return 1;
}
return 0;
}

12
clipboard-win.cpp

@ -0,0 +1,12 @@
int copy(const char* stuff, int length) {
HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, length);
memcpy(GlobalLock(hMem), output, length);
GlobalUnlock(hMem);
OpenClipboard(0);
EmptyClipboard();
SetClipboardData(CF_TEXT, hMem);
CloseClipboard();
return 0;
}

2
clipboard.cpp

@ -0,0 +1,2 @@

11
clipboard.h

@ -0,0 +1,11 @@
#ifndef ULE_CLIPBOARD_H
#define ULE_CLIPBOARD_H
namespace Clipboard {
void Copy(const char* stuff);
};
#endif

42
print.cpp

@ -119,11 +119,30 @@ void trace(String* string) {
// the names as provided by 'backtrace_symbols' are mangled for some reason. // the names as provided by 'backtrace_symbols' are mangled for some reason.
// we have to demangle them, using this weird api // we have to demangle them, using this weird api
// example mangled name (wrapped in double quotes):
// example mangled names (wrapped in double quotes):
// "2 shard_tracy 0x00000001032d5618 _ZL17drawSettingsPanelv + 904" // "2 shard_tracy 0x00000001032d5618 _ZL17drawSettingsPanelv + 904"
// "2 shard 0x000000010ed8be34 _ZN6ShaderC2EPKcS1_P5ArrayIS1_ES1_ + 1108"
// "12 shard 0x000000010ed5edeb main + 43"
//
// the rule for finding the 'first' character is annoying, because it's usually but not always starting with an underscore,
// and when it is an underscore it's usually but not always the first underscore in the string.
char buffer[1024]; char buffer[1024];
const char* mangledNameBegin = String::lastCharOccurence(traces[i], '_');
const char* mangledNameEnd = String::lastCharOccurence(traces[i], '+'); // it actually ends one char before. const char* mangledNameEnd = String::lastCharOccurence(traces[i], '+'); // it actually ends one char before.
const char* mangledNameBegin = null;
if (mangledNameEnd != null && ((mangledNameEnd - traces[i]) > 2)) {
const char* cursor = mangledNameEnd - 2;
while (cursor != traces[i]) {
if (*cursor == '_') {
mangledNameBegin = cursor;
} else if (*cursor == ' ') {
mangledNameBegin = cursor + 1;
break;
}
cursor--;
}
}
if (mangledNameBegin == null || mangledNameEnd == null) { if (mangledNameBegin == null || mangledNameEnd == null) {
// we can't demangle this name for some reason, just copy the mangled name to the buffer // we can't demangle this name for some reason, just copy the mangled name to the buffer
@ -132,7 +151,7 @@ void trace(String* string) {
buffer[length] = '\0'; buffer[length] = '\0';
} else { } else {
size_t length = mangledNameEnd - 1 - mangledNameBegin;
size_t length = mangledNameEnd - mangledNameBegin - 1;
String::memcpy(buffer, (void*)mangledNameBegin, length); String::memcpy(buffer, (void*)mangledNameBegin, length);
buffer[length] = '\0'; buffer[length] = '\0';
} }
@ -140,9 +159,20 @@ void trace(String* string) {
s32 status = -1; s32 status = -1;
char* trace = abi::__cxa_demangle(buffer, null, null, &status); char* trace = abi::__cxa_demangle(buffer, null, null, &status);
if (trace == null) { if (trace == null) {
println("warning: failed to demangle name: %s, exit status of attempt: %d", traces[i], status);
// just write back the original trace, un-demangled.
trace = traces[i];
// @HACK, both 'main' and 'start' symbols will fail to be demangled, and we don't really care about printing them
// in most cases. your application (certainly true for us) will have its own endpoint which itself is of questionable
// usefulness to print, but 'main' and 'start' are even less useful.
if (String::memeq((const unsigned char*)(mangledNameBegin), (const unsigned char*)"main", sizeof("main") - 1)) {
continue;
} else if (String::memeq((const unsigned char*)(mangledNameBegin), (const unsigned char*)"start", sizeof("start") - 1)) {
continue;
} else {
println("warning: failed to demangle name: %s, exit status of attempt: %d", traces[i], status);
// just write back the original trace, un-demangled.
trace = traces[i];
}
} }
if (string == null) { if (string == null) {

Loading…
Cancel
Save