Skip to content

Commit e40d2f8

Browse files
Bugfixes and cleanup
1 parent 0fc2463 commit e40d2f8

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

substratevm/debug/gdbpy/gdb-debughelpers.py

+18-2
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ def __init__(self):
234234
self.heap_base_regnum = try_or_else(lambda: int(gdb.parse_and_eval('(int)__svm_heap_base_regnum')), 0, gdb.error)
235235
self.frame_size_status_mask = try_or_else(lambda: int(gdb.parse_and_eval('(int)__svm_frame_size_status_mask')), 0, gdb.error)
236236
self.object_type = gdb.lookup_type("java.lang.Object")
237+
self.object_header_type = gdb.lookup_type("_objhdr")
237238
self.stack_type = gdb.lookup_type("long")
238239
self.hub_type = gdb.lookup_type("java.lang.Class")
239240
self.classloader_type = gdb.lookup_type("java.lang.ClassLoader")
@@ -372,6 +373,12 @@ def get_java_string(self, obj: gdb.Value, gdb_output_string: bool = False) -> st
372373
trace(f'<SVMUtil> - get_java_string({hex(self.get_adr(obj))}) = {result}')
373374
return result
374375

376+
def get_hub_field(self, obj: gdb.Value) -> gdb.Value:
377+
try:
378+
return obj.cast(self.object_header_type)[self.hub_field_name]
379+
except gdb.error:
380+
return self.null
381+
375382
def get_obj_field(self, obj: gdb.Value, field_name: str, default: gdb.Value = None) -> gdb.Value:
376383
try:
377384
return obj[field_name]
@@ -387,7 +394,7 @@ def get_int_field(self, obj: gdb.Value, field_name: str, default: int = 0) -> in
387394

388395
def get_classloader_namespace(self, obj: gdb.Value) -> str:
389396
try:
390-
hub = self.get_obj_field(obj, SVMUtil.hub_field_name)
397+
hub = self.get_hub_field(obj)
391398
if self.is_null(hub):
392399
return ""
393400

@@ -422,7 +429,7 @@ def get_rtt(self, obj: gdb.Value) -> gdb.Type:
422429
if self.get_uncompressed_type(SVMUtil.get_basic_type(obj.type)).code == gdb.TYPE_CODE_UNION:
423430
obj = self.cast_to(obj, self.object_type)
424431

425-
hub = self.get_obj_field(obj, SVMUtil.hub_field_name)
432+
hub = self.get_hub_field(obj)
426433
if self.is_null(hub):
427434
return static_type
428435

@@ -506,15 +513,18 @@ def get_base_class(self, t: gdb.Type) -> gdb.Type:
506513

507514
def find_shared_types(self, type_list: list, t: gdb.Type) -> list: # list[gdb.Type]
508515
if len(type_list) == 0:
516+
# fill type list -> java.lang.Object will be last element
509517
while t != self.object_type:
510518
type_list += [t]
511519
t = self.get_base_class(t)
512520
return type_list
513521
else:
522+
# find first type in hierarchy of t that is contained in the type list
514523
while t != self.object_type:
515524
if t in type_list:
516525
return type_list[type_list.index(t):]
517526
t = self.get_base_class(t)
527+
# if nothing matches return the java.lang.Object
518528
return [self.object_type]
519529

520530
def is_java_type(self, t: gdb.Type) -> bool:
@@ -847,6 +857,8 @@ def infer_generic_types(self) -> str:
847857
for i, elem in enumerate(self, 1):
848858
if not self.__svm_util.is_null(elem): # check for null values
849859
elem_type = self.__svm_util.find_shared_types(elem_type, self.__svm_util.get_rtt(elem))
860+
# java.lang.Object will always be the last element in a type list
861+
# if it is the only element in the list we cannot infer more than java.lang.Object
850862
if (len(elem_type) > 0 and elem_type[0] == self.__svm_util.object_type) or (0 <= svm_infer_generics.value <= i):
851863
break
852864

@@ -924,6 +936,8 @@ def infer_generic_types(self) -> tuple: # (str, str):
924936
key_type = self.__svm_util.find_shared_types(key_type, self.__svm_util.get_rtt(key))
925937
if not self.__svm_util.is_null(value) and (len(value_type) == 0 or value_type[0] != self.__svm_util.object_type):
926938
value_type = self.__svm_util.find_shared_types(value_type, self.__svm_util.get_rtt(value))
939+
# java.lang.Object will always be the last element in a type list
940+
# if it is the only element in the list we cannot infer more than java.lang.Object
927941
if (0 <= svm_infer_generics.value <= i) or (len(key_type) > 0 and key_type[0] == self.__svm_util.object_type and
928942
len(value_type) > 0 and value_type[0] == self.__svm_util.object_type):
929943
break
@@ -1010,6 +1024,8 @@ def infer_generic_types(self) -> tuple: # (str, str):
10101024
key_type = self.__svm_util.find_shared_types(key_type, self.__svm_util.get_rtt(key))
10111025
if not self.__svm_util.is_null(value) and (len(value_type) == 0 or value_type[0] != self.__svm_util.object_type):
10121026
value_type = self.__svm_util.find_shared_types(value_type, self.__svm_util.get_rtt(value))
1027+
# java.lang.Object will always be the last element in a type list
1028+
# if it is the only element in the list we cannot infer more than java.lang.Object
10131029
if (0 <= svm_infer_generics.value <= i) or (len(key_type) > 0 and key_type[0] == self.__svm_util.object_type and
10141030
len(value_type) > 0 and value_type[0] == self.__svm_util.object_type):
10151031
break

substratevm/mx.substratevm/mx_substratevm.py

-8
Original file line numberDiff line numberDiff line change
@@ -1135,7 +1135,6 @@ def run_debug_test(image_name: str, testfile: str, source_path: str, with_isolat
11351135
else:
11361136
c_command = ['cl', '-MD', join(tutorial_c_source_dir, 'cinterfacetutorial.c'), '-I.',
11371137
'libcinterfacetutorial.lib']
1138-
mx.log(' '.join(c_command))
11391138
mx.run(c_command, cwd=build_dir)
11401139
if mx.get_os() == 'linux':
11411140
logfile = join(path, pathlib.Path(testfile).stem + ('' if with_isolates else '_no_isolates') + '.log')
@@ -1146,7 +1145,6 @@ def run_debug_test(image_name: str, testfile: str, source_path: str, with_isolat
11461145
'-iex', f"set auto-load safe-path {join(build_dir, 'gdb-debughelpers.py')}",
11471146
'-x', testfile, join(build_dir, image_name)
11481147
]
1149-
log_gdb_command(gdb_command)
11501148
# unittest may result in different exit code, nonZeroIsFatal ensures that we can go on with other test
11511149
return mx.run(gdb_command, cwd=build_dir, nonZeroIsFatal=False)
11521150
return 0
@@ -1173,10 +1171,6 @@ def run_debug_test(image_name: str, testfile: str, source_path: str, with_isolat
11731171
mx.abort(status)
11741172

11751173

1176-
def log_gdb_command(gdb_command):
1177-
mx.log(' '.join([(f"'{c}'" if ' ' in c else c) for c in gdb_command]))
1178-
1179-
11801174
def _runtimedebuginfotest(native_image, output_path, args=None):
11811175
"""Build and run the runtimedebuginfotest"""
11821176

@@ -1230,7 +1224,6 @@ def _runtimedebuginfotest(native_image, output_path, args=None):
12301224
'-iex', f"set auto-load safe-path {join(output_path, 'gdb-debughelpers.py')}",
12311225
'-x', test_runtime_compilation_py, runtime_compile_binary
12321226
]
1233-
log_gdb_command(gdb_command)
12341227
# unittest may result in different exit code, nonZeroIsFatal ensures that we can go on with other test
12351228
status = mx.run(gdb_command, cwd=output_path, nonZeroIsFatal=False)
12361229

@@ -1253,7 +1246,6 @@ def run_js_test(eager: bool = False):
12531246
'-iex', f"set auto-load safe-path {join(output_path, 'gdb-debughelpers.py')}",
12541247
'-x', test_runtime_deopt_py, '--args', js_launcher, testdeopt_js
12551248
]
1256-
log_gdb_command(gdb_command)
12571249
# unittest may result in different exit code, nonZeroIsFatal ensures that we can go on with other test
12581250
return mx.run(gdb_command, cwd=output_path, nonZeroIsFatal=False)
12591251

substratevm/mx.substratevm/testhello.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,7 @@ def test():
886886
exec_string = execute("info types com.oracle.svm.test.debug.CStructTests\$")
887887
rexp = [
888888
fr"{spaces_pattern}typedef composite_struct \* com\.oracle\.svm\.test\.debug\.CStructTests\$CompositeStruct;",
889-
fr"{spaces_pattern}typedef int32_t \* com\.oracle\.svm\.test\.debug\.CStructTests\$MyCIntPointer;",
889+
fr"{spaces_pattern}typedef int \* com\.oracle\.svm\.test\.debug\.CStructTests\$MyCIntPointer;",
890890
fr"{spaces_pattern}typedef simple_struct \* com\.oracle\.svm\.test\.debug\.CStructTests\$SimpleStruct;",
891891
fr"{spaces_pattern}typedef simple_struct2 \* com\.oracle\.svm\.test\.debug\.CStructTests\$SimpleStruct2;",
892892
fr"{spaces_pattern}typedef weird \* com\.oracle\.svm\.test\.debug\.CStructTests\$Weird;"]
@@ -927,8 +927,8 @@ def test():
927927
fr"/\*{spaces_pattern}24{spaces_pattern}\|{spaces_pattern}4{spaces_pattern}\*/{spaces_pattern}float f_float;",
928928
fr"/\*{spaces_pattern}XXX{spaces_pattern}4-byte hole{spaces_pattern}\*/",
929929
fr"/\*{spaces_pattern}32{spaces_pattern}\|{spaces_pattern}8{spaces_pattern}\*/{spaces_pattern}double f_double;",
930-
fr"/\*{spaces_pattern}40{spaces_pattern}\|{spaces_pattern}32{spaces_pattern}\*/{spaces_pattern}int32_t a_int\[8\];",
931-
fr"/\*{spaces_pattern}72{spaces_pattern}\|{spaces_pattern}12{spaces_pattern}\*/{spaces_pattern}(u)?int8_t a_char\[12\];",
930+
fr"/\*{spaces_pattern}40{spaces_pattern}\|{spaces_pattern}32{spaces_pattern}\*/{spaces_pattern}int a_int\[8\];",
931+
fr"/\*{spaces_pattern}72{spaces_pattern}\|{spaces_pattern}12{spaces_pattern}\*/{spaces_pattern}char a_char\[12\];",
932932
fr"/\*{spaces_pattern}XXX{spaces_pattern}4-byte padding{spaces_pattern}\*/",
933933
fr"{spaces_pattern}/\* total size \(bytes\):{spaces_pattern}88 \*/",
934934
fr"{spaces_pattern}}} \*"]

0 commit comments

Comments
 (0)