/[svn]/linuxsampler/trunk/src/common/global_private.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/common/global_private.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3762 by schoenebeck, Sun Sep 15 17:55:56 2013 UTC revision 3763 by schoenebeck, Sun Apr 5 20:15:57 2020 UTC
# Line 3  Line 3 
3   *   LinuxSampler - modular, streaming capable sampler                     *   *   LinuxSampler - modular, streaming capable sampler                     *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *
6   *   Copyright (C) 2005 - 2013 Christian Schoenebeck                       *   *   Copyright (C) 2005 - 2020 Christian Schoenebeck                       *
7   *                                                                         *   *                                                                         *
8   *   This program is free software; you can redistribute it and/or modify  *   *   This program is free software; you can redistribute it and/or modify  *
9   *   it under the terms of the GNU General Public License as published by  *   *   it under the terms of the GNU General Public License as published by  *
# Line 28  Line 28 
28  # include <config.h>  # include <config.h>
29  #endif  #endif
30    
31    #include <stdlib.h>
32    #include <stdarg.h>
33    #include <stdio.h>
34    #include <string>
35    #if !defined(WIN32)
36    # include <execinfo.h> // for backtrace() and backtrace_symbols()
37    #endif
38    #if defined (__APPLE__)
39    # include <mach-o/dyld.h>
40    #endif
41    
42  // Make sure all mandatory configuration macros are defined.  // Make sure all mandatory configuration macros are defined.
43  // We don't care about optional configuration macros though.  // We don't care about optional configuration macros though.
44  #ifndef CONFIG_GLOBAL_ATTENUATION_DEFAULT  #ifndef CONFIG_GLOBAL_ATTENUATION_DEFAULT
# Line 140  int hexToNumber(char hex_digit) { Line 151  int hexToNumber(char hex_digit) {
151  int hexsToNumber(char hex_digit0, char hex_digit1) {  int hexsToNumber(char hex_digit0, char hex_digit1) {
152      return hexToNumber(hex_digit1)*16 + hexToNumber(hex_digit0);      return hexToNumber(hex_digit1)*16 + hexToNumber(hex_digit0);
153  }  }
154    
155    #if defined (__APPLE__)
156    
157    static std::string dyldImagesAsString() {
158        std::string s;
159        const uint32_t n = _dyld_image_count();
160        for (uint32_t i = 0; i < n; ++i) {
161            const std::string name = _dyld_get_image_name(i);
162    
163            // ignore system frameworks
164            // (as we don't have their source files anyway, do we?)
165            if (name.find("/System/Library/") == 0)
166                continue;
167            if (name.find("/usr/lib/") != std::string::npos)
168                continue;
169    
170            const intptr_t slide = _dyld_get_image_vmaddr_slide(i);
171            const struct mach_header* loadaddr = _dyld_get_image_header(i);
172            char* cs = NULL;
173            asprintf(&cs, "%d. '%s' loadaddr %p, slide %p\n", i+1, name.c_str(), loadaddr, (void*)slide);
174            s += cs;
175            free(cs);
176        }
177        return s;
178    }
179    
180    #endif
181    
182    /** @brief Return a backtrace of call.
183     *
184     * Calling this function will return the calling stack as text representation
185     * for debugging purposes.
186     */
187    std::string backtraceAsString() {
188        std::string s;
189        #ifdef WIN32
190        //TODO: Windows implementation using CaptureStackBackTrace() (plus maybe SymFromAddr())
191        s = "not implemented";
192        #else
193        # ifdef __APPLE__
194        s += dyldImagesAsString();
195        s += "   \n\n";
196        # endif
197        const size_t bufSz = 1024;
198        void* array[bufSz];
199        const size_t sz = backtrace(array, bufSz);
200        char** strings = backtrace_symbols(array, sz);
201        for (int i = 0; i < sz; ++i) {
202            s += strings[i];
203            s += "\n";
204        }
205        free(strings);
206        #endif
207        return s;
208    }

Legend:
Removed from v.3762  
changed lines
  Added in v.3763

  ViewVC Help
Powered by ViewVC