1 /* Utility target functions for GDB, and GDBserver.
3 Copyright (C) 2015 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #include "common-defs.h"
21 #include "target/target-utils.h"
24 read_alloc (gdb_byte
**buf_p
, int handle
, read_alloc_pread_ftype
*pread_func
,
27 size_t buf_alloc
, buf_pos
;
32 /* Start by reading up to 4K at a time. The target will throttle
33 this number down if necessary. */
35 buf
= xmalloc (buf_alloc
);
39 n
= pread_func (handle
, &buf
[buf_pos
], buf_alloc
- buf_pos
- padding
,
40 buf_pos
, &target_errno
);
43 if (n
< 0 || (n
== 0 && buf_pos
== 0))
49 /* An error occurred. */
54 /* Read all there was. */
61 /* If the buffer is filling up, expand it. */
62 if (buf_alloc
< buf_pos
* 2)
65 buf
= xrealloc (buf
, buf_alloc
);
71 read_stralloc (struct inferior
*inf
, const char *filename
,
72 read_stralloc_func_ftype
*func
)
76 LONGEST i
, transferred
;
78 transferred
= func (inf
, filename
, &buffer
, 1);
79 bufstr
= (char *) buffer
;
87 bufstr
[transferred
] = 0;
89 /* Check for embedded NUL bytes; but allow trailing NULs. */
90 for (i
= strlen (bufstr
); i
< transferred
; i
++)
93 warning (_("target file %s "
94 "contained unexpected null characters"),
This page took 0.033516 seconds and 4 git commands to generate.