diff options
-rw-r--r-- | ChangeLog | 17 | ||||
-rw-r--r-- | parse.cxx | 5 | ||||
-rw-r--r-- | staptree.cxx | 11 | ||||
-rw-r--r-- | staptree.h | 7 | ||||
-rw-r--r-- | translate.cxx | 38 |
5 files changed, 67 insertions, 11 deletions
@@ -1,3 +1,20 @@ +2007-11-12 Martin Hunt <hunt@redhat.com> + + * 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 <hunt@redhat.com> + + * tapsets.cxx (build_blacklist): Add __raw_spin_is_locked. + 2007-10-25 Josh Stone <joshua.i.stone@intel.com> PR 5219 @@ -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; @@ -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<format_component> const & components); static std::vector<format_component> 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() << ");"; |