Changeset 4762301 in opengl-game


Ignore:
Timestamp:
Jun 6, 2019, 1:13:48 AM (6 years ago)
Author:
Dmitry Portnoy <dmp1488@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
17f28a1
Parents:
b373466
Message:

Make CrashLogger work for Debian-based systems

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • CrashLogger.cpp

    rb373466 r4762301  
    55#include <csignal>
    66#include <cstring>
     7#include <cstdint> // Check if this lets me remove any windows includes
    78
    89#include <fcntl.h>
     
    133134
    134135   // retrieve current stack addresses
    135    uint32_t addrlen = backtrace(addrlist, sizeof(addrlist) / sizeof(void*));
     136   unsigned int addrlen = backtrace(addrlist, sizeof(addrlist) / sizeof(void*));
    136137
    137138   if (addrlen == 0) {
     
    144145
    145146   size_t funcnamesize = 1024;
    146    char* funcname = (char*)malloc(funcnamesize);
     147   char funcname[1024];
    147148
    148149   // iterate over the returned symbol lines
    149150   // skip the first few, since those are printStackTrace, abortHandler,
    150151   // and a couple others called after the crash
    151    for (unsigned int i = 4; i < addrlen; i++) {
     152   for (unsigned int i = 0; i < addrlen; i++) {
    152153      char* begin_name = NULL;
    153154      char* begin_offset = NULL;
    154       char* end_offset = NULL; // Iirc, this is used in the Linux code (Check what it's used for)
     155      char* end_offset = NULL;
    155156
    156157#ifdef MAC
     
    158159         if ((*p == '_') && (*(p-1) == ' ')) {
    159160            begin_name = p-1;
    160          } else if(*p == '+') {
     161         } else if (*p == '+') {
    161162            begin_offset = p-1;
    162163         }
     
    175176         if (status == 0)  {
    176177            funcname = ret; // use possibly realloc()-ed string
     178            write(fd_out, "  ", 2);
    177179            write(fd_out, symbollist[i], strlen(symbollist[i]));
    178180            write(fd_out, " ", 1);
    179181            write(fd_out, funcname, strlen(funcname));
    180182            write(fd_out, " ", 1);
    181             write(fd_out, begin_offset, strlen(begin_offset));
    182183         } else {
    183184            // demangling failed. Output function name as a C function with no arguments.
    184             write(fd_out, "Error\n", 6);
     185            write(fd_out, "  ", 2);
    185186            write(fd_out, symbollist[i], strlen(symbollist[i]));
    186187            write(fd_out, " ", 1);
    187188            write(fd_out, begin_name, strlen(begin_name));
    188189            write(fd_out, "() ", 3);
     190         }
     191         write(fd_out, begin_offset, strlen(begin_offset));
     192         write(fd_out, "\n", 1);
     193      } else {`
     194         // couldn't parse the line? print the whole line.
     195         write(fd_out, symbollist[i], strlen(symbollist[i]));
     196      }
     197#else
     198      for (char *p = symbollist[i]; *p; p++) {
     199         if (*p == '(') {
     200            begin_name = p;
     201         } else if (*p == '+') {
     202            begin_offset = p;
     203         } else if (*p == ')' && (begin_offset || begin_name)) {
     204            end_offset = p;
     205         }
     206      }
     207
     208      if (begin_name && end_offset && (begin_name < end_offset)) {
     209         *begin_name++ = '\0';
     210         *end_offset++ = '\0';
     211         if (begin_offset) {
     212            *begin_offset++ = '\0';
     213         }
     214
     215         // mangled name is now in [begin_name, begin_offset) and caller
     216         // offset in [begin_offset, end_offset). now apply
     217         // __cxa_demangle():
     218         int status;
     219         char* ret = abi::__cxa_demangle(begin_name, funcname, &funcnamesize, &status);
     220
     221         write(fd_out, "  ", 2);
     222         write(fd_out, symbollist[i], strlen(symbollist[i]));
     223         write(fd_out, " ( ", 3);
     224         if (status == 0) {
     225            write(fd_out, ret, strlen(ret));
     226         } else {
     227            write(fd_out, begin_name, strlen(begin_name));
     228         }
     229         if (begin_offset) {
     230            write(fd_out, " + ", 3);
    189231            write(fd_out, begin_offset, strlen(begin_offset));
    190          }
     232         } else {
     233            write(fd_out, "         ", 9);
     234         }
     235         write(fd_out, ") ", 1);
     236         write(fd_out, end_offset, strlen(end_offset));
     237         write(fd_out, "\n", 1);
    191238      } else {
    192239         // couldn't parse the line? print the whole line.
    193240         write(fd_out, symbollist[i], strlen(symbollist[i]));
    194241      }
    195       write(fd_out, "\n", 1);
    196 #else
    197       // Check that this works on Linux Mint
    198       write(fd_out, symbollist[i], strlen(symbollist[i]));
    199       write(fd_out, "\n", 1);
    200242#endif
    201243   }
    202244
    203    free(funcname);
    204245   free(symbollist);
    205246
  • makefile

    rb373466 r4762301  
    11OS = $(shell uname)
    22CC = g++
    3 CFLAGS = -std=c++0x -Wall -pedantic#-Wextra -fno-inline
     3CFLAGS = -std=c++0x -Wall -pedantic -rdynamic
     4#-Wextra -fno-inline
    45
    56ifeq ($(OS),Darwin)
  • utils.h

    rb373466 r4762301  
    55
    66#include <glm/mat4x4.hpp>
     7#include <glm/gtc/type_ptr.hpp>
    78
    89using namespace std;
Note: See TracChangeset for help on using the changeset viewer.