Changeset 056d6821 in mainline for uspace/app
- Timestamp:
- 2011-07-26T21:17:29Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 051e6ac, 0837ab4
- Parents:
- 2f02ee25 (diff), 75aa59a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- uspace/app
- Files:
-
- 1 deleted
- 11 edited
-
bdsh/cmds/modules/cp/cp.c (modified) (2 diffs)
-
bdsh/cmds/modules/ls/ls.c (modified) (1 diff)
-
bdsh/compl.c (modified) (1 diff)
-
bdsh/exec.c (modified) (1 diff)
-
bdsh/input.c (modified) (1 diff)
-
init/init.c (modified) (1 diff)
-
taskdump/elf_core.c (modified) (14 diffs)
-
taskdump/include/elf.h (deleted)
-
taskdump/include/elf_core.h (modified) (1 diff)
-
taskdump/include/symtab.h (modified) (1 diff)
-
taskdump/symtab.c (modified) (8 diffs)
-
taskdump/taskdump.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/cmds/modules/cp/cp.c
r2f02ee25 r056d6821 71 71 size_t blen, int vb) 72 72 { 73 int fd1, fd2, bytes = 0;74 off64_t total = 0;73 int fd1, fd2, bytes; 74 off64_t total; 75 75 int64_t copied = 0; 76 76 char *buff = NULL; … … 104 104 } 105 105 106 for (;;) { 107 ssize_t res; 108 size_t written = 0; 109 110 bytes = read(fd1, buff, blen); 111 if (bytes <= 0) 106 while ((bytes = read_all(fd1, buff, blen)) > 0) { 107 if ((bytes = write_all(fd2, buff, bytes)) < 0) 112 108 break; 113 109 copied += bytes; 114 res = bytes;115 do {116 /*117 * Theoretically, it may not be enough to call write()118 * only once. Also the previous read() may have119 * returned less data than requested.120 */121 bytes = write(fd2, buff + written, res);122 if (bytes < 0)123 goto err;124 written += bytes;125 res -= bytes;126 } while (res > 0);127 128 /* TODO: re-insert assert() once this is stand alone,129 * removed as abort() exits the entire shell130 */131 if (res != 0) {132 printf("\n%zd more bytes than actually exist were copied\n", res);133 goto err;134 }135 110 } 136 111 137 112 if (bytes < 0) { 138 err:139 113 printf("\nError copying %s, (%d)\n", src, bytes); 140 114 copied = bytes; -
uspace/app/bdsh/cmds/modules/ls/ls.c
r2f02ee25 r056d6821 169 169 170 170 /* fill the name field */ 171 tosort[nbdirs].name = (char *) malloc(str_ length(dp->d_name) + 1);171 tosort[nbdirs].name = (char *) malloc(str_size(dp->d_name) + 1); 172 172 if (!tosort[nbdirs].name) { 173 173 cli_error(CL_ENOMEM, "ls: failed to scan %s", d); 174 174 goto out; 175 175 } 176 177 str_cpy(tosort[nbdirs].name, str_ length(dp->d_name) + 1, dp->d_name);176 177 str_cpy(tosort[nbdirs].name, str_size(dp->d_name) + 1, dp->d_name); 178 178 len = snprintf(buff, PATH_MAX - 1, "%s/%s", d, tosort[nbdirs].name); 179 179 buff[len] = '\0'; -
uspace/app/bdsh/compl.c
r2f02ee25 r056d6821 280 280 281 281 cs->dir = opendir(*cs->path); 282 283 /* Skip directories that we fail to open. */ 284 if (cs->dir == NULL) 285 cs->path++; 282 286 } 283 287 -
uspace/app/bdsh/exec.c
r2f02ee25 r056d6821 52 52 static int try_access(const char *); 53 53 54 const char *search_dir[] = { " app", "srv", NULL };54 const char *search_dir[] = { "/app", "/srv", NULL }; 55 55 56 56 /* work-around for access() */ -
uspace/app/bdsh/input.c
r2f02ee25 r056d6821 170 170 } 171 171 172 rc = run_command( cmd, usr, &new_iostate);172 rc = run_command(actual_cmd, usr, &new_iostate); 173 173 174 174 finit_with_files: -
uspace/app/init/init.c
r2f02ee25 r056d6821 294 294 295 295 #ifdef CONFIG_MOUNT_DATA 296 /* Make sure fat is running. */ 297 if (str_cmp(STRING(RDFMT), "fat") != 0) { 298 srv_start("/srv/fat"); 299 } 296 300 mount_data(); 297 301 #else -
uspace/app/taskdump/elf_core.c
r2f02ee25 r056d6821 1 1 /* 2 * Copyright (c) 201 0Jiri Svoboda2 * Copyright (c) 2011 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 38 38 * Looking at core files produced by Linux, these don't have section headers, 39 39 * only program headers, although objdump shows them as having sections. 40 * Basically at the beginning there should be a note segment (which we 41 * do not write) and one loadable segment per memory area (which we do write). 42 * 43 * The note segment probably contains register state, etc. -- we don't 44 * deal with these yet. Nevertheless you can use these core files with 45 * objdump or gdb. 46 */ 47 40 * Basically at the beginning there should be a note segment followed 41 * by one loadable segment per memory area. 42 * 43 * The note segment contains a series of records with register state, 44 * process info etc. We only write one record NT_PRSTATUS which contains 45 * process/register state (anything which is not register state we fill 46 * with zeroes). 47 */ 48 49 #include <align.h> 50 #include <elf/elf.h> 51 #include <elf/elf_linux.h> 48 52 #include <stdio.h> 49 53 #include <stdlib.h> … … 58 62 #include <udebug.h> 59 63 #include <macros.h> 60 61 #include <elf.h> 62 #include " include/elf_core.h"64 #include <libarch/istate.h> 65 66 #include "elf_core.h" 63 67 64 68 static off64_t align_foff_up(off64_t, uintptr_t, size_t); 65 static int write_all(int, void *, size_t);69 static int align_pos(int, size_t); 66 70 static int write_mem_area(int, as_area_info_t *, async_sess_t *); 67 71 … … 83 87 */ 84 88 int elf_core_save(const char *file_name, as_area_info_t *ainfo, unsigned int n, 85 async_sess_t *sess )89 async_sess_t *sess, istate_t *istate) 86 90 { 87 91 elf_header_t elf_hdr; … … 90 94 elf_word flags; 91 95 elf_segment_header_t *p_hdr; 96 elf_prstatus_t pr_status; 97 elf_note_t note; 98 size_t word_size; 92 99 93 100 int fd; 94 int rc;101 ssize_t rc; 95 102 unsigned int i; 96 103 97 n_ph = n; 98 99 p_hdr = malloc(sizeof(elf_segment_header_t) * n); 104 #ifdef __32_BITS__ 105 word_size = 4; 106 #endif 107 #ifdef __64_BITS__ 108 word_size = 8; 109 #endif 110 memset(&pr_status, 0, sizeof(pr_status)); 111 istate_to_elf_regs(istate, &pr_status.regs); 112 113 n_ph = n + 1; 114 115 p_hdr = malloc(sizeof(elf_segment_header_t) * n_ph); 100 116 if (p_hdr == NULL) { 101 117 printf("Failed allocating memory.\n"); … … 115 131 * ELF header 116 132 * program headers 133 * note segment 117 134 * repeat: 118 135 * (pad for alignment) 119 * segment data136 * core segment 120 137 * end repeat 121 138 */ … … 147 164 foff = elf_hdr.e_phoff + n_ph * sizeof(elf_segment_header_t); 148 165 149 for (i = 1; i <= n; ++i) { 150 foff = align_foff_up(foff, ainfo[i - 1].start_addr, PAGE_SIZE); 166 memset(&p_hdr[0], 0, sizeof(p_hdr[0])); 167 p_hdr[0].p_type = PT_NOTE; 168 p_hdr[0].p_offset = foff; 169 p_hdr[0].p_vaddr = 0; 170 p_hdr[0].p_paddr = 0; 171 p_hdr[0].p_filesz = sizeof(elf_note_t) 172 + ALIGN_UP((str_size("CORE") + 1), word_size) 173 + ALIGN_UP(sizeof(elf_prstatus_t), word_size); 174 p_hdr[0].p_memsz = 0; 175 p_hdr[0].p_flags = 0; 176 p_hdr[0].p_align = 1; 177 178 foff += p_hdr[0].p_filesz; 179 180 for (i = 0; i < n; ++i) { 181 foff = align_foff_up(foff, ainfo[i].start_addr, PAGE_SIZE); 151 182 152 183 flags = 0; 153 if (ainfo[i - 1].flags & AS_AREA_READ)184 if (ainfo[i].flags & AS_AREA_READ) 154 185 flags |= PF_R; 155 if (ainfo[i - 1].flags & AS_AREA_WRITE)186 if (ainfo[i].flags & AS_AREA_WRITE) 156 187 flags |= PF_W; 157 if (ainfo[i - 1].flags & AS_AREA_EXEC)188 if (ainfo[i].flags & AS_AREA_EXEC) 158 189 flags |= PF_X; 159 190 160 memset(&p_hdr[i - 1], 0, sizeof(p_hdr[i -1]));161 p_hdr[i -1].p_type = PT_LOAD;162 p_hdr[i -1].p_offset = foff;163 p_hdr[i - 1].p_vaddr = ainfo[i - 1].start_addr;164 p_hdr[i -1].p_paddr = 0;165 p_hdr[i - 1].p_filesz = ainfo[i - 1].size;166 p_hdr[i - 1].p_memsz = ainfo[i - 1].size;167 p_hdr[i -1].p_flags = flags;168 p_hdr[i -1].p_align = PAGE_SIZE;169 170 foff += ainfo[i - 1].size;191 memset(&p_hdr[i + 1], 0, sizeof(p_hdr[i + 1])); 192 p_hdr[i + 1].p_type = PT_LOAD; 193 p_hdr[i + 1].p_offset = foff; 194 p_hdr[i + 1].p_vaddr = ainfo[i].start_addr; 195 p_hdr[i + 1].p_paddr = 0; 196 p_hdr[i + 1].p_filesz = ainfo[i].size; 197 p_hdr[i + 1].p_memsz = ainfo[i].size; 198 p_hdr[i + 1].p_flags = flags; 199 p_hdr[i + 1].p_align = PAGE_SIZE; 200 201 foff += ainfo[i].size; 171 202 } 172 203 173 204 rc = write_all(fd, &elf_hdr, sizeof(elf_hdr)); 174 if (rc != EOK) {205 if (rc != sizeof(elf_hdr)) { 175 206 printf("Failed writing ELF header.\n"); 176 207 free(p_hdr); … … 180 211 for (i = 0; i < n_ph; ++i) { 181 212 rc = write_all(fd, &p_hdr[i], sizeof(p_hdr[i])); 182 if (rc != EOK) {213 if (rc != sizeof(p_hdr[i])) { 183 214 printf("Failed writing program header.\n"); 184 215 free(p_hdr); … … 187 218 } 188 219 189 for (i = 0; i < n_ph; ++i) { 220 if (lseek(fd, p_hdr[0].p_offset, SEEK_SET) == (off64_t) -1) { 221 printf("Failed writing memory data.\n"); 222 free(p_hdr); 223 return EIO; 224 } 225 226 /* 227 * Write note header 228 */ 229 note.namesz = str_size("CORE") + 1; 230 note.descsz = sizeof(elf_prstatus_t); 231 note.type = NT_PRSTATUS; 232 233 rc = write_all(fd, ¬e, sizeof(elf_note_t)); 234 if (rc != sizeof(elf_note_t)) { 235 printf("Failed writing note header.\n"); 236 free(p_hdr); 237 return EIO; 238 } 239 240 rc = write_all(fd, "CORE", note.namesz); 241 if (rc != (ssize_t) note.namesz) { 242 printf("Failed writing note header.\n"); 243 free(p_hdr); 244 return EIO; 245 } 246 247 rc = align_pos(fd, word_size); 248 if (rc != EOK) { 249 printf("Failed writing note header.\n"); 250 free(p_hdr); 251 return EIO; 252 } 253 254 rc = write_all(fd, &pr_status, sizeof(elf_prstatus_t)); 255 if (rc != sizeof(elf_prstatus_t)) { 256 printf("Failed writing register data.\n"); 257 free(p_hdr); 258 return EIO; 259 } 260 261 for (i = 1; i < n_ph; ++i) { 190 262 if (lseek(fd, p_hdr[i].p_offset, SEEK_SET) == (off64_t) -1) { 191 263 printf("Failed writing memory data.\n"); … … 193 265 return EIO; 194 266 } 195 if (write_mem_area(fd, &ainfo[i ], sess) != EOK) {267 if (write_mem_area(fd, &ainfo[i - 1], sess) != EOK) { 196 268 printf("Failed writing memory data.\n"); 197 269 free(p_hdr); … … 210 282 off64_t rva = vaddr % page_size; 211 283 off64_t rfo = foff % page_size; 212 284 213 285 if (rva >= rfo) 214 286 return (foff + (rva - rfo)); 215 287 216 288 return (foff + (page_size + (rva - rfo))); 217 289 } … … 231 303 size_t total; 232 304 uintptr_t addr; 233 int rc;305 ssize_t rc; 234 306 235 307 addr = area->start_addr; … … 245 317 246 318 rc = write_all(fd, buffer, to_copy); 247 if (rc != EOK) {319 if (rc != (ssize_t) to_copy) { 248 320 printf("Failed writing memory contents.\n"); 249 321 return EIO; … … 257 329 } 258 330 259 /** Write until the buffer is written in its entirety. 260 * 261 * This function fails if it cannot write exactly @a len bytes to the file. 262 * 263 * @param fd The file to write to. 264 * @param buf Data, @a len bytes long. 265 * @param len Number of bytes to write. 266 * 267 * @return EOK on error, return value from write() if writing 268 * failed. 269 */ 270 static int write_all(int fd, void *data, size_t len) 331 static int align_pos(int fd, size_t align) 271 332 { 272 int cnt = 0;273 274 do { 275 data += cnt;276 len -= cnt;277 cnt = write(fd, data, len);278 } while (cnt > 0 && (len - cnt) > 0); 279 280 if (cnt < 0)281 return cnt; 282 283 if ( len - cnt >0)284 return EIO;333 off64_t cur_pos; 334 size_t rem, adv; 335 336 cur_pos = lseek(fd, 0, SEEK_CUR); 337 if (cur_pos < 0) 338 return -1; 339 340 rem = cur_pos % align; 341 adv = align - rem; 342 343 cur_pos = lseek(fd, adv, SEEK_CUR); 344 if (cur_pos < 0) 345 return -1; 285 346 286 347 return EOK; 287 348 } 288 349 289 290 350 /** @} 291 351 */ -
uspace/app/taskdump/include/elf_core.h
r2f02ee25 r056d6821 37 37 38 38 #include <async.h> 39 #include <elf/elf_linux.h> 40 #include <libarch/istate.h> 39 41 40 42 extern int elf_core_save(const char *, as_area_info_t *, unsigned int, 41 async_sess_t * );43 async_sess_t *, istate_t *); 42 44 43 45 #endif -
uspace/app/taskdump/include/symtab.h
r2f02ee25 r056d6821 36 36 #define SYMTAB_H_ 37 37 38 #include <elf/elf.h> 38 39 #include <sys/types.h> 39 #include <elf.h>40 40 41 41 typedef struct { -
uspace/app/taskdump/symtab.c
r2f02ee25 r056d6821 36 36 */ 37 37 38 #include <elf/elf.h> 38 39 #include <stdio.h> 39 40 #include <stdlib.h> … … 43 44 #include <fcntl.h> 44 45 45 #include <elf.h>46 46 #include "include/symtab.h" 47 47 … … 50 50 elf_section_header_t *shdr); 51 51 static int chunk_load(int fd, off64_t start, size_t size, void **ptr); 52 static int read_all(int fd, void *buf, size_t len);53 52 54 53 /** Load symbol table from an ELF file. … … 90 89 91 90 rc = read_all(fd, &elf_hdr, sizeof(elf_header_t)); 92 if (rc != EOK) {91 if (rc != sizeof(elf_header_t)) { 93 92 printf("failed reading elf header\n"); 94 93 free(stab); … … 312 311 313 312 rc = read_all(fd, sec_hdr, sizeof(elf_section_header_t)); 314 if (rc != EOK)313 if (rc != sizeof(elf_section_header_t)) 315 314 return EIO; 316 315 … … 331 330 static int chunk_load(int fd, off64_t start, size_t size, void **ptr) 332 331 { 333 int rc; 334 335 rc = lseek(fd, start, SEEK_SET); 336 if (rc == (off64_t) -1) { 332 ssize_t rc; 333 off64_t offs; 334 335 offs = lseek(fd, start, SEEK_SET); 336 if (offs == (off64_t) -1) { 337 337 printf("failed seeking chunk\n"); 338 338 *ptr = NULL; … … 347 347 348 348 rc = read_all(fd, *ptr, size); 349 if (rc != EOK) {349 if (rc != (ssize_t) size) { 350 350 printf("failed reading chunk\n"); 351 351 free(*ptr); … … 357 357 } 358 358 359 /** Read until the buffer is read in its entirety.360 *361 * This function fails if it cannot read exactly @a len bytes from the file.362 *363 * @param fd The file to read from.364 * @param buf Buffer for storing data, @a len bytes long.365 * @param len Number of bytes to read.366 *367 * @return EOK on error, EIO if file is short or return value368 * from read() if reading failed.369 */370 static int read_all(int fd, void *buf, size_t len)371 {372 int cnt = 0;373 374 do {375 buf += cnt;376 len -= cnt;377 cnt = read(fd, buf, len);378 } while (cnt > 0 && (len - cnt) > 0);379 380 if (cnt < 0)381 return cnt;382 383 if (len - cnt > 0)384 return EIO;385 386 return EOK;387 }388 389 359 /** @} 390 360 */ -
uspace/app/taskdump/taskdump.c
r2f02ee25 r056d6821 34 34 35 35 #include <async.h> 36 #include <elf/elf_linux.h> 36 37 #include <stdio.h> 37 38 #include <stdlib.h> … … 72 73 static char *get_app_task_name(void); 73 74 static char *fmt_sym_address(uintptr_t addr); 75 76 static istate_t reg_state; 74 77 75 78 int main(int argc, char *argv[]) … … 293 296 if (write_core_file) { 294 297 printf("Writing core file '%s'\n", core_file_name); 295 rc = elf_core_save(core_file_name, ainfo_buf, n_areas, sess); 298 299 rc = elf_core_save(core_file_name, ainfo_buf, n_areas, sess, 300 ®_state); 301 296 302 if (rc != EOK) { 297 303 printf("Failed writing core file.\n"); … … 321 327 pc = istate_get_pc(&istate); 322 328 fp = istate_get_fp(&istate); 329 330 /* Save register state for dumping to core file later. */ 331 reg_state = istate; 323 332 324 333 sym_pc = fmt_sym_address(pc);
Note:
See TracChangeset
for help on using the changeset viewer.
