Coverage Report

Created: 2026-07-25 10:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/binutils-gdb/opcodes/dis-buf.c
Line
Count
Source
1
/* Disassemble from a buffer, for GNU.
2
   Copyright (C) 1993-2026 Free Software Foundation, Inc.
3
4
   This file is part of the GNU opcodes library.
5
6
   This library is free software; you can redistribute it and/or modify
7
   it under the terms of the GNU General Public License as published by
8
   the Free Software Foundation; either version 3, or (at your option)
9
   any later version.
10
11
   It is distributed in the hope that it will be useful, but WITHOUT
12
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13
   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
14
   License for more details.
15
16
   You should have received a copy of the GNU General Public License
17
   along with this program; if not, write to the Free Software
18
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19
   MA 02110-1301, USA.  */
20
21
#include "sysdep.h"
22
#include "dis-asm.h"
23
#include <errno.h>
24
#include "opintl.h"
25
26
/* Get LENGTH bytes from info's buffer, at target address memaddr.
27
   Transfer them to myaddr.  */
28
int
29
buffer_read_memory (bfd_vma memaddr,
30
        bfd_byte *myaddr,
31
        unsigned int length,
32
        struct disassemble_info *info)
33
165M
{
34
165M
  unsigned int opb = info->octets_per_byte;
35
165M
  size_t addr_off, to_stop;
36
37
165M
  if (memaddr < info->buffer_vma
38
165M
      || _bfd_mul_overflow (memaddr - info->buffer_vma, opb, &addr_off)
39
165M
      || addr_off > info->buffer_length
40
164M
      || length > info->buffer_length - addr_off
41
164M
      || (info->stop_vma
42
0
    && (memaddr >= info->stop_vma
43
0
        || _bfd_mul_overflow (info->stop_vma - memaddr, opb, &to_stop)
44
0
        || length > to_stop)))
45
    /* Out of bounds.  Use EIO because GDB uses it.  */
46
774k
    return EIO;
47
164M
  memcpy (myaddr, info->buffer + addr_off, length);
48
49
164M
  return 0;
50
165M
}
51
52
/* Print an error message.  We can assume that this is in response to
53
   an error return from buffer_read_memory.  */
54
55
void
56
perror_memory (int status,
57
         bfd_vma memaddr,
58
         struct disassemble_info *info)
59
90.0k
{
60
90.0k
  if (status != EIO)
61
    /* Can't happen.  */
62
0
    info->fprintf_func (info->stream, _("Unknown error %d\n"), status);
63
90.0k
  else
64
90.0k
    {
65
      /* Actually, address between memaddr and memaddr + len was
66
   out of bounds.  */
67
90.0k
      info->fprintf_func (info->stream,
68
90.0k
        _("Address 0x%" PRIx64 " is out of bounds.\n"),
69
90.0k
        (uint64_t) memaddr);
70
90.0k
    }
71
90.0k
}
72
73
/* This could be in a separate file, to save miniscule amounts of space
74
   in statically linked executables.  */
75
76
/* Just print the address is hex.  This is included for completeness even
77
   though both GDB and objdump provide their own (to print symbolic
78
   addresses).  */
79
80
void
81
generic_print_address (bfd_vma addr, struct disassemble_info *info)
82
5.20M
{
83
5.20M
  (*info->fprintf_func) (info->stream, "0x%08" PRIx64, (uint64_t) addr);
84
5.20M
}
85
86
/* Just return NULL.  */
87
88
asymbol *
89
generic_symbol_at_address (bfd_vma addr ATTRIBUTE_UNUSED,
90
         struct disassemble_info *info ATTRIBUTE_UNUSED)
91
347k
{
92
347k
  return NULL;
93
347k
}
94
95
/* Just return TRUE.  */
96
97
bool
98
generic_symbol_is_valid (asymbol * sym ATTRIBUTE_UNUSED,
99
       struct disassemble_info *info ATTRIBUTE_UNUSED)
100
24.0k
{
101
  return true;
102
24.0k
}