From b9c1b51e45b845debb76d8658edabca70ca56079 Mon Sep 17 00:00:00 2001 From: Kate Stone Date: Tue, 6 Sep 2016 20:57:50 +0000 Subject: =?UTF-8?q?***=20This=20commit=20represents=20a=20complete=20refor?= =?UTF-8?q?matting=20of=20the=20LLDB=20source=20code=20***=20to=20conform?= =?UTF-8?q?=20to=20clang-format=E2=80=99s=20LLVM=20style.=20=20This=20kind?= =?UTF-8?q?=20of=20mass=20change=20has=20***=20two=20obvious=20implication?= =?UTF-8?q?s:?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Firstly, merging this particular commit into a downstream fork may be a huge effort. Alternatively, it may be worth merging all changes up to this commit, performing the same reformatting operation locally, and then discarding the merge for this particular commit. The commands used to accomplish this reformatting were as follows (with current working directory as the root of the repository): find . \( -iname "*.c" -or -iname "*.cpp" -or -iname "*.h" -or -iname "*.mm" \) -exec clang-format -i {} + find . -iname "*.py" -exec autopep8 --in-place --aggressive --aggressive {} + ; The version of clang-format used was 3.9.0, and autopep8 was 1.2.4. Secondly, “blame” style tools will generally point to this commit instead of a meaningful prior commit. There are alternatives available that will attempt to look through this change and find the appropriate prior commit. YMMV. llvm-svn: 280751 --- .../Plugins/Process/Linux/ProcFileReader.cpp | 139 ++++++++++----------- 1 file changed, 67 insertions(+), 72 deletions(-) (limited to 'lldb/source/Plugins/Process/Linux/ProcFileReader.cpp') diff --git a/lldb/source/Plugins/Process/Linux/ProcFileReader.cpp b/lldb/source/Plugins/Process/Linux/ProcFileReader.cpp index 4d1f231..a1bb7a6 100644 --- a/lldb/source/Plugins/Process/Linux/ProcFileReader.cpp +++ b/lldb/source/Plugins/Process/Linux/ProcFileReader.cpp @@ -26,83 +26,78 @@ using namespace lldb_private; using namespace lldb_private::process_linux; -lldb::DataBufferSP -ProcFileReader::ReadIntoDataBuffer (lldb::pid_t pid, const char *name) -{ - int fd; - char path[PATH_MAX]; - - // Make sure we've got a nil terminated buffer for all the folks calling - // GetBytes() directly off our returned DataBufferSP if we hit an error. - lldb::DataBufferSP buf_sp (new DataBufferHeap(1, 0)); - - // Ideally, we would simply create a FileSpec and call ReadFileContents. - // However, files in procfs have zero size (since they are, in general, - // dynamically generated by the kernel) which is incompatible with the - // current ReadFileContents implementation. Therefore we simply stream the - // data into a DataBuffer ourselves. - if (snprintf (path, PATH_MAX, "/proc/%" PRIu64 "/%s", pid, name) > 0) - { - if ((fd = open (path, O_RDONLY, 0)) >= 0) - { - size_t bytes_read = 0; - std::unique_ptr buf_ap(new DataBufferHeap(1024, 0)); - - for (;;) - { - size_t avail = buf_ap->GetByteSize() - bytes_read; - ssize_t status = read (fd, buf_ap->GetBytes() + bytes_read, avail); - - if (status < 0) - break; - - if (status == 0) - { - buf_ap->SetByteSize (bytes_read); - buf_sp.reset (buf_ap.release()); - break; - } - - bytes_read += status; - - if (avail - status == 0) - buf_ap->SetByteSize (2 * buf_ap->GetByteSize()); - } - - close (fd); +lldb::DataBufferSP ProcFileReader::ReadIntoDataBuffer(lldb::pid_t pid, + const char *name) { + int fd; + char path[PATH_MAX]; + + // Make sure we've got a nil terminated buffer for all the folks calling + // GetBytes() directly off our returned DataBufferSP if we hit an error. + lldb::DataBufferSP buf_sp(new DataBufferHeap(1, 0)); + + // Ideally, we would simply create a FileSpec and call ReadFileContents. + // However, files in procfs have zero size (since they are, in general, + // dynamically generated by the kernel) which is incompatible with the + // current ReadFileContents implementation. Therefore we simply stream the + // data into a DataBuffer ourselves. + if (snprintf(path, PATH_MAX, "/proc/%" PRIu64 "/%s", pid, name) > 0) { + if ((fd = open(path, O_RDONLY, 0)) >= 0) { + size_t bytes_read = 0; + std::unique_ptr buf_ap(new DataBufferHeap(1024, 0)); + + for (;;) { + size_t avail = buf_ap->GetByteSize() - bytes_read; + ssize_t status = read(fd, buf_ap->GetBytes() + bytes_read, avail); + + if (status < 0) + break; + + if (status == 0) { + buf_ap->SetByteSize(bytes_read); + buf_sp.reset(buf_ap.release()); + break; } - } - - return buf_sp; -} -Error -ProcFileReader::ProcessLineByLine (lldb::pid_t pid, const char *name, std::function line_parser) -{ - Error error; - - // Try to open the /proc/{pid}/maps entry. - char filename [PATH_MAX]; - snprintf (filename, sizeof(filename), "/proc/%" PRIu64 "/%s", pid, name); - filename[sizeof (filename) - 1] = '\0'; - - std::ifstream proc_file (filename); - if (proc_file.fail ()) - { - error.SetErrorStringWithFormat ("failed to open file '%s'", filename); - return error; - } + bytes_read += status; - // Read the file line by line, processing until either end of file or when the line_parser returns false. - std::string line; - bool should_continue = true; + if (avail - status == 0) + buf_ap->SetByteSize(2 * buf_ap->GetByteSize()); + } - while (should_continue && std::getline (proc_file, line)) - { - // Pass the line over to the line_parser for processing. If the line_parser returns false, we - // stop processing. - should_continue = line_parser (line); + close(fd); } + } + + return buf_sp; +} +Error ProcFileReader::ProcessLineByLine( + lldb::pid_t pid, const char *name, + std::function line_parser) { + Error error; + + // Try to open the /proc/{pid}/maps entry. + char filename[PATH_MAX]; + snprintf(filename, sizeof(filename), "/proc/%" PRIu64 "/%s", pid, name); + filename[sizeof(filename) - 1] = '\0'; + + std::ifstream proc_file(filename); + if (proc_file.fail()) { + error.SetErrorStringWithFormat("failed to open file '%s'", filename); return error; + } + + // Read the file line by line, processing until either end of file or when the + // line_parser returns false. + std::string line; + bool should_continue = true; + + while (should_continue && std::getline(proc_file, line)) { + // Pass the line over to the line_parser for processing. If the line_parser + // returns false, we + // stop processing. + should_continue = line_parser(line); + } + + return error; } -- cgit v1.1