Skip to content

Commit b5622cb

Browse files
authored
implement support for vFile:mode and vFile:size packets (#141)
## Purpose Implement responses to the `vFile:mode` and `vFile:size` packets in ds2 platform and debug server sessions. Fully addresses issue #136. ## Overview * Add `File::fileMode` support to the `Host::File` interface * Implement the POSIX version of `Host::File::fileMode` using `stat(2)` * Stub-out the Windows implementation of `Host::File::fileMode` * Override and implement the existing `SessionDelegate::onFileGetSize` method in `FileOperationsMixin` to call the exiting `Host::File::fileSize` method * Add a new `SessionDelegate::onFileGetMode` method and override it in `FileOperationsMixin` to call the new `Host::File::fileMode` method * Fix error response of `vFile:size` to match the lldb documentation. ## Problem Details DS2 does not properly implement responses to the `vFile:mode` and `vFile:size` packets. These packets are documented [here](https://lldb.llvm.org/resources/lldbgdbremote.html#vfile-packets). Most of the pieces for `vFile:size` were already present, but they were not all tied together. ## Validation With some other uncommitted local patches, verify the following lldb test cases pass on Android and Linux: ``` TestGdbRemotePlatformFile.TestGdbRemotePlatformFile.test_platform_file_mode_fail_llgs TestGdbRemotePlatformFile.TestGdbRemotePlatformFile.test_platform_file_mode_llgs TestGdbRemotePlatformFile.TestGdbRemotePlatformFile.test_platform_file_size_llgs ``` These test cases will be re-enabled in CI testing after this and a number of other patches are merged.
1 parent ad33b38 commit b5622cb

File tree

9 files changed

+56
-3
lines changed

9 files changed

+56
-3
lines changed

Headers/DebugServer2/GDBRemote/DummySessionDelegateImpl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@ class DummySessionDelegateImpl : public SessionDelegate {
245245
uint8_t digest[16]) override;
246246
ErrorCode onFileGetSize(Session &session, std::string const &path,
247247
uint64_t &size) override;
248+
ErrorCode onFileGetMode(Session &session, std::string const &path,
249+
uint32_t &mode) const override;
248250

249251
ErrorCode onQueryProcessList(Session &session, ProcessInfoMatch const &match,
250252
bool first, ProcessInfo &info) const override;

Headers/DebugServer2/GDBRemote/Mixins/FileOperationsMixin.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ template <typename T> class FileOperationsMixin : public T {
4545

4646
protected:
4747
ErrorCode onFileExists(Session &session, std::string const &path) override;
48+
ErrorCode onFileGetSize(Session &session, std::string const &path,
49+
uint64_t &size) override;
50+
ErrorCode onFileGetMode(Session &session, std::string const &path,
51+
uint32_t &mode) const override;
4852
ErrorCode onFileRemove(Session &session, std::string const &path) override;
4953

5054
protected:

Headers/DebugServer2/GDBRemote/SessionDelegate.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,8 @@ class SessionDelegate {
272272
uint8_t digest[16]) = 0;
273273
virtual ErrorCode onFileGetSize(Session &session, std::string const &path,
274274
uint64_t &size) = 0;
275+
virtual ErrorCode onFileGetMode(Session &session, std::string const &path,
276+
uint32_t &mode) const = 0;
275277

276278
virtual ErrorCode onQueryProcessList(Session &session,
277279
ProcessInfoMatch const &match,

Headers/DebugServer2/Host/File.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class File {
6363

6464
public:
6565
static ErrorCode fileSize(std::string const &path, uint64_t &size);
66+
static ErrorCode fileMode(std::string const &path, uint32_t &mode);
6667

6768
protected:
6869
int _fd;

Sources/GDBRemote/DummySessionDelegateImpl.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,8 @@ DUMMY_IMPL_EMPTY(onFileComputeMD5, Session &, std::string const &, uint8_t[16])
293293

294294
DUMMY_IMPL_EMPTY(onFileGetSize, Session &, std::string const &, uint64_t &)
295295

296+
DUMMY_IMPL_EMPTY_CONST(onFileGetMode, Session &, std::string const &, uint32_t&)
297+
296298
DUMMY_IMPL_EMPTY_CONST(onQueryProcessList, Session &, ProcessInfoMatch const &,
297299
bool, ProcessInfo &)
298300

Sources/GDBRemote/Mixins/FileOperationsMixin.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,19 @@ ErrorCode FileOperationsMixin<T>::onFileExists(Session &,
8888
return Host::Platform::IsFilePresent(path) ? kSuccess : kErrorNotFound;
8989
}
9090

91+
template <typename T>
92+
ErrorCode FileOperationsMixin<T>::onFileGetSize(Session &session, std::string const &path,
93+
uint64_t &size){
94+
return Host::File::fileSize(path, size);
95+
}
96+
97+
template <typename T>
98+
ErrorCode FileOperationsMixin<T>::onFileGetMode(Session &session,
99+
std::string const &path,
100+
uint32_t &mode) const {
101+
return Host::File::fileMode(path, mode);
102+
}
103+
91104
template <typename T>
92105
ErrorCode FileOperationsMixin<T>::onFileRemove(Session &session,
93106
std::string const &path) {

Sources/GDBRemote/Session.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2964,6 +2964,7 @@ void Session::Handle_vFile(ProtocolInterpreter::Handler const &,
29642964
//
29652965
// LLDB: vFile:exists:path
29662966
// vFile:size:path
2967+
// vFile:mode:path
29672968
// vFile:MD5:path
29682969
//
29692970
bool escaped = false;
@@ -3093,11 +3094,25 @@ void Session::Handle_vFile(ProtocolInterpreter::Handler const &,
30933094
uint64_t size;
30943095
ErrorCode error =
30953096
_delegate->onFileGetSize(*this, HexToString(&args[op_end]), size);
3096-
// Fsize or Exx if error.
3097+
// Response is F followed by the file size in base 16 or
3098+
// F-1,errno with the errno if an error occurs, base 16.
3099+
ss << 'F';
30973100
if (error != kSuccess) {
3098-
ss << 'E' << std::hex << error;
3101+
ss << -1 << std::hex << error;
30993102
} else {
3100-
ss << 'F' << std::hex << size;
3103+
ss << std::hex << size;
3104+
}
3105+
} else if (op == "mode") {
3106+
uint32_t mode;
3107+
ErrorCode error =
3108+
_delegate->onFileGetMode(*this, HexToString(&args[op_end]), mode);
3109+
// Response is F followed by the mode bits in base 16 or
3110+
// F-1,errno with the errno if an error occurs, base 16
3111+
ss << 'F';
3112+
if (error != kSuccess) {
3113+
ss << -1 << ',' << std::hex << error;
3114+
} else {
3115+
ss << std::hex << mode;
31013116
}
31023117
} else {
31033118
sendError(kErrorUnsupported);

Sources/Host/POSIX/File.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,5 +163,14 @@ ErrorCode File::fileSize(std::string const &path, uint64_t &size) {
163163
size = static_cast<uint64_t>(stbuf.st_size);
164164
return kSuccess;
165165
}
166+
167+
ErrorCode File::fileMode(std::string const &path, uint32_t &mode) {
168+
struct stat stbuf;
169+
if (stat(path.c_str(), &stbuf) < 0)
170+
return Platform::TranslateError();
171+
172+
mode = static_cast<uint32_t>(ALLPERMS & stbuf.st_mode);
173+
return kSuccess;
174+
}
166175
} // namespace Host
167176
} // namespace ds2

Sources/Host/Windows/File.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,10 @@ ErrorCode File::createDirectory(std::string const &path, uint32_t flags) {
4242
ErrorCode File::fileSize(std::string const &path, uint64_t &size) {
4343
return kErrorUnsupported;
4444
}
45+
46+
ErrorCode File::fileMode(std::string const &path, uint32_t &mode) {
47+
return kErrorUnsupported;
48+
}
49+
4550
} // namespace Host
4651
} // namespace ds2

0 commit comments

Comments
 (0)