Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Side by Side Diff: gdb/gdbserver/hostio.c

Issue 11969036: Merge GDB 7.5.1 (Closed) Base URL: http://git.chromium.org/native_client/nacl-gdb.git@master
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gdb/gdbserver/gdbthread.h ('k') | gdb/gdbserver/i386-low.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* Host file transfer support for gdbserver. 1 /* Host file transfer support for gdbserver.
2 Copyright (C) 2007-2012 Free Software Foundation, Inc. 2 Copyright (C) 2007-2012 Free Software Foundation, Inc.
3 3
4 Contributed by CodeSourcery. 4 Contributed by CodeSourcery.
5 5
6 This file is part of GDB. 6 This file is part of GDB.
7 7
8 This program is free software; you can redistribute it and/or modify 8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by 9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or 10 the Free Software Foundation; either version 3 of the License, or
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 || require_end (p)) 321 || require_end (p))
322 { 322 {
323 hostio_packet_error (own_buf); 323 hostio_packet_error (own_buf);
324 return; 324 return;
325 } 325 }
326 326
327 data = xmalloc (len); 327 data = xmalloc (len);
328 #ifdef HAVE_PREAD 328 #ifdef HAVE_PREAD
329 ret = pread (fd, data, len, offset); 329 ret = pread (fd, data, len, offset);
330 #else 330 #else
331 ret = lseek (fd, offset, SEEK_SET); 331 ret = -1;
332 if (ret != -1)
333 ret = read (fd, data, len);
334 #endif 332 #endif
333 /* If we have no pread or it failed for this file, use lseek/read. */
334 if (ret == -1)
335 {
336 ret = lseek (fd, offset, SEEK_SET);
337 if (ret != -1)
338 ret = read (fd, data, len);
339 }
335 340
336 if (ret == -1) 341 if (ret == -1)
337 { 342 {
338 hostio_error (own_buf); 343 hostio_error (own_buf);
339 free (data); 344 free (data);
340 return; 345 return;
341 } 346 }
342 347
343 bytes_sent = hostio_reply_with_data (own_buf, data, ret, new_packet_len); 348 bytes_sent = hostio_reply_with_data (own_buf, data, ret, new_packet_len);
344 349
(...skipping 24 matching lines...) Expand all
369 || require_comma (&p) 374 || require_comma (&p)
370 || require_data (p, packet_len - (p - own_buf), &data, &len)) 375 || require_data (p, packet_len - (p - own_buf), &data, &len))
371 { 376 {
372 hostio_packet_error (own_buf); 377 hostio_packet_error (own_buf);
373 return; 378 return;
374 } 379 }
375 380
376 #ifdef HAVE_PWRITE 381 #ifdef HAVE_PWRITE
377 ret = pwrite (fd, data, len, offset); 382 ret = pwrite (fd, data, len, offset);
378 #else 383 #else
379 ret = lseek (fd, offset, SEEK_SET); 384 ret = -1;
380 if (ret != -1)
381 ret = write (fd, data, len);
382 #endif 385 #endif
386 /* If we have no pwrite or it failed for this file, use lseek/write. */
387 if (ret == -1)
388 {
389 ret = lseek (fd, offset, SEEK_SET);
390 if (ret != -1)
391 ret = write (fd, data, len);
392 }
383 393
384 if (ret == -1) 394 if (ret == -1)
385 { 395 {
386 hostio_error (own_buf); 396 hostio_error (own_buf);
387 free (data); 397 free (data);
388 return; 398 return;
389 } 399 }
390 400
391 hostio_reply (own_buf, ret); 401 hostio_reply (own_buf, ret);
392 free (data); 402 free (data);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 459
450 if (ret == -1) 460 if (ret == -1)
451 { 461 {
452 hostio_error (own_buf); 462 hostio_error (own_buf);
453 return; 463 return;
454 } 464 }
455 465
456 hostio_reply (own_buf, ret); 466 hostio_reply (own_buf, ret);
457 } 467 }
458 468
469 static void
470 handle_readlink (char *own_buf, int *new_packet_len)
471 {
472 #if defined (HAVE_READLINK)
473 char filename[PATH_MAX], linkname[PATH_MAX];
474 char *p;
475 int ret, bytes_sent;
476
477 p = own_buf + strlen ("vFile:readlink:");
478
479 if (require_filename (&p, filename)
480 || require_end (p))
481 {
482 hostio_packet_error (own_buf);
483 return;
484 }
485
486 ret = readlink (filename, linkname, sizeof linkname);
487 if (ret == -1)
488 {
489 hostio_error (own_buf);
490 return;
491 }
492
493 bytes_sent = hostio_reply_with_data (own_buf, linkname, ret, new_packet_len);
494
495 /* If the response does not fit into a single packet, do not attempt
496 to return a partial response, but simply fail. */
497 if (bytes_sent < ret)
498 sprintf (own_buf, "F-1,%x", FILEIO_ENAMETOOLONG);
499 #else /* ! HAVE_READLINK */
500 sprintf (own_buf, "F-1,%x", FILEIO_ENOSYS);
501 #endif
502 }
503
459 /* Handle all the 'F' file transfer packets. */ 504 /* Handle all the 'F' file transfer packets. */
460 505
461 int 506 int
462 handle_vFile (char *own_buf, int packet_len, int *new_packet_len) 507 handle_vFile (char *own_buf, int packet_len, int *new_packet_len)
463 { 508 {
464 if (strncmp (own_buf, "vFile:open:", 11) == 0) 509 if (strncmp (own_buf, "vFile:open:", 11) == 0)
465 handle_open (own_buf); 510 handle_open (own_buf);
466 else if (strncmp (own_buf, "vFile:pread:", 11) == 0) 511 else if (strncmp (own_buf, "vFile:pread:", 11) == 0)
467 handle_pread (own_buf, new_packet_len); 512 handle_pread (own_buf, new_packet_len);
468 else if (strncmp (own_buf, "vFile:pwrite:", 12) == 0) 513 else if (strncmp (own_buf, "vFile:pwrite:", 12) == 0)
469 handle_pwrite (own_buf, packet_len); 514 handle_pwrite (own_buf, packet_len);
470 else if (strncmp (own_buf, "vFile:close:", 12) == 0) 515 else if (strncmp (own_buf, "vFile:close:", 12) == 0)
471 handle_close (own_buf); 516 handle_close (own_buf);
472 else if (strncmp (own_buf, "vFile:unlink:", 13) == 0) 517 else if (strncmp (own_buf, "vFile:unlink:", 13) == 0)
473 handle_unlink (own_buf); 518 handle_unlink (own_buf);
519 else if (strncmp (own_buf, "vFile:readlink:", 15) == 0)
520 handle_readlink (own_buf, new_packet_len);
474 else 521 else
475 return 0; 522 return 0;
476 523
477 return 1; 524 return 1;
478 } 525 }
OLDNEW
« no previous file with comments | « gdb/gdbserver/gdbthread.h ('k') | gdb/gdbserver/i386-low.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698