From: "Yordan Karadzhov (VMware)" <y.karadz@gmail.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org,
"Yordan Karadzhov (VMware)" <y.karadz@gmail.com>,
Stephen Brennan <stephen@brennan.io>
Subject: [PATCH] kernel-shark: Provide parsing for quotation marks in Record command line
Date: Tue, 27 Aug 2019 16:14:18 +0300 [thread overview]
Message-ID: <20190827131418.18713-1-y.karadz@gmail.com> (raw)
Shell-like parsing of quotation marks in the content of the "Command"
field of the "Record" dialog will give more options to the users.
For example, now we can trace
python -c 'print("hello world")'
Suggested-by: Stephen Brennan <stephen@brennan.io>
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=204679
Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
kernel-shark/src/KsCaptureDialog.cpp | 38 ++++++++++++++++++++++++++--
1 file changed, 36 insertions(+), 2 deletions(-)
diff --git a/kernel-shark/src/KsCaptureDialog.cpp b/kernel-shark/src/KsCaptureDialog.cpp
index dc1e9b2..b3393b6 100644
--- a/kernel-shark/src/KsCaptureDialog.cpp
+++ b/kernel-shark/src/KsCaptureDialog.cpp
@@ -157,7 +157,9 @@ KsCaptureControl::KsCaptureControl(QWidget *parent)
*/
QStringList KsCaptureControl::getArgs()
{
+ QString::SplitBehavior opt = QString::SkipEmptyParts;
QStringList argv;
+ QString cmdTmp;
argv << "record";
@@ -170,7 +172,36 @@ QStringList KsCaptureControl::getArgs()
argv << _eventsWidget.getCheckedEvents(true);
argv << "-o" << outputFileName();
- argv << _commandLineEdit.text().split(" ");
+
+ cmdTmp = _commandLineEdit.text();
+ if (!cmdTmp.contains('\'') && !cmdTmp.contains('\"')) {
+ /* Split all command line arguments. */
+ argv << cmdTmp.split(" ", opt);
+ } else {
+ int iOpenQuots, iCloseQuots, size = cmdTmp.size();
+ int iSingleQuots = (cmdTmp.count('\'') == 2) ? cmdTmp.indexOf('\'') : size;
+ int iDoubleQuots = (cmdTmp.count('\"') == 2) ? cmdTmp.indexOf('\"') : size;
+
+ if (iSingleQuots < iDoubleQuots) {
+ iOpenQuots = iSingleQuots;
+ iCloseQuots = cmdTmp.lastIndexOf('\'') + 1;
+ } else if (iDoubleQuots < iSingleQuots) {
+ iOpenQuots = iDoubleQuots;
+ iCloseQuots = cmdTmp.lastIndexOf('\"') + 1;
+ } else {
+ emit print("\nERROR: Unable to parse the command.");
+ return {};
+ }
+
+ /* Split the arguments. */
+ argv << cmdTmp.left(iOpenQuots).split(" ", opt);
+
+ /* Everything in between the quotation marks goes in one piece. */
+ argv << cmdTmp.mid(iOpenQuots, iCloseQuots - iOpenQuots);
+
+ /* Split the rest of the arguments. */
+ argv << cmdTmp.right(size - iCloseQuots).split(" ", opt);
+ }
return argv;
}
@@ -350,7 +381,10 @@ void KsCaptureControl::_browse()
void KsCaptureControl::_apply()
{
- emit argsReady(getArgs().join(" "));
+ QStringList argv = getArgs();
+
+ if (argv.count())
+ emit argsReady(argv.join(" "));
}
/** @brief Create KsCaptureMonitor widget. */
--
2.20.1
next reply other threads:[~2019-08-27 13:14 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-27 13:14 Yordan Karadzhov (VMware) [this message]
2019-08-28 5:10 ` [PATCH] kernel-shark: Provide parsing for quotation marks in Record command line stephen
2019-08-28 13:06 ` Steven Rostedt
2019-08-28 14:10 ` Yordan Karadzhov (VMware)
2019-08-28 14:56 ` Steven Rostedt
2019-08-28 13:25 ` Steven Rostedt
2019-08-28 13:30 ` Steven Rostedt
2019-09-17 10:44 ` Yordan Karadzhov (VMware)
2019-09-17 13:17 ` Steven Rostedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190827131418.18713-1-y.karadz@gmail.com \
--to=y.karadz@gmail.com \
--cc=linux-trace-devel@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=stephen@brennan.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).