njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1 | |
| 2 | /*--------------------------------------------------------------------*/ |
njn | c953984 | 2002-10-02 13:26:35 +0000 | [diff] [blame] | 3 | /*--- Management of memory error messages. ---*/ |
njn25 | cac76cb | 2002-09-23 11:21:57 +0000 | [diff] [blame] | 4 | /*--- mc_errcontext.c ---*/ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 5 | /*--------------------------------------------------------------------*/ |
| 6 | |
| 7 | /* |
nethercote | 137bc55 | 2003-11-14 17:47:54 +0000 | [diff] [blame] | 8 | This file is part of MemCheck, a heavyweight Valgrind tool for |
njn | c953984 | 2002-10-02 13:26:35 +0000 | [diff] [blame] | 9 | detecting memory errors. |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 10 | |
nethercote | bb1c991 | 2004-01-04 16:43:23 +0000 | [diff] [blame] | 11 | Copyright (C) 2000-2004 Julian Seward |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 12 | jseward@acm.org |
| 13 | |
| 14 | This program is free software; you can redistribute it and/or |
| 15 | modify it under the terms of the GNU General Public License as |
| 16 | published by the Free Software Foundation; either version 2 of the |
| 17 | License, or (at your option) any later version. |
| 18 | |
| 19 | This program is distributed in the hope that it will be useful, but |
| 20 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 22 | General Public License for more details. |
| 23 | |
| 24 | You should have received a copy of the GNU General Public License |
| 25 | along with this program; if not, write to the Free Software |
| 26 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 27 | 02111-1307, USA. |
| 28 | |
| 29 | The GNU General Public License is contained in the file COPYING. |
| 30 | */ |
| 31 | |
njn25 | cac76cb | 2002-09-23 11:21:57 +0000 | [diff] [blame] | 32 | #include "mc_include.h" |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 33 | |
| 34 | /*------------------------------------------------------------*/ |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 35 | /*--- Printing errors ---*/ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 36 | /*------------------------------------------------------------*/ |
| 37 | |
njn | 26f0251 | 2004-11-22 18:33:15 +0000 | [diff] [blame] | 38 | void TL_(pp_Error) ( Error* err ) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 39 | { |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 40 | MAC_Error* err_extra = VG_(get_error_extra)(err); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 41 | |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 42 | switch (VG_(get_error_kind)(err)) { |
nethercote | 8b76fe5 | 2004-11-08 19:20:09 +0000 | [diff] [blame] | 43 | case CoreMemErr: { |
| 44 | Char* s = ( err_extra->isUnaddr ? "unaddressable" : "uninitialised" ); |
| 45 | VG_(message)(Vg_UserMsg, "%s contains %s byte(s)", |
| 46 | VG_(get_error_string)(err), s); |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 47 | VG_(pp_ExeContext)( VG_(get_error_where)(err) ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 48 | break; |
| 49 | |
nethercote | 8b76fe5 | 2004-11-08 19:20:09 +0000 | [diff] [blame] | 50 | } |
| 51 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 52 | case ValueErr: |
| 53 | if (err_extra->size == 0) { |
nethercote | 8b76fe5 | 2004-11-08 19:20:09 +0000 | [diff] [blame] | 54 | VG_(message)(Vg_UserMsg, |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 55 | "Conditional jump or move depends on uninitialised value(s)"); |
| 56 | } else { |
| 57 | VG_(message)(Vg_UserMsg, |
| 58 | "Use of uninitialised value of size %d", |
| 59 | err_extra->size); |
| 60 | } |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 61 | VG_(pp_ExeContext)( VG_(get_error_where)(err) ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 62 | break; |
| 63 | |
nethercote | 8b76fe5 | 2004-11-08 19:20:09 +0000 | [diff] [blame] | 64 | case ParamErr: { |
| 65 | Bool isReg = ( Register == err_extra->addrinfo.akind ); |
| 66 | Char* s1 = ( isReg ? "contains" : "points to" ); |
| 67 | Char* s2 = ( err_extra->isUnaddr ? "unaddressable" : "uninitialised" ); |
njn | ca82cc0 | 2004-11-22 17:18:48 +0000 | [diff] [blame] | 68 | if (isReg) tl_assert(!err_extra->isUnaddr); |
nethercote | 8b76fe5 | 2004-11-08 19:20:09 +0000 | [diff] [blame] | 69 | |
| 70 | VG_(message)(Vg_UserMsg, "Syscall param %s %s %s byte(s)", |
| 71 | VG_(get_error_string)(err), s1, s2); |
| 72 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 73 | VG_(pp_ExeContext)( VG_(get_error_where)(err) ); |
| 74 | MAC_(pp_AddrInfo)(VG_(get_error_address)(err), &err_extra->addrinfo); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 75 | break; |
nethercote | 8b76fe5 | 2004-11-08 19:20:09 +0000 | [diff] [blame] | 76 | } |
| 77 | case UserErr: { |
| 78 | Char* s = ( err_extra->isUnaddr ? "Unaddressable" : "Uninitialised" ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 79 | |
nethercote | 8b76fe5 | 2004-11-08 19:20:09 +0000 | [diff] [blame] | 80 | VG_(message)(Vg_UserMsg, |
| 81 | "%s byte(s) found during client check request", s); |
| 82 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 83 | VG_(pp_ExeContext)( VG_(get_error_where)(err) ); |
| 84 | MAC_(pp_AddrInfo)(VG_(get_error_address)(err), &err_extra->addrinfo); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 85 | break; |
nethercote | 8b76fe5 | 2004-11-08 19:20:09 +0000 | [diff] [blame] | 86 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 87 | default: |
njn | b126f73 | 2004-11-22 17:57:07 +0000 | [diff] [blame] | 88 | MAC_(pp_shared_Error)(err); |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 89 | break; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 90 | } |
| 91 | } |
| 92 | |
| 93 | /*------------------------------------------------------------*/ |
| 94 | /*--- Recording errors ---*/ |
| 95 | /*------------------------------------------------------------*/ |
| 96 | |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 97 | /* Creates a copy of the `extra' part, updates the copy with address info if |
| 98 | necessary, and returns the copy. */ |
sewardj | af48a60 | 2003-07-06 00:54:47 +0000 | [diff] [blame] | 99 | /* This one called from generated code and non-generated code. */ |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 100 | void MC_(record_value_error) ( ThreadId tid, Int size ) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 101 | { |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 102 | MAC_Error err_extra; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 103 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 104 | MAC_(clear_MAC_Error)( &err_extra ); |
nethercote | 8b76fe5 | 2004-11-08 19:20:09 +0000 | [diff] [blame] | 105 | err_extra.size = size; |
| 106 | err_extra.isUnaddr = False; |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 107 | VG_(maybe_record_error)( tid, ValueErr, /*addr*/0, /*s*/NULL, &err_extra ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 108 | } |
| 109 | |
njn | 66fe05a | 2003-07-22 09:12:33 +0000 | [diff] [blame] | 110 | /* This called from non-generated code */ |
njn | 34419c1 | 2003-05-02 17:24:29 +0000 | [diff] [blame] | 111 | |
nethercote | 8b76fe5 | 2004-11-08 19:20:09 +0000 | [diff] [blame] | 112 | void MC_(record_user_error) ( ThreadId tid, Addr a, Bool isWrite, |
| 113 | Bool isUnaddr ) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 114 | { |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 115 | MAC_Error err_extra; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 116 | |
njn | ca82cc0 | 2004-11-22 17:18:48 +0000 | [diff] [blame] | 117 | tl_assert(VG_INVALID_THREADID != tid); |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 118 | MAC_(clear_MAC_Error)( &err_extra ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 119 | err_extra.addrinfo.akind = Undescribed; |
nethercote | 8b76fe5 | 2004-11-08 19:20:09 +0000 | [diff] [blame] | 120 | err_extra.isUnaddr = isUnaddr; |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 121 | VG_(maybe_record_error)( tid, UserErr, a, /*s*/NULL, &err_extra ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 122 | } |
| 123 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 124 | /*------------------------------------------------------------*/ |
| 125 | /*--- Suppressions ---*/ |
| 126 | /*------------------------------------------------------------*/ |
| 127 | |
njn | 26f0251 | 2004-11-22 18:33:15 +0000 | [diff] [blame] | 128 | Bool TL_(recognised_suppression) ( Char* name, Supp* su ) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 129 | { |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 130 | SuppKind skind; |
sewardj | 99aac97 | 2002-12-26 01:53:45 +0000 | [diff] [blame] | 131 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 132 | if (MAC_(shared_recognised_suppression)(name, su)) |
| 133 | return True; |
| 134 | |
| 135 | /* Extra suppressions not used by Addrcheck */ |
njn | 34419c1 | 2003-05-02 17:24:29 +0000 | [diff] [blame] | 136 | else if (VG_STREQ(name, "Cond")) skind = Value0Supp; |
| 137 | else if (VG_STREQ(name, "Value0")) skind = Value0Supp;/* backwards compat */ |
| 138 | else if (VG_STREQ(name, "Value1")) skind = Value1Supp; |
| 139 | else if (VG_STREQ(name, "Value2")) skind = Value2Supp; |
| 140 | else if (VG_STREQ(name, "Value4")) skind = Value4Supp; |
| 141 | else if (VG_STREQ(name, "Value8")) skind = Value8Supp; |
njn | c061666 | 2003-06-12 09:58:41 +0000 | [diff] [blame] | 142 | else if (VG_STREQ(name, "Value16")) skind = Value16Supp; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 143 | else |
| 144 | return False; |
| 145 | |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 146 | VG_(set_supp_kind)(su, skind); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 147 | return True; |
| 148 | } |
| 149 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 150 | /*--------------------------------------------------------------------*/ |
njn25 | cac76cb | 2002-09-23 11:21:57 +0000 | [diff] [blame] | 151 | /*--- end mc_errcontext.c ---*/ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 152 | /*--------------------------------------------------------------------*/ |