@@ -271,15 +271,13 @@ class CommandObjectTargetCreate : public CommandObjectParsed {
271
271
FileSpec remote_file (m_remote_file.GetOptionValue ().GetCurrentValue ());
272
272
273
273
if (core_file) {
274
- if (!FileSystem::Instance ().Exists (core_file)) {
275
- result.AppendErrorWithFormat (" core file '%s' doesn't exist" ,
276
- core_file.GetPath ().c_str ());
277
- result.SetStatus (eReturnStatusFailed);
278
- return false ;
279
- }
280
- if (!FileSystem::Instance ().Readable (core_file)) {
281
- result.AppendErrorWithFormat (" core file '%s' is not readable" ,
282
- core_file.GetPath ().c_str ());
274
+ auto file = FileSystem::Instance ().Open (
275
+ core_file, lldb_private::File::eOpenOptionRead);
276
+
277
+ if (!file) {
278
+ result.AppendErrorWithFormatv (" Cannot open '{0}': {1}." ,
279
+ core_file.GetPath (),
280
+ llvm::toString (file.takeError ()));
283
281
result.SetStatus (eReturnStatusFailed);
284
282
return false ;
285
283
}
@@ -288,18 +286,13 @@ class CommandObjectTargetCreate : public CommandObjectParsed {
288
286
if (argc == 1 || core_file || remote_file) {
289
287
FileSpec symfile (m_symbol_file.GetOptionValue ().GetCurrentValue ());
290
288
if (symfile) {
291
- if (FileSystem::Instance ().Exists (symfile)) {
292
- if (!FileSystem::Instance ().Readable (symfile)) {
293
- result.AppendErrorWithFormat (" symbol file '%s' is not readable" ,
294
- symfile.GetPath ().c_str ());
295
- result.SetStatus (eReturnStatusFailed);
296
- return false ;
297
- }
298
- } else {
299
- char symfile_path[PATH_MAX];
300
- symfile.GetPath (symfile_path, sizeof (symfile_path));
301
- result.AppendErrorWithFormat (" invalid symbol file path '%s'" ,
302
- symfile_path);
289
+ auto file = FileSystem::Instance ().Open (
290
+ symfile, lldb_private::File::eOpenOptionRead);
291
+
292
+ if (!file) {
293
+ result.AppendErrorWithFormatv (" Cannot open '{0}': {1}." ,
294
+ symfile.GetPath (),
295
+ llvm::toString (file.takeError ()));
303
296
result.SetStatus (eReturnStatusFailed);
304
297
return false ;
305
298
}
@@ -401,48 +394,34 @@ class CommandObjectTargetCreate : public CommandObjectParsed {
401
394
if (module_sp)
402
395
module_sp->SetPlatformFileSpec (remote_file);
403
396
}
397
+
404
398
if (core_file) {
405
- char core_path[PATH_MAX];
406
- core_file.GetPath (core_path, sizeof (core_path));
407
- if (FileSystem::Instance ().Exists (core_file)) {
408
- if (!FileSystem::Instance ().Readable (core_file)) {
409
- result.AppendMessageWithFormat (
410
- " Core file '%s' is not readable.\n " , core_path);
411
- result.SetStatus (eReturnStatusFailed);
412
- return false ;
413
- }
414
- FileSpec core_file_dir;
415
- core_file_dir.GetDirectory () = core_file.GetDirectory ();
416
- target_sp->AppendExecutableSearchPaths (core_file_dir);
399
+ FileSpec core_file_dir;
400
+ core_file_dir.GetDirectory () = core_file.GetDirectory ();
401
+ target_sp->AppendExecutableSearchPaths (core_file_dir);
417
402
418
- ProcessSP process_sp (target_sp->CreateProcess (
419
- GetDebugger ().GetListener (), llvm::StringRef (), &core_file));
403
+ ProcessSP process_sp (target_sp->CreateProcess (
404
+ GetDebugger ().GetListener (), llvm::StringRef (), &core_file));
420
405
421
- if (process_sp) {
422
- // Seems weird that we Launch a core file, but that is what we
423
- // do!
424
- error = process_sp->LoadCore ();
406
+ if (process_sp) {
407
+ // Seems weird that we Launch a core file, but that is what we
408
+ // do!
409
+ error = process_sp->LoadCore ();
425
410
426
- if (error.Fail ()) {
427
- result.AppendError (
428
- error.AsCString (" can't find plug-in for core file" ));
429
- result.SetStatus (eReturnStatusFailed);
430
- return false ;
431
- } else {
432
- result.AppendMessageWithFormat (
433
- " Core file '%s' (%s) was loaded.\n " , core_path,
434
- target_sp->GetArchitecture ().GetArchitectureName ());
435
- result.SetStatus (eReturnStatusSuccessFinishNoResult);
436
- }
437
- } else {
438
- result.AppendErrorWithFormat (
439
- " Unable to find process plug-in for core file '%s'\n " ,
440
- core_path);
411
+ if (error.Fail ()) {
412
+ result.AppendError (
413
+ error.AsCString (" can't find plug-in for core file" ));
441
414
result.SetStatus (eReturnStatusFailed);
415
+ return false ;
416
+ } else {
417
+ result.AppendMessageWithFormatv (" Core file '{0}' ({1}) was loaded.\n " , core_file.GetPath (),
418
+ target_sp->GetArchitecture ().GetArchitectureName ());
419
+ result.SetStatus (eReturnStatusSuccessFinishNoResult);
442
420
}
443
421
} else {
444
- result.AppendErrorWithFormat (" Core file '%s' does not exist\n " ,
445
- core_path);
422
+ result.AppendErrorWithFormatv (
423
+ " Unable to find process plug-in for core file '{0}'\n " ,
424
+ core_file.GetPath ());
446
425
result.SetStatus (eReturnStatusFailed);
447
426
}
448
427
} else {
0 commit comments