From: Nicholas Nethercote Date: Sun, 8 May 2005 18:34:59 +0000 (+0000) Subject: Moved mc_errcontext.c into mc_main.c, since it was very small and there was X-Git-Tag: svn/VALGRIND_3_0_0~677 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=020fa40bb0e0ce8addea2681ba73ab89abbcaa87;p=thirdparty%2Fvalgrind.git Moved mc_errcontext.c into mc_main.c, since it was very small and there was no benefit in having it separate. This allows some exports to be removed from mc_include.h. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@3641 --- diff --git a/memcheck/Makefile.am b/memcheck/Makefile.am index 71c351f295..c964733f49 100644 --- a/memcheck/Makefile.am +++ b/memcheck/Makefile.am @@ -17,7 +17,6 @@ vgtool_memcheck_so_SOURCES = \ mac_leakcheck.c \ mac_malloc_wrappers.c \ mac_needs.c \ - mc_errcontext.c \ mc_main.c \ mc_translate.c vgtool_memcheck_so_LDFLAGS = -shared diff --git a/memcheck/mc_errcontext.c b/memcheck/mc_errcontext.c deleted file mode 100644 index 101485d407..0000000000 --- a/memcheck/mc_errcontext.c +++ /dev/null @@ -1,152 +0,0 @@ - -/*--------------------------------------------------------------------*/ -/*--- Management of memory error messages. ---*/ -/*--- mc_errcontext.c ---*/ -/*--------------------------------------------------------------------*/ - -/* - This file is part of MemCheck, a heavyweight Valgrind tool for - detecting memory errors. - - Copyright (C) 2000-2005 Julian Seward - jseward@acm.org - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307, USA. - - The GNU General Public License is contained in the file COPYING. -*/ - -#include "mc_include.h" - -/*------------------------------------------------------------*/ -/*--- Printing errors ---*/ -/*------------------------------------------------------------*/ - -void TL_(pp_Error) ( Error* err ) -{ - MAC_Error* err_extra = VG_(get_error_extra)(err); - - switch (VG_(get_error_kind)(err)) { - case CoreMemErr: { - Char* s = ( err_extra->isUnaddr ? "unaddressable" : "uninitialised" ); - VG_(message)(Vg_UserMsg, "%s contains %s byte(s)", - VG_(get_error_string)(err), s); - VG_(pp_ExeContext)( VG_(get_error_where)(err) ); - break; - - } - - case ValueErr: - if (err_extra->size == 0) { - VG_(message)(Vg_UserMsg, - "Conditional jump or move depends on uninitialised value(s)"); - } else { - VG_(message)(Vg_UserMsg, - "Use of uninitialised value of size %d", - err_extra->size); - } - VG_(pp_ExeContext)( VG_(get_error_where)(err) ); - break; - - case ParamErr: { - Bool isReg = ( Register == err_extra->addrinfo.akind ); - Char* s1 = ( isReg ? "contains" : "points to" ); - Char* s2 = ( err_extra->isUnaddr ? "unaddressable" : "uninitialised" ); - if (isReg) tl_assert(!err_extra->isUnaddr); - - VG_(message)(Vg_UserMsg, "Syscall param %s %s %s byte(s)", - VG_(get_error_string)(err), s1, s2); - - VG_(pp_ExeContext)( VG_(get_error_where)(err) ); - MAC_(pp_AddrInfo)(VG_(get_error_address)(err), &err_extra->addrinfo); - break; - } - case UserErr: { - Char* s = ( err_extra->isUnaddr ? "Unaddressable" : "Uninitialised" ); - - VG_(message)(Vg_UserMsg, - "%s byte(s) found during client check request", s); - - VG_(pp_ExeContext)( VG_(get_error_where)(err) ); - MAC_(pp_AddrInfo)(VG_(get_error_address)(err), &err_extra->addrinfo); - break; - } - default: - MAC_(pp_shared_Error)(err); - break; - } -} - -/*------------------------------------------------------------*/ -/*--- Recording errors ---*/ -/*------------------------------------------------------------*/ - -/* Creates a copy of the `extra' part, updates the copy with address info if - necessary, and returns the copy. */ -/* This one called from generated code and non-generated code. */ -void MC_(record_value_error) ( ThreadId tid, Int size ) -{ - MAC_Error err_extra; - - MAC_(clear_MAC_Error)( &err_extra ); - err_extra.size = size; - err_extra.isUnaddr = False; - VG_(maybe_record_error)( tid, ValueErr, /*addr*/0, /*s*/NULL, &err_extra ); -} - -/* This called from non-generated code */ - -void MC_(record_user_error) ( ThreadId tid, Addr a, Bool isWrite, - Bool isUnaddr ) -{ - MAC_Error err_extra; - - tl_assert(VG_INVALID_THREADID != tid); - MAC_(clear_MAC_Error)( &err_extra ); - err_extra.addrinfo.akind = Undescribed; - err_extra.isUnaddr = isUnaddr; - VG_(maybe_record_error)( tid, UserErr, a, /*s*/NULL, &err_extra ); -} - -/*------------------------------------------------------------*/ -/*--- Suppressions ---*/ -/*------------------------------------------------------------*/ - -Bool TL_(recognised_suppression) ( Char* name, Supp* su ) -{ - SuppKind skind; - - if (MAC_(shared_recognised_suppression)(name, su)) - return True; - - /* Extra suppressions not used by Addrcheck */ - else if (VG_STREQ(name, "Cond")) skind = Value0Supp; - else if (VG_STREQ(name, "Value0")) skind = Value0Supp;/* backwards compat */ - else if (VG_STREQ(name, "Value1")) skind = Value1Supp; - else if (VG_STREQ(name, "Value2")) skind = Value2Supp; - else if (VG_STREQ(name, "Value4")) skind = Value4Supp; - else if (VG_STREQ(name, "Value8")) skind = Value8Supp; - else if (VG_STREQ(name, "Value16")) skind = Value16Supp; - else - return False; - - VG_(set_supp_kind)(su, skind); - return True; -} - -/*--------------------------------------------------------------------*/ -/*--- end mc_errcontext.c ---*/ -/*--------------------------------------------------------------------*/ diff --git a/memcheck/mc_include.h b/memcheck/mc_include.h index 0ea9aee816..9a9bcb89ca 100644 --- a/memcheck/mc_include.h +++ b/memcheck/mc_include.h @@ -70,12 +70,6 @@ extern VGA_REGPARM(1) UWord MC_(helperc_LOADV2) ( Addr ); extern VGA_REGPARM(1) UWord MC_(helperc_LOADV4) ( Addr ); extern VGA_REGPARM(1) ULong MC_(helperc_LOADV8) ( Addr ); -/* Functions defined in mc_errcontext.c */ -extern void MC_(record_value_error) ( ThreadId tid, Int size ); -extern void MC_(record_user_error) ( ThreadId tid, Addr a, Bool isWrite, - Bool isUnaddr ); - - #endif /*--------------------------------------------------------------------*/ diff --git a/memcheck/mc_main.c b/memcheck/mc_main.c index a301265bf2..e8ceedbd77 100644 --- a/memcheck/mc_main.c +++ b/memcheck/mc_main.c @@ -1205,6 +1205,122 @@ static void mc_pre_reg_read ( CorePart part, ThreadId tid, Char* s, } +/*------------------------------------------------------------*/ +/*--- Printing errors ---*/ +/*------------------------------------------------------------*/ + +void TL_(pp_Error) ( Error* err ) +{ + MAC_Error* err_extra = VG_(get_error_extra)(err); + + switch (VG_(get_error_kind)(err)) { + case CoreMemErr: { + Char* s = ( err_extra->isUnaddr ? "unaddressable" : "uninitialised" ); + VG_(message)(Vg_UserMsg, "%s contains %s byte(s)", + VG_(get_error_string)(err), s); + VG_(pp_ExeContext)( VG_(get_error_where)(err) ); + break; + + } + + case ValueErr: + if (err_extra->size == 0) { + VG_(message)(Vg_UserMsg, + "Conditional jump or move depends on uninitialised value(s)"); + } else { + VG_(message)(Vg_UserMsg, + "Use of uninitialised value of size %d", + err_extra->size); + } + VG_(pp_ExeContext)( VG_(get_error_where)(err) ); + break; + + case ParamErr: { + Bool isReg = ( Register == err_extra->addrinfo.akind ); + Char* s1 = ( isReg ? "contains" : "points to" ); + Char* s2 = ( err_extra->isUnaddr ? "unaddressable" : "uninitialised" ); + if (isReg) tl_assert(!err_extra->isUnaddr); + + VG_(message)(Vg_UserMsg, "Syscall param %s %s %s byte(s)", + VG_(get_error_string)(err), s1, s2); + + VG_(pp_ExeContext)( VG_(get_error_where)(err) ); + MAC_(pp_AddrInfo)(VG_(get_error_address)(err), &err_extra->addrinfo); + break; + } + case UserErr: { + Char* s = ( err_extra->isUnaddr ? "Unaddressable" : "Uninitialised" ); + + VG_(message)(Vg_UserMsg, + "%s byte(s) found during client check request", s); + + VG_(pp_ExeContext)( VG_(get_error_where)(err) ); + MAC_(pp_AddrInfo)(VG_(get_error_address)(err), &err_extra->addrinfo); + break; + } + default: + MAC_(pp_shared_Error)(err); + break; + } +} + +/*------------------------------------------------------------*/ +/*--- Recording errors ---*/ +/*------------------------------------------------------------*/ + +/* Creates a copy of the `extra' part, updates the copy with address info if + necessary, and returns the copy. */ +/* This one called from generated code and non-generated code. */ +void mc_record_value_error ( ThreadId tid, Int size ) +{ + MAC_Error err_extra; + + MAC_(clear_MAC_Error)( &err_extra ); + err_extra.size = size; + err_extra.isUnaddr = False; + VG_(maybe_record_error)( tid, ValueErr, /*addr*/0, /*s*/NULL, &err_extra ); +} + +/* This called from non-generated code */ + +void mc_record_user_error ( ThreadId tid, Addr a, Bool isWrite, + Bool isUnaddr ) +{ + MAC_Error err_extra; + + tl_assert(VG_INVALID_THREADID != tid); + MAC_(clear_MAC_Error)( &err_extra ); + err_extra.addrinfo.akind = Undescribed; + err_extra.isUnaddr = isUnaddr; + VG_(maybe_record_error)( tid, UserErr, a, /*s*/NULL, &err_extra ); +} + +/*------------------------------------------------------------*/ +/*--- Suppressions ---*/ +/*------------------------------------------------------------*/ + +Bool TL_(recognised_suppression) ( Char* name, Supp* su ) +{ + SuppKind skind; + + if (MAC_(shared_recognised_suppression)(name, su)) + return True; + + /* Extra suppressions not used by Addrcheck */ + else if (VG_STREQ(name, "Cond")) skind = Value0Supp; + else if (VG_STREQ(name, "Value0")) skind = Value0Supp;/* backwards compat */ + else if (VG_STREQ(name, "Value1")) skind = Value1Supp; + else if (VG_STREQ(name, "Value2")) skind = Value2Supp; + else if (VG_STREQ(name, "Value4")) skind = Value4Supp; + else if (VG_STREQ(name, "Value8")) skind = Value8Supp; + else if (VG_STREQ(name, "Value16")) skind = Value16Supp; + else + return False; + + VG_(set_supp_kind)(su, skind); + return True; +} + /*------------------------------------------------------------*/ /*--- Functions called directly from generated code: ---*/ /*--- Load/store handlers. ---*/ @@ -1605,27 +1721,27 @@ void MC_(helperc_STOREV1) ( Addr aA, UWord vbyte ) void MC_(helperc_value_check0_fail) ( void ) { - MC_(record_value_error) ( VG_(get_running_tid)(), 0 ); + mc_record_value_error ( VG_(get_running_tid)(), 0 ); } void MC_(helperc_value_check1_fail) ( void ) { - MC_(record_value_error) ( VG_(get_running_tid)(), 1 ); + mc_record_value_error ( VG_(get_running_tid)(), 1 ); } void MC_(helperc_value_check4_fail) ( void ) { - MC_(record_value_error) ( VG_(get_running_tid)(), 4 ); + mc_record_value_error ( VG_(get_running_tid)(), 4 ); } void MC_(helperc_value_check8_fail) ( void ) { - MC_(record_value_error) ( VG_(get_running_tid)(), 8 ); + mc_record_value_error ( VG_(get_running_tid)(), 8 ); } VGA_REGPARM(1) void MC_(helperc_complain_undef) ( HWord sz ) { - MC_(record_value_error) ( VG_(get_running_tid)(), (Int)sz ); + mc_record_value_error ( VG_(get_running_tid)(), (Int)sz ); } @@ -1687,7 +1803,7 @@ VGA_REGPARM(1) void MC_(helperc_complain_undef) ( HWord sz ) //zz /* setting */ //zz for (i = 0; i < szW; i++) { //zz if (get_vbytes4_ALIGNED( (Addr)&vbits[i] ) != VGM_WORD_VALID) -//zz MC_(record_value_error)(tid, 4); +//zz mc_record_value_error(tid, 4); //zz set_vbytes4_ALIGNED( (Addr)&data[i], vbits[i] ); //zz } //zz } else { @@ -2108,8 +2224,8 @@ Bool TL_(handle_client_request) ( ThreadId tid, UWord* arg, UWord* ret ) case VG_USERREQ__CHECK_WRITABLE: /* check writable */ ok = mc_check_writable ( arg[1], arg[2], &bad_addr ); if (!ok) - MC_(record_user_error) ( tid, bad_addr, /*isWrite*/True, - /*isUnaddr*/True ); + mc_record_user_error ( tid, bad_addr, /*isWrite*/True, + /*isUnaddr*/True ); *ret = ok ? (UWord)NULL : bad_addr; break; @@ -2117,11 +2233,11 @@ Bool TL_(handle_client_request) ( ThreadId tid, UWord* arg, UWord* ret ) MC_ReadResult res; res = mc_check_readable ( arg[1], arg[2], &bad_addr ); if (MC_AddrErr == res) - MC_(record_user_error) ( tid, bad_addr, /*isWrite*/False, - /*isUnaddr*/True ); + mc_record_user_error ( tid, bad_addr, /*isWrite*/False, + /*isUnaddr*/True ); else if (MC_ValueErr == res) - MC_(record_user_error) ( tid, bad_addr, /*isWrite*/False, - /*isUnaddr*/False ); + mc_record_user_error ( tid, bad_addr, /*isWrite*/False, + /*isUnaddr*/False ); *ret = ( res==MC_Ok ? (UWord)NULL : bad_addr ); break; }