debug_common.C

Go to the documentation of this file.
00001 /*
00002  * See the dyninst/COPYRIGHT file for copyright information.
00003  * 
00004  * We provide the Paradyn Tools (below described as "Paradyn")
00005  * on an AS IS basis, and do not warrant its validity or performance.
00006  * We reserve the right to update, modify, or discontinue this
00007  * software at any time.  We shall have no obligation to supply such
00008  * updates or modifications or any other form of support to you.
00009  * 
00010  * By your use of Paradyn, you understand and agree that we (or any
00011  * other person or entity with proprietary rights in Paradyn) are
00012  * under no obligation to provide either maintenance services,
00013  * update services, notices of latent defects, or correction of
00014  * defects for Paradyn.
00015  * 
00016  * This library is free software; you can redistribute it and/or
00017  * modify it under the terms of the GNU Lesser General Public
00018  * License as published by the Free Software Foundation; either
00019  * version 2.1 of the License, or (at your option) any later version.
00020  * 
00021  * This library is distributed in the hope that it will be useful,
00022  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00023  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00024  * Lesser General Public License for more details.
00025  * 
00026  * You should have received a copy of the GNU Lesser General Public
00027  * License along with this library; if not, write to the Free Software
00028  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00029  */
00030 
00031 #include <stdio.h>
00032 #include <stdlib.h>
00033 #include <stdarg.h>
00034 
00035 #include "common/h/debug_common.h"
00036 
00037 int common_debug_dwarf = 0;
00038 int common_debug_addrtranslate = 0;
00039 
00040 #if defined(_MSC_VER)
00041 #pragma warning(push)
00042 #pragma warning(disable:4996) 
00043 #endif
00044 
00045 bool init_debug_common() {
00046     static bool initialized = false;
00047     if (initialized) return true;
00048     initialized = true;
00049 
00050     if (getenv("COMMON_DEBUG_DWARF") ||
00051         getenv("DYNINST_DEBUG_DWARF")) {
00052        common_debug_dwarf = 1;
00053     }
00054 
00055     if (getenv("DYNINST_DEBUG_ADDRTRANSLATE") ||
00056         getenv("DYNINST_DEBUG_TRANSLATE")) {
00057        common_debug_addrtranslate = 1;
00058     }
00059 
00060     return true;
00061 }
00062 
00063 
00064 int dwarf_printf_int(const char *format, ...)
00065 {
00066    init_debug_common();
00067   if (!common_debug_dwarf) return 0;
00068   if (NULL == format) return -1;
00069 
00070   va_list va;
00071   va_start(va, format);
00072   int ret = vfprintf(stderr, format, va);
00073   va_end(va);
00074 
00075   return ret;
00076 }
00077 
00078 int translate_printf_int(const char *format, ...)
00079 {
00080    init_debug_common();
00081   if (!common_debug_addrtranslate) return 0;
00082   if (NULL == format) return -1;
00083 
00084   va_list va;
00085   va_start(va, format);
00086   int ret = vfprintf(stderr, format, va);
00087   va_end(va);
00088 
00089   return ret;
00090 }
00091 
00092 
00093 #if defined(_MSC_VER)
00094 #pragma warning(pop)    
00095 #endif
00096 
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 12 Jul 2013 for SymtabAPI by  doxygen 1.6.1