Index: llvm/test/tools/llvm-dwarfdump/X86/locstats-bytes-overflow.yaml =================================================================== --- llvm/test/tools/llvm-dwarfdump/X86/locstats-bytes-overflow.yaml +++ llvm/test/tools/llvm-dwarfdump/X86/locstats-bytes-overflow.yaml @@ -1,4 +1,7 @@ -# RUN: yaml2obj %s | llvm-dwarfdump --statistics - 2>&1 | FileCheck %s +# RUN: yaml2obj %s -o %t.o +# RUN: llvm-dwarfdump --statistics %t.o 2>&1 | FileCheck %s +# RUN: not %llvm-locstats %t.o 2>&1 | FileCheck %s --check-prefix=LOCSTATS +# RUN: rm %t.o ## Check that we are covering the situation when a stat field overflows. ## @@ -22,6 +25,7 @@ ## [0x0000000000000003, 0x0000000000000005): DW_OP_reg2 RCX) # CHECK: "sum_all_variables(#bytes in parent scope)": "overflowed" +# LOCSTATS: error: "sum_all_variables(#bytes in parent scope)" field overflowed. --- !ELF FileHeader: Index: llvm/utils/llvm-locstats/llvm-locstats.py =================================================================== --- llvm/utils/llvm-locstats/llvm-locstats.py +++ llvm/utils/llvm-locstats/llvm-locstats.py @@ -179,6 +179,8 @@ universal_newlines = True) cmd_stdout, cmd_stderr = subproc.communicate() + # TODO: Handle errors that are coming from llvm-dwarfdump. + # Get the JSON and parse it. json_parsed = None @@ -190,84 +192,91 @@ # TODO: Parse the statistics Version from JSON. + def init_field(name): + if json_parsed[name] == 'overflowed': + print ('error: "' + name + '" field overflowed.') + sys.exit(1) + return json_parsed[name] + if opts.only_variables: # Read the JSON only for local variables. variables_total_locstats = \ - json_parsed['#local vars processed by location statistics'] + init_field('#local vars processed by location statistics') variables_scope_bytes_covered = \ - json_parsed['sum_all_local_vars(#bytes in parent scope covered' \ - ' by DW_AT_location)'] + init_field('sum_all_local_vars(#bytes in parent scope covered' \ + ' by DW_AT_location)') variables_scope_bytes = \ - json_parsed['sum_all_local_vars(#bytes in parent scope)'] + init_field('sum_all_local_vars(#bytes in parent scope)') if not opts.ignore_debug_entry_values: for cov_bucket in coverage_buckets(): cov_category = "#local vars with {} of parent scope covered " \ "by DW_AT_location".format(cov_bucket) - variables_coverage_map[cov_bucket] = json_parsed[cov_category] + variables_coverage_map[cov_bucket] = init_field(cov_category) else: variables_scope_bytes_entry_values = \ - json_parsed['sum_all_local_vars(#bytes in parent scope ' \ - 'covered by DW_OP_entry_value)'] + init_field('sum_all_local_vars(#bytes in parent scope ' \ + 'covered by DW_OP_entry_value)') variables_scope_bytes_covered = variables_scope_bytes_covered \ - variables_scope_bytes_entry_values for cov_bucket in coverage_buckets(): cov_category = \ "#local vars - entry values with {} of parent scope " \ "covered by DW_AT_location".format(cov_bucket) - variables_coverage_map[cov_bucket] = json_parsed[cov_category] + variables_coverage_map[cov_bucket] = init_field(cov_category) elif opts.only_formal_parameters: # Read the JSON only for formal parameters. variables_total_locstats = \ - json_parsed['#params processed by location statistics'] + init_field('#params processed by location statistics') variables_scope_bytes_covered = \ - json_parsed['sum_all_params(#bytes in parent scope covered ' \ - 'by DW_AT_location)'] + init_field('sum_all_params(#bytes in parent scope covered ' \ + 'by DW_AT_location)') variables_scope_bytes = \ - json_parsed['sum_all_params(#bytes in parent scope)'] + init_field('sum_all_params(#bytes in parent scope)') if not opts.ignore_debug_entry_values: for cov_bucket in coverage_buckets(): cov_category = "#params with {} of parent scope covered " \ "by DW_AT_location".format(cov_bucket) - variables_coverage_map[cov_bucket] = json_parsed[cov_category] + variables_coverage_map[cov_bucket] = init_field(cov_category) else: variables_scope_bytes_entry_values = \ - json_parsed['sum_all_params(#bytes in parent scope covered ' \ - 'by DW_OP_entry_value)'] + init_field('sum_all_params(#bytes in parent scope covered ' \ + 'by DW_OP_entry_value)') variables_scope_bytes_covered = variables_scope_bytes_covered \ - variables_scope_bytes_entry_values for cov_bucket in coverage_buckets(): cov_category = \ "#params - entry values with {} of parent scope covered" \ " by DW_AT_location".format(cov_bucket) - variables_coverage_map[cov_bucket] = json_parsed[cov_category] + variables_coverage_map[cov_bucket] = init_field(cov_category) else: # Read the JSON for both local variables and formal parameters. variables_total = \ - json_parsed['#source variables'] - variables_with_loc = json_parsed['#source variables with location'] + init_field('#source variables') + variables_with_loc = init_field('#source variables with location') variables_total_locstats = \ - json_parsed['#variables processed by location statistics'] + init_field('#variables processed by location statistics') variables_scope_bytes_covered = \ - json_parsed['sum_all_variables(#bytes in parent scope covered ' \ - 'by DW_AT_location)'] + init_field('sum_all_variables(#bytes in parent scope covered ' \ + 'by DW_AT_location)') variables_scope_bytes = \ - json_parsed['sum_all_variables(#bytes in parent scope)'] + init_field('sum_all_variables(#bytes in parent scope)') + if not opts.ignore_debug_entry_values: for cov_bucket in coverage_buckets(): cov_category = "#variables with {} of parent scope covered " \ "by DW_AT_location".format(cov_bucket) - variables_coverage_map[cov_bucket] = json_parsed[cov_category] + variables_coverage_map[cov_bucket] = init_field(cov_category) else: variables_scope_bytes_entry_values = \ - json_parsed['sum_all_variables(#bytes in parent scope covered ' \ - 'by DW_OP_entry_value)'] + init_field('sum_all_variables(#bytes in parent scope covered ' \ + 'by DW_OP_entry_value)') variables_scope_bytes_covered = variables_scope_bytes_covered \ - variables_scope_bytes_entry_values for cov_bucket in coverage_buckets(): cov_category = \ "#variables - entry values with {} of parent scope covered " \ "by DW_AT_location".format(cov_bucket) - variables_coverage_map[cov_bucket] = json_parsed[cov_category] + variables_coverage_map[cov_bucket] = init_field(cov_category) return LocationStats(binary, variables_total, variables_total_locstats, variables_with_loc, variables_scope_bytes_covered,