1
1
/*
2
- * Copyright (c) 2011, 2015 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2011, 2022 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
26
26
27
27
#if !defined(_WINDOWS) && !defined(__APPLE__)
28
28
#include " decoder_elf.hpp"
29
- #include " memory/allocation.inline.hpp"
29
+ #include " logging/log.hpp"
30
+ #include " runtime/os.hpp"
30
31
31
32
ElfDecoder::~ElfDecoder () {
32
33
if (_opened_elf_files != NULL ) {
@@ -53,6 +54,45 @@ bool ElfDecoder::decode(address addr, char *buf, int buflen, int* offset, const
53
54
return true ;
54
55
}
55
56
57
+ bool ElfDecoder::get_source_info (address pc, char * filename, size_t filename_len, int * line, bool is_pc_after_call) {
58
+ assert (filename != nullptr && filename_len > 0 && line != nullptr , " Argument error" );
59
+ filename[0 ] = ' \0 ' ;
60
+ *line = -1 ;
61
+
62
+ char filepath[JVM_MAXPATHLEN];
63
+ filepath[JVM_MAXPATHLEN - 1 ] = ' \0 ' ;
64
+ int offset_in_library = -1 ;
65
+ if (!os::dll_address_to_library_name (pc, filepath, sizeof (filepath), &offset_in_library)) {
66
+ // Method not found. offset_in_library should not overflow.
67
+ DWARF_LOG_ERROR (" Did not find library for address " INTPTR_FORMAT, p2i (pc))
68
+ return false ;
69
+ }
70
+
71
+ if (filepath[JVM_MAXPATHLEN - 1 ] != ' \0 ' ) {
72
+ DWARF_LOG_ERROR (" File path is too large to fit into buffer of size %d" , JVM_MAXPATHLEN);
73
+ return false ;
74
+ }
75
+
76
+ const uint32_t unsigned_offset_in_library = (uint32_t )offset_in_library;
77
+
78
+ ElfFile* file = get_elf_file (filepath);
79
+ if (file == NULL ) {
80
+ return false ;
81
+ }
82
+ DWARF_LOG_INFO (" ##### Find filename and line number for offset " PTR32_FORMAT " in library %s #####" ,
83
+ unsigned_offset_in_library, filepath);
84
+
85
+ if (!file->get_source_info (unsigned_offset_in_library, filename, filename_len, line, is_pc_after_call)) {
86
+ return false ;
87
+ }
88
+
89
+ DWARF_LOG_SUMMARY (" pc: " INTPTR_FORMAT " , offset: " PTR32_FORMAT " , filename: %s, line: %u" ,
90
+ p2i (pc), offset_in_library, filename, *line);
91
+ DWARF_LOG_INFO (" " ) // To structure the debug output better.
92
+ return true ;
93
+ }
94
+
95
+
56
96
ElfFile* ElfDecoder::get_elf_file (const char * filepath) {
57
97
ElfFile* file;
58
98
0 commit comments