| 1 | /*
|
|---|
| 2 | * Copyright (c) 2023 Jiří Zárevúcky
|
|---|
| 3 | * All rights reserved.
|
|---|
| 4 | *
|
|---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
|---|
| 6 | * modification, are permitted provided that the following conditions
|
|---|
| 7 | * are met:
|
|---|
| 8 | *
|
|---|
| 9 | * - Redistributions of source code must retain the above copyright
|
|---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
|---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
|---|
| 13 | * documentation and/or other materials provided with the distribution.
|
|---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
|---|
| 15 | * derived from this software without specific prior written permission.
|
|---|
| 16 | *
|
|---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 27 | */
|
|---|
| 28 |
|
|---|
| 29 | #ifndef DWARFS_LINE_H_
|
|---|
| 30 | #define DWARFS_LINE_H_
|
|---|
| 31 |
|
|---|
| 32 | #include <stdbool.h>
|
|---|
| 33 | #include <stddef.h>
|
|---|
| 34 | #include <stdint.h>
|
|---|
| 35 | #include <debug/sections.h>
|
|---|
| 36 |
|
|---|
| 37 | struct debug_line_program_header {
|
|---|
| 38 | uint64_t unit_length;
|
|---|
| 39 | uint64_t header_length;
|
|---|
| 40 | const uint8_t *unit_end;
|
|---|
| 41 | const uint8_t *header_end;
|
|---|
| 42 | const uint8_t *standard_opcode_lengths;
|
|---|
| 43 | size_t standard_opcode_lengths_size;
|
|---|
| 44 | unsigned width;
|
|---|
| 45 | uint16_t version;
|
|---|
| 46 | uint8_t minimum_instruction_length;
|
|---|
| 47 | bool default_is_stmt;
|
|---|
| 48 | int8_t line_base;
|
|---|
| 49 | uint8_t line_range;
|
|---|
| 50 | uint8_t opcode_base;
|
|---|
| 51 |
|
|---|
| 52 | union {
|
|---|
| 53 | struct {
|
|---|
| 54 | const uint8_t *include_directories;
|
|---|
| 55 | const uint8_t *include_directories_end;
|
|---|
| 56 | const uint8_t *file_names;
|
|---|
| 57 | } v3;
|
|---|
| 58 | struct {
|
|---|
| 59 | uint64_t directories_count;
|
|---|
| 60 | uint64_t file_names_count;
|
|---|
| 61 | const uint8_t *directory_entry_format;
|
|---|
| 62 | const uint8_t *directory_entry_format_end;
|
|---|
| 63 | const uint8_t *directories;
|
|---|
| 64 | const uint8_t *directories_end;
|
|---|
| 65 | const uint8_t *file_name_entry_format;
|
|---|
| 66 | const uint8_t *file_name_entry_format_end;
|
|---|
| 67 | const uint8_t *file_names;
|
|---|
| 68 | const uint8_t *file_names_end;
|
|---|
| 69 | uint8_t address_size;
|
|---|
| 70 | uint8_t segment_selector_size;
|
|---|
| 71 | uint8_t directory_entry_format_count;
|
|---|
| 72 | uint8_t file_name_entry_format_count;
|
|---|
| 73 | uint8_t maximum_operations_per_instruction;
|
|---|
| 74 | } v5;
|
|---|
| 75 | };
|
|---|
| 76 | };
|
|---|
| 77 |
|
|---|
| 78 | struct debug_line_program {
|
|---|
| 79 | const struct debug_line_program_header *hdr;
|
|---|
| 80 | const uint8_t *program;
|
|---|
| 81 | const uint8_t *program_end;
|
|---|
| 82 |
|
|---|
| 83 | uintptr_t address;
|
|---|
| 84 | int op_advance;
|
|---|
| 85 | int file;
|
|---|
| 86 | int line;
|
|---|
| 87 | int column;
|
|---|
| 88 |
|
|---|
| 89 | bool end_sequence;
|
|---|
| 90 | bool truncated;
|
|---|
| 91 | };
|
|---|
| 92 |
|
|---|
| 93 | static inline struct debug_line_program debug_line_program_create(const uint8_t *program,
|
|---|
| 94 | const uint8_t *const program_end,
|
|---|
| 95 | const struct debug_line_program_header *hdr)
|
|---|
| 96 | {
|
|---|
| 97 | return (struct debug_line_program) {
|
|---|
| 98 | .hdr = hdr,
|
|---|
| 99 | .program = program,
|
|---|
| 100 | .program_end = program_end,
|
|---|
| 101 | .end_sequence = true,
|
|---|
| 102 | .truncated = false,
|
|---|
| 103 | };
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 | extern bool debug_line_get_address_info(debug_sections_t *scs, uintptr_t addr, int op_index, const char **file, const char **dir, int *line, int *col);
|
|---|
| 107 |
|
|---|
| 108 | #endif /* DWARFS_LINE_H_ */
|
|---|