From 32784362de8e2cfc686ce98557dd261003aff2ff Mon Sep 17 00:00:00 2001 From: hunt Date: Mon, 12 Nov 2007 21:55:53 +0000 Subject: 2007-11-12 Martin Hunt * translate.cxx (visit_print_format): Strings without a format or formatted with "%s" or "%s\n" should be printed with calls to _stp_print(). Call _stp_print_char() if printing a char. * staptree.cxx (parse_print): Check for "print_char". * staptree.h (struct print_format): Add print_char. (parse_print): Update prototype. * parse.cxx (parse_symbol): Set print_char bool in print_format. --- ChangeLog | 17 +++++++++++++++++ parse.cxx | 5 +++-- staptree.cxx | 11 +++++++++-- staptree.h | 7 +++---- translate.cxx | 38 +++++++++++++++++++++++++++++++++++--- 5 files changed, 67 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 72f8c77b..0cdb4e7d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2007-11-12 Martin Hunt + + * translate.cxx (visit_print_format): Strings without a format or + formatted with "%s" or "%s\n" should be printed with calls to _stp_print(). + Call _stp_print_char() if printing a char. + + * staptree.cxx (parse_print): Check for "print_char". + + * staptree.h (struct print_format): Add print_char. + (parse_print): Update prototype. + + * parse.cxx (parse_symbol): Set print_char bool in print_format. + +2007-11-12 Martin Hunt + + * tapsets.cxx (build_blacklist): Add __raw_spin_is_locked. + 2007-10-25 Josh Stone PR 5219 diff --git a/parse.cxx b/parse.cxx index 0b465aa8..173639b3 100644 --- a/parse.cxx +++ b/parse.cxx @@ -2234,7 +2234,7 @@ parser::parse_symbol () // now scrutinize this identifier for the various magic forms of identifier // (printf, @stat_op, and $var...) - bool pf_stream, pf_format, pf_delim, pf_newline; + bool pf_stream, pf_format, pf_delim, pf_newline, pf_char; if (name.size() > 0 && name[0] == '@') { @@ -2259,7 +2259,7 @@ parser::parse_symbol () } else if (print_format::parse_print(name, - pf_stream, pf_format, pf_delim, pf_newline)) + pf_stream, pf_format, pf_delim, pf_newline, pf_char)) { print_format *fmt = new print_format; fmt->tok = t; @@ -2267,6 +2267,7 @@ parser::parse_symbol () fmt->print_with_format = pf_format; fmt->print_with_delim = pf_delim; fmt->print_with_newline = pf_newline; + fmt->print_char = pf_char; expect_op("("); if ((name == "print" || name == "println") && diff --git a/staptree.cxx b/staptree.cxx index ccfc8a8d..d71472a6 100644 --- a/staptree.cxx +++ b/staptree.cxx @@ -340,12 +340,18 @@ void functioncall::print (ostream& o) const bool print_format::parse_print(const std::string &name, - bool &stream, bool &format, bool &delim, bool &newline) + bool &stream, bool &format, bool &delim, bool &newline, bool &_char) { const char *n = name.c_str(); stream = true; - format = delim = newline = false; + format = delim = newline = _char = false; + + if (strcmp(n, "print_char") == 0) + { + _char = true; + return true; + } if (*n == 's') { @@ -2292,6 +2298,7 @@ deep_copy_visitor::visit_print_format (print_format* e) n->print_with_format = e->print_with_format; n->print_with_delim = e->print_with_delim; n->print_with_newline = e->print_with_newline; + n->print_char = e->print_char; n->raw_components = e->raw_components; n->components = e->components; n->delimiter = e->delimiter; diff --git a/staptree.h b/staptree.h index a6b7c173..23f43566 100644 --- a/staptree.h +++ b/staptree.h @@ -266,6 +266,7 @@ struct print_format: public expression bool print_with_format; bool print_with_delim; bool print_with_newline; + bool print_char; enum format_flag { @@ -328,8 +329,8 @@ struct print_format: public expression static std::string components_to_string(std::vector const & components); static std::vector string_to_components(std::string const & str); - static bool parse_print(const std::string &name, - bool &stream, bool &format, bool &delim, bool &newline); + static bool parse_print(const std::string &name, bool &stream, + bool &format, bool &delim, bool &newline, bool &_char); void print (std::ostream& o) const; void visit (visitor* u); @@ -560,8 +561,6 @@ struct stapfile }; - - struct probe_point { struct component // XXX: sort of a restricted functioncall diff --git a/translate.cxx b/translate.cxx index 4ecc6b9f..d3e76108 100644 --- a/translate.cxx +++ b/translate.cxx @@ -4078,16 +4078,48 @@ c_unparser::visit_print_format (print_format* e) } } - // Allocate the result exp_type ty = e->print_to_stream ? pe_long : pe_string; tmpvar res = gensym (ty); + int use_print = 0; + + string format_string = print_format::components_to_string(components); + if (tmp.size() == 0 || (tmp.size() == 1 && format_string == "%s")) + use_print = 1; + else if (tmp.size() == 1 + && e->args[0]->tok->type == tok_string + && format_string == "%s\\n") + { + use_print = 1; + tmp[0].override(tmp[0].value() + "\"\\n\""); + } // Make the [s]printf call, but not if there was an error evaluating the args o->newline() << "if (likely (! c->last_error)) {"; o->indent(1); if (e->print_to_stream) { + if (e->print_char) + { + o->newline() << "_stp_print_char ("; + if (tmp.size()) + o->line() << tmp[0].value() << ");"; + else + o->line() << '"' << format_string << "\");"; + o->newline(-1) << "}"; + return; + } + if (use_print) + { + o->newline() << "_stp_print ("; + if (tmp.size()) + o->line() << tmp[0].value() << ");"; + else + o->line() << '"' << format_string << "\");"; + o->newline(-1) << "}"; + return; + } + // We'll just hardcode the result of 0 instead of using the // temporary. res.override("((int64_t)0LL)"); @@ -4096,8 +4128,8 @@ c_unparser::visit_print_format (print_format* e) else o->newline() << "_stp_snprintf (" << res.value() << ", MAXSTRINGLEN, "; - o->line() << '"' << print_format::components_to_string(components) << '"'; - + o->line() << '"' << format_string << '"'; + for (unsigned i = 0; i < tmp.size(); ++i) o->line() << ", " << tmp[i].value(); o->line() << ");"; -- cgit