| OLD | NEW |
| 1 // Copyright 2014 The Crashpad Authors. All rights reserved. | 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
| 2 // | 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
| 6 // | 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // | 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 return std::string(flavor_data, flavor_len); | 185 return std::string(flavor_data, flavor_len); |
| 186 } | 186 } |
| 187 | 187 |
| 188 } // namespace | 188 } // namespace |
| 189 | 189 |
| 190 namespace crashpad { | 190 namespace crashpad { |
| 191 | 191 |
| 192 std::string ExceptionToString(exception_type_t exception, | 192 std::string ExceptionToString(exception_type_t exception, |
| 193 SymbolicConstantToStringOptions options) { | 193 SymbolicConstantToStringOptions options) { |
| 194 const char* exception_name = | 194 const char* exception_name = |
| 195 static_cast<size_t>(exception) < arraysize(kExceptionNames) | 195 implicit_cast<size_t>(exception) < arraysize(kExceptionNames) |
| 196 ? kExceptionNames[exception] | 196 ? kExceptionNames[exception] |
| 197 : nullptr; | 197 : nullptr; |
| 198 if (!exception_name) { | 198 if (!exception_name) { |
| 199 if (options & kUnknownIsNumeric) { | 199 if (options & kUnknownIsNumeric) { |
| 200 return base::StringPrintf("%d", exception); | 200 return base::StringPrintf("%d", exception); |
| 201 } | 201 } |
| 202 return std::string(); | 202 return std::string(); |
| 203 } | 203 } |
| 204 | 204 |
| 205 if (options & kUseShortName) { | 205 if (options & kUseShortName) { |
| 206 return std::string(exception_name); | 206 return std::string(exception_name); |
| 207 } | 207 } |
| 208 return base::StringPrintf("%s%s", kExcPrefix, exception_name); | 208 return base::StringPrintf("%s%s", kExcPrefix, exception_name); |
| 209 } | 209 } |
| 210 | 210 |
| 211 bool StringToException(const base::StringPiece& string, | 211 bool StringToException(const base::StringPiece& string, |
| 212 StringToSymbolicConstantOptions options, | 212 StringToSymbolicConstantOptions options, |
| 213 exception_type_t* exception) { | 213 exception_type_t* exception) { |
| 214 if ((options & kAllowFullName) || (options & kAllowShortName)) { | 214 if ((options & kAllowFullName) || (options & kAllowShortName)) { |
| 215 bool can_match_full = | 215 bool can_match_full = |
| 216 (options & kAllowFullName) && | 216 (options & kAllowFullName) && |
| 217 string.substr(0, strlen(kExcPrefix)).compare(kExcPrefix) == 0; | 217 string.substr(0, strlen(kExcPrefix)).compare(kExcPrefix) == 0; |
| 218 base::StringPiece short_string = | 218 base::StringPiece short_string = |
| 219 can_match_full ? string.substr(strlen(kExcPrefix)) : string; | 219 can_match_full ? string.substr(strlen(kExcPrefix)) : string; |
| 220 for (exception_type_t index = 0; | 220 for (exception_type_t index = 0; |
| 221 index < static_cast<exception_type_t>(arraysize(kExceptionNames)); | 221 index < implicit_cast<exception_type_t>(arraysize(kExceptionNames)); |
| 222 ++index) { | 222 ++index) { |
| 223 const char* exception_name = kExceptionNames[index]; | 223 const char* exception_name = kExceptionNames[index]; |
| 224 if (!exception_name) { | 224 if (!exception_name) { |
| 225 continue; | 225 continue; |
| 226 } | 226 } |
| 227 if (can_match_full && short_string.compare(exception_name) == 0) { | 227 if (can_match_full && short_string.compare(exception_name) == 0) { |
| 228 *exception = index; | 228 *exception = index; |
| 229 return true; | 229 return true; |
| 230 } | 230 } |
| 231 if ((options & kAllowShortName) && string.compare(exception_name) == 0) { | 231 if ((options & kAllowShortName) && string.compare(exception_name) == 0) { |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 return true; | 315 return true; |
| 316 } | 316 } |
| 317 | 317 |
| 318 if ((options & kAllowFullName) || (options & kAllowShortName)) { | 318 if ((options & kAllowFullName) || (options & kAllowShortName)) { |
| 319 bool can_match_full = | 319 bool can_match_full = |
| 320 (options & kAllowFullName) && | 320 (options & kAllowFullName) && |
| 321 string.substr(0, strlen(kExcMaskPrefix)).compare(kExcMaskPrefix) == 0; | 321 string.substr(0, strlen(kExcMaskPrefix)).compare(kExcMaskPrefix) == 0; |
| 322 base::StringPiece short_string = | 322 base::StringPiece short_string = |
| 323 can_match_full ? string.substr(strlen(kExcMaskPrefix)) : string; | 323 can_match_full ? string.substr(strlen(kExcMaskPrefix)) : string; |
| 324 for (exception_type_t index = 0; | 324 for (exception_type_t index = 0; |
| 325 index < static_cast<exception_type_t>(arraysize(kExceptionNames)); | 325 index < implicit_cast<exception_type_t>(arraysize(kExceptionNames)); |
| 326 ++index) { | 326 ++index) { |
| 327 const char* exception_name = kExceptionNames[index]; | 327 const char* exception_name = kExceptionNames[index]; |
| 328 if (!exception_name) { | 328 if (!exception_name) { |
| 329 continue; | 329 continue; |
| 330 } | 330 } |
| 331 if (can_match_full && short_string.compare(exception_name) == 0) { | 331 if (can_match_full && short_string.compare(exception_name) == 0) { |
| 332 *exception_mask = 1 << index; | 332 *exception_mask = 1 << index; |
| 333 return true; | 333 return true; |
| 334 } | 334 } |
| 335 if ((options & kAllowShortName) && string.compare(exception_name) == 0) { | 335 if ((options & kAllowShortName) && string.compare(exception_name) == 0) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 354 } | 354 } |
| 355 | 355 |
| 356 return false; | 356 return false; |
| 357 } | 357 } |
| 358 | 358 |
| 359 std::string ExceptionBehaviorToString(exception_behavior_t behavior, | 359 std::string ExceptionBehaviorToString(exception_behavior_t behavior, |
| 360 SymbolicConstantToStringOptions options) { | 360 SymbolicConstantToStringOptions options) { |
| 361 const exception_behavior_t basic_behavior = ExceptionBehaviorBasic(behavior); | 361 const exception_behavior_t basic_behavior = ExceptionBehaviorBasic(behavior); |
| 362 | 362 |
| 363 const char* behavior_name = | 363 const char* behavior_name = |
| 364 static_cast<size_t>(basic_behavior) < arraysize(kBehaviorNames) | 364 implicit_cast<size_t>(basic_behavior) < arraysize(kBehaviorNames) |
| 365 ? kBehaviorNames[basic_behavior] | 365 ? kBehaviorNames[basic_behavior] |
| 366 : nullptr; | 366 : nullptr; |
| 367 if (!behavior_name) { | 367 if (!behavior_name) { |
| 368 if (options & kUnknownIsNumeric) { | 368 if (options & kUnknownIsNumeric) { |
| 369 return base::StringPrintf("%#x", behavior); | 369 return base::StringPrintf("%#x", behavior); |
| 370 } | 370 } |
| 371 return std::string(); | 371 return std::string(); |
| 372 } | 372 } |
| 373 | 373 |
| 374 std::string behavior_string; | 374 std::string behavior_string; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 } | 421 } |
| 422 } | 422 } |
| 423 | 423 |
| 424 if ((options & kAllowFullName) || (options & kAllowShortName)) { | 424 if ((options & kAllowFullName) || (options & kAllowShortName)) { |
| 425 bool can_match_full = | 425 bool can_match_full = |
| 426 (options & kAllowFullName) && | 426 (options & kAllowFullName) && |
| 427 sp.substr(0, strlen(kBehaviorPrefix)).compare(kBehaviorPrefix) == 0; | 427 sp.substr(0, strlen(kBehaviorPrefix)).compare(kBehaviorPrefix) == 0; |
| 428 base::StringPiece short_string = | 428 base::StringPiece short_string = |
| 429 can_match_full ? sp.substr(strlen(kBehaviorPrefix)) : sp; | 429 can_match_full ? sp.substr(strlen(kBehaviorPrefix)) : sp; |
| 430 for (exception_behavior_t index = 0; | 430 for (exception_behavior_t index = 0; |
| 431 index < static_cast<exception_behavior_t>(arraysize(kBehaviorNames)); | 431 index < implicit_cast<exception_behavior_t>(arraysize(kBehaviorNames)); |
| 432 ++index) { | 432 ++index) { |
| 433 const char* behavior_name = kBehaviorNames[index]; | 433 const char* behavior_name = kBehaviorNames[index]; |
| 434 if (!behavior_name) { | 434 if (!behavior_name) { |
| 435 continue; | 435 continue; |
| 436 } | 436 } |
| 437 if (can_match_full && short_string.compare(behavior_name) == 0) { | 437 if (can_match_full && short_string.compare(behavior_name) == 0) { |
| 438 build_behavior |= index; | 438 build_behavior |= index; |
| 439 *behavior = build_behavior; | 439 *behavior = build_behavior; |
| 440 return true; | 440 return true; |
| 441 } | 441 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 456 *behavior = build_behavior; | 456 *behavior = build_behavior; |
| 457 return true; | 457 return true; |
| 458 } | 458 } |
| 459 | 459 |
| 460 return false; | 460 return false; |
| 461 } | 461 } |
| 462 | 462 |
| 463 std::string ThreadStateFlavorToString(thread_state_flavor_t flavor, | 463 std::string ThreadStateFlavorToString(thread_state_flavor_t flavor, |
| 464 SymbolicConstantToStringOptions options) { | 464 SymbolicConstantToStringOptions options) { |
| 465 const char* flavor_name = | 465 const char* flavor_name = |
| 466 static_cast<size_t>(flavor) < arraysize(kFlavorNames) | 466 implicit_cast<size_t>(flavor) < arraysize(kFlavorNames) |
| 467 ? kFlavorNames[flavor] | 467 ? kFlavorNames[flavor] |
| 468 : nullptr; | 468 : nullptr; |
| 469 | 469 |
| 470 if (!flavor_name) { | 470 if (!flavor_name) { |
| 471 for (size_t generic_flavor_index = 0; | 471 for (size_t generic_flavor_index = 0; |
| 472 generic_flavor_index < arraysize(kGenericFlavorNames); | 472 generic_flavor_index < arraysize(kGenericFlavorNames); |
| 473 ++generic_flavor_index) { | 473 ++generic_flavor_index) { |
| 474 if (flavor == kGenericFlavorNames[generic_flavor_index].flavor) { | 474 if (flavor == kGenericFlavorNames[generic_flavor_index].flavor) { |
| 475 flavor_name = kGenericFlavorNames[generic_flavor_index].name; | 475 flavor_name = kGenericFlavorNames[generic_flavor_index].name; |
| 476 break; | 476 break; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 489 return ThreadStateFlavorFullToShort(flavor_name); | 489 return ThreadStateFlavorFullToShort(flavor_name); |
| 490 } | 490 } |
| 491 return std::string(flavor_name); | 491 return std::string(flavor_name); |
| 492 } | 492 } |
| 493 | 493 |
| 494 bool StringToThreadStateFlavor(const base::StringPiece& string, | 494 bool StringToThreadStateFlavor(const base::StringPiece& string, |
| 495 StringToSymbolicConstantOptions options, | 495 StringToSymbolicConstantOptions options, |
| 496 thread_state_flavor_t* flavor) { | 496 thread_state_flavor_t* flavor) { |
| 497 if ((options & kAllowFullName) || (options & kAllowShortName)) { | 497 if ((options & kAllowFullName) || (options & kAllowShortName)) { |
| 498 for (thread_state_flavor_t index = 0; | 498 for (thread_state_flavor_t index = 0; |
| 499 index < static_cast<thread_state_flavor_t>(arraysize(kFlavorNames)); | 499 index < implicit_cast<thread_state_flavor_t>(arraysize(kFlavorNames)); |
| 500 ++index) { | 500 ++index) { |
| 501 const char* flavor_name = kFlavorNames[index]; | 501 const char* flavor_name = kFlavorNames[index]; |
| 502 if (!flavor_name) { | 502 if (!flavor_name) { |
| 503 continue; | 503 continue; |
| 504 } | 504 } |
| 505 if ((options & kAllowFullName) && string.compare(flavor_name) == 0) { | 505 if ((options & kAllowFullName) && string.compare(flavor_name) == 0) { |
| 506 *flavor = index; | 506 *flavor = index; |
| 507 return true; | 507 return true; |
| 508 } | 508 } |
| 509 if (options & kAllowShortName) { | 509 if (options & kAllowShortName) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 536 } | 536 } |
| 537 | 537 |
| 538 if (options & kAllowNumber) { | 538 if (options & kAllowNumber) { |
| 539 return StringToNumber(string, reinterpret_cast<unsigned int*>(flavor)); | 539 return StringToNumber(string, reinterpret_cast<unsigned int*>(flavor)); |
| 540 } | 540 } |
| 541 | 541 |
| 542 return false; | 542 return false; |
| 543 } | 543 } |
| 544 | 544 |
| 545 } // namespace crashpad | 545 } // namespace crashpad |
| OLD | NEW |