1
1
#![ allow( clippy:: useless_conversion) ]
2
2
3
- use super :: mystd:: ffi:: { OsStr , OsString } ;
3
+ use super :: mystd:: ffi:: OsStr ;
4
4
use super :: mystd:: fs;
5
- use super :: mystd:: os:: unix:: ffi:: { OsStrExt , OsStringExt } ;
5
+ use super :: mystd:: os:: unix:: ffi:: OsStrExt ;
6
6
use super :: mystd:: path:: { Path , PathBuf } ;
7
7
use super :: Either ;
8
- use super :: { gimli, Context , Endian , EndianSlice , Mapping , Stash , Vec } ;
8
+ use super :: { gimli, Context , Endian , EndianSlice , Mapping , Stash } ;
9
+ use alloc:: string:: String ;
9
10
use alloc:: sync:: Arc ;
11
+ use alloc:: vec:: Vec ;
10
12
use core:: convert:: { TryFrom , TryInto } ;
11
13
use core:: str;
12
14
#[ cfg( feature = "ruzstd" ) ]
@@ -393,7 +395,7 @@ fn decompress_zstd(mut input: &[u8], mut output: &mut [u8]) -> Option<()> {
393
395
Some ( ( ) )
394
396
}
395
397
396
- const DEBUG_PATH : & [ u8 ] = b "/usr/lib/debug";
398
+ const DEBUG_PATH : & str = "/usr/lib/debug" ;
397
399
398
400
fn debug_path_exists ( ) -> bool {
399
401
cfg_if:: cfg_if! {
@@ -403,7 +405,7 @@ fn debug_path_exists() -> bool {
403
405
404
406
let mut exists = DEBUG_PATH_EXISTS . load( Ordering :: Relaxed ) ;
405
407
if exists == 0 {
406
- exists = if Path :: new( OsStr :: from_bytes ( DEBUG_PATH ) ) . is_dir( ) {
408
+ exists = if Path :: new( DEBUG_PATH ) . is_dir( ) {
407
409
1
408
410
} else {
409
411
2
@@ -422,8 +424,8 @@ fn debug_path_exists() -> bool {
422
424
/// The format of build id paths is documented at:
423
425
/// https://sourceware.org/gdb/onlinedocs/gdb/Separate-Debug-Files.html
424
426
fn locate_build_id ( build_id : & [ u8 ] ) -> Option < PathBuf > {
425
- const BUILD_ID_PATH : & [ u8 ] = b "/usr/lib/debug/.build-id/";
426
- const BUILD_ID_SUFFIX : & [ u8 ] = b ".debug";
427
+ const BUILD_ID_PATH : & str = "/usr/lib/debug/.build-id/" ;
428
+ const BUILD_ID_SUFFIX : & str = ".debug" ;
427
429
428
430
if build_id. len ( ) < 2 {
429
431
return None ;
@@ -434,25 +436,17 @@ fn locate_build_id(build_id: &[u8]) -> Option<PathBuf> {
434
436
}
435
437
436
438
let mut path =
437
- Vec :: with_capacity ( BUILD_ID_PATH . len ( ) + BUILD_ID_SUFFIX . len ( ) + build_id. len ( ) * 2 + 1 ) ;
438
- path. extend ( BUILD_ID_PATH ) ;
439
- path. push ( hex ( build_id[ 0 ] >> 4 ) ) ;
440
- path. push ( hex ( build_id[ 0 ] & 0xf ) ) ;
441
- path. push ( b '/') ;
439
+ String :: with_capacity ( BUILD_ID_PATH . len ( ) + BUILD_ID_SUFFIX . len ( ) + build_id. len ( ) * 2 + 1 ) ;
440
+ path. push_str ( BUILD_ID_PATH ) ;
441
+ path. push ( char :: from_digit ( ( build_id[ 0 ] >> 4 ) as u32 , 16 ) ? ) ;
442
+ path. push ( char :: from_digit ( ( build_id[ 0 ] & 0xf ) as u32 , 16 ) ? ) ;
443
+ path. push ( '/' ) ;
442
444
for byte in & build_id[ 1 ..] {
443
- path. push ( hex ( byte >> 4 ) ) ;
444
- path. push ( hex ( byte & 0xf ) ) ;
445
- }
446
- path. extend ( BUILD_ID_SUFFIX ) ;
447
- Some ( PathBuf :: from ( OsString :: from_vec ( path) ) )
448
- }
449
-
450
- fn hex ( byte : u8 ) -> u8 {
451
- if byte < 10 {
452
- b'0' + byte
453
- } else {
454
- b'a' + byte - 10
445
+ path. push ( char:: from_digit ( ( byte >> 4 ) as u32 , 16 ) ?) ;
446
+ path. push ( char:: from_digit ( ( byte & 0xf ) as u32 , 16 ) ?) ;
455
447
}
448
+ path. push_str ( BUILD_ID_SUFFIX ) ;
449
+ Some ( PathBuf :: from ( path) )
456
450
}
457
451
458
452
/// Locate a file specified in a `.gnu_debuglink` section.
@@ -469,9 +463,8 @@ fn hex(byte: u8) -> u8 {
469
463
fn locate_debuglink ( path : & Path , filename : & [ u8 ] ) -> Option < PathBuf > {
470
464
let path = fs:: canonicalize ( path) . ok ( ) ?;
471
465
let parent = path. parent ( ) ?;
472
- let mut f = PathBuf :: from ( OsString :: with_capacity (
473
- DEBUG_PATH . len ( ) + parent. as_os_str ( ) . len ( ) + filename. len ( ) + 2 ,
474
- ) ) ;
466
+ let mut f =
467
+ PathBuf :: with_capacity ( DEBUG_PATH . len ( ) + parent. as_os_str ( ) . len ( ) + filename. len ( ) + 2 ) ;
475
468
let filename = Path :: new ( OsStr :: from_bytes ( filename) ) ;
476
469
477
470
// Try "/parent/filename" if it differs from "path"
@@ -482,9 +475,7 @@ fn locate_debuglink(path: &Path, filename: &[u8]) -> Option<PathBuf> {
482
475
}
483
476
484
477
// Try "/parent/.debug/filename"
485
- let mut s = OsString :: from ( f) ;
486
- s. clear ( ) ;
487
- f = PathBuf :: from ( s) ;
478
+ f. clear ( ) ;
488
479
f. push ( parent) ;
489
480
f. push ( ".debug" ) ;
490
481
f. push ( filename) ;
@@ -494,10 +485,8 @@ fn locate_debuglink(path: &Path, filename: &[u8]) -> Option<PathBuf> {
494
485
495
486
if debug_path_exists ( ) {
496
487
// Try "/usr/lib/debug/parent/filename"
497
- let mut s = OsString :: from ( f) ;
498
- s. clear ( ) ;
499
- f = PathBuf :: from ( s) ;
500
- f. push ( OsStr :: from_bytes ( DEBUG_PATH ) ) ;
488
+ f. clear ( ) ;
489
+ f. push ( DEBUG_PATH ) ;
501
490
f. push ( parent. strip_prefix ( "/" ) . unwrap ( ) ) ;
502
491
f. push ( filename) ;
503
492
if f. is_file ( ) {
0 commit comments