From 63d8b0ec0788ae2033ed966b18fac3ebb43a89d0 Mon Sep 17 00:00:00 2001 From: Sehong Na Date: Sat, 31 May 2014 12:36:06 +0900 Subject: [PATCH 1/1] Initialize Tizen 2.3 --- AUTHOR | 7 + LICENSE | 517 +++++++++ LICENSE.LGPLv2.1 | 503 +++++++++ LICENSE.MIT | 8 + Makefile | 106 ++ NOTICE | 9 + custom_chart/da_chart.c | 592 ++++++++++ custom_chart/da_chart.h | 110 ++ custom_chart/da_chart_dummy.c | 65 ++ dynamic-analysis-probe.manifest | 5 + helper/addr-capi.c | 58 + helper/addr-tizen.c | 58 + helper/appfw-capi.c | 37 + helper/appfw-tizen.cpp | 60 + helper/btsym.c | 481 ++++++++ helper/dacapture.c | 437 ++++++++ helper/dacollection.c | 838 ++++++++++++++ helper/dahelper.c | 109 ++ helper/libdaprobe.c | 793 +++++++++++++ helper/private_link.h | 374 +++++++ include/dacollection.h | 148 +++ include/daerror.h | 54 + include/dahelper.h | 237 ++++ include/daprobe.h | 363 ++++++ include/dautil.h | 39 + include/khash.h | 325 ++++++ include/probeinfo.h | 174 +++ include/tizen_probe.h | 78 ++ packaging/dynamic-analysis-probe.changes | 9 + packaging/dynamic-analysis-probe.manifest | 5 + packaging/dynamic-analysis-probe.spec | 45 + probe_capi/capi_appfw.c | 179 +++ probe_event/da_event.c | 134 +++ probe_event/da_event.h | 137 +++ probe_event/gesture.cpp | 654 +++++++++++ probe_event/gesture.h | 86 ++ probe_event/keytouch.c | 277 +++++ probe_event/orientation.c | 79 ++ probe_file/da_io.h | 315 ++++++ probe_file/da_io_posix.c | 1189 ++++++++++++++++++++ probe_file/da_io_stdc.c | 634 +++++++++++ probe_memory/da_memory.h | 65 ++ probe_memory/libdamemalloc.c | 183 +++ probe_memory/libdamemmanage.c | 103 ++ probe_memory/libdanew.cpp | 276 +++++ probe_socket/da_socket.h | 65 ++ probe_socket/libdasocket.c | 1457 ++++++++++++++++++++++++ probe_third/libdaemon.c | 89 ++ probe_thread/da_sync.h | 89 ++ probe_thread/da_thread.h | 71 ++ probe_thread/libdasync.c | 416 +++++++ probe_thread/libdathread.c | 646 +++++++++++ probe_tizenapi/tizen_constructor.cpp | 1164 +++++++++++++++++++ probe_tizenapi/tizen_controls.cpp | 469 ++++++++ probe_tizenapi/tizen_file.cpp | 1383 +++++++++++++++++++++++ probe_tizenapi/tizen_lifecycle.cpp | 214 ++++ probe_tizenapi/tizen_sync.cpp | 1135 +++++++++++++++++++ probe_tizenapi/tizen_thread.cpp | 1737 +++++++++++++++++++++++++++++ probe_ui/capi_capture.c | 99 ++ probe_ui/da_ui.h | 65 ++ probe_ui/tizen_capture.cpp | 375 +++++++ probe_ui/tizen_display.cpp | 108 ++ probe_ui/tizen_frameani.cpp | 78 ++ probe_ui/tizen_frameani.h | 58 + probe_ui/tizen_scenemanager.cpp | 171 +++ probe_userfunc/libdauserfunc.c | 562 ++++++++++ 66 files changed, 21406 insertions(+) create mode 100644 AUTHOR create mode 100644 LICENSE create mode 100644 LICENSE.LGPLv2.1 create mode 100644 LICENSE.MIT create mode 100644 Makefile create mode 100644 NOTICE create mode 100755 custom_chart/da_chart.c create mode 100755 custom_chart/da_chart.h create mode 100755 custom_chart/da_chart_dummy.c create mode 100644 dynamic-analysis-probe.manifest create mode 100644 helper/addr-capi.c create mode 100644 helper/addr-tizen.c create mode 100644 helper/appfw-capi.c create mode 100644 helper/appfw-tizen.cpp create mode 100755 helper/btsym.c create mode 100755 helper/dacapture.c create mode 100755 helper/dacollection.c create mode 100755 helper/dahelper.c create mode 100755 helper/libdaprobe.c create mode 100644 helper/private_link.h create mode 100755 include/dacollection.h create mode 100755 include/daerror.h create mode 100755 include/dahelper.h create mode 100644 include/daprobe.h create mode 100644 include/dautil.h create mode 100755 include/khash.h create mode 100755 include/probeinfo.h create mode 100755 include/tizen_probe.h create mode 100644 packaging/dynamic-analysis-probe.changes create mode 100644 packaging/dynamic-analysis-probe.manifest create mode 100644 packaging/dynamic-analysis-probe.spec create mode 100644 probe_capi/capi_appfw.c create mode 100755 probe_event/da_event.c create mode 100755 probe_event/da_event.h create mode 100755 probe_event/gesture.cpp create mode 100644 probe_event/gesture.h create mode 100755 probe_event/keytouch.c create mode 100644 probe_event/orientation.c create mode 100755 probe_file/da_io.h create mode 100755 probe_file/da_io_posix.c create mode 100644 probe_file/da_io_stdc.c create mode 100644 probe_memory/da_memory.h create mode 100755 probe_memory/libdamemalloc.c create mode 100644 probe_memory/libdamemmanage.c create mode 100644 probe_memory/libdanew.cpp create mode 100644 probe_socket/da_socket.h create mode 100644 probe_socket/libdasocket.c create mode 100644 probe_third/libdaemon.c create mode 100644 probe_thread/da_sync.h create mode 100644 probe_thread/da_thread.h create mode 100644 probe_thread/libdasync.c create mode 100644 probe_thread/libdathread.c create mode 100755 probe_tizenapi/tizen_constructor.cpp create mode 100755 probe_tizenapi/tizen_controls.cpp create mode 100755 probe_tizenapi/tizen_file.cpp create mode 100755 probe_tizenapi/tizen_lifecycle.cpp create mode 100755 probe_tizenapi/tizen_sync.cpp create mode 100755 probe_tizenapi/tizen_thread.cpp create mode 100755 probe_ui/capi_capture.c create mode 100755 probe_ui/da_ui.h create mode 100755 probe_ui/tizen_capture.cpp create mode 100644 probe_ui/tizen_display.cpp create mode 100644 probe_ui/tizen_frameani.cpp create mode 100644 probe_ui/tizen_frameani.h create mode 100755 probe_ui/tizen_scenemanager.cpp create mode 100755 probe_userfunc/libdauserfunc.c diff --git a/AUTHOR b/AUTHOR new file mode 100644 index 0000000..bd2e3c1 --- /dev/null +++ b/AUTHOR @@ -0,0 +1,7 @@ +Jaewon Lim +Woojin Jung +Yeongtaik Byeon +Jooyoul Lee +Sanghyun Lee +Juyoung Kim +HyunGoo Kang diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..09068c3 --- /dev/null +++ b/LICENSE @@ -0,0 +1,517 @@ +The MIT License (MIT) +Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + + + + + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! + + diff --git a/LICENSE.LGPLv2.1 b/LICENSE.LGPLv2.1 new file mode 100644 index 0000000..816d2c9 --- /dev/null +++ b/LICENSE.LGPLv2.1 @@ -0,0 +1,503 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! + diff --git a/LICENSE.MIT b/LICENSE.MIT new file mode 100644 index 0000000..7b26146 --- /dev/null +++ b/LICENSE.MIT @@ -0,0 +1,8 @@ +The MIT License (MIT) +Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..be45bd6 --- /dev/null +++ b/Makefile @@ -0,0 +1,106 @@ +CURDIR = `pwd` +INSTALLDIR = usr/lib + +DUMMY_VERSION = 0.0.1 + +INC_COMMON = -I./include \ + -I./probe_thread \ + -I/usr/include/system \ + -I/usr/include/appfw \ + -I/usr/include/ecore-1 \ + -I/usr/include/evas-1 \ + -I/usr/include/eina-1 \ + -I/usr/include/eina-1/eina \ + -I/usr/include/elementary-1 \ + -I/usr/include/eet-1 \ + -I/usr/include/edje-1 \ + -I/usr/include/efreet-1 \ + -I/usr/include/ethumb-1 \ + -I/usr/include/e_dbus-1 \ + -I/usr/include/dbus-1.0 \ + -I/usr/lib/dbus-1.0/include +INC_CAPI = $(INC_COMMON) #-I/usr/include/vconf -I/usr/include/pixman-1 +INC_TIZEN = $(INC_COMMON) -I/usr/include/osp + +COMMON_SRCS = ./helper/libdaprobe.c \ + ./helper/dahelper.c \ + ./helper/btsym.c \ + ./helper/dacollection.c \ + ./helper/dacapture.c \ + ./probe_memory/libdamemalloc.c \ + ./probe_memory/libdamemmanage.c \ + ./custom_chart/da_chart.c \ + ./probe_socket/libdasocket.c \ + ./probe_event/da_event.c \ + ./probe_event/keytouch.c \ + ./probe_event/orientation.c \ + ./probe_third/libdaemon.c \ + ./probe_thread/libdathread.c \ + ./probe_thread/libdasync.c \ + ./probe_userfunc/libdauserfunc.c \ + ./probe_file/da_io_posix.c \ + ./probe_file/da_io_stdc.c + +CAPI_SRCS =$(COMMON_SRCS) \ + ./helper/appfw-capi.c \ + ./helper/addr-capi.c \ + ./probe_capi/capi_appfw.c \ + ./probe_ui/capi_capture.c + +TIZEN_SRCS = $(COMMON_SRCS) \ + ./helper/appfw-tizen.cpp \ + ./helper/addr-tizen.c \ + ./probe_memory/libdanew.cpp \ + ./probe_tizenapi/tizen_file.cpp \ + ./probe_tizenapi/tizen_thread.cpp \ + ./probe_tizenapi/tizen_lifecycle.cpp \ + ./probe_tizenapi/tizen_sync.cpp \ + ./probe_tizenapi/tizen_controls.cpp \ + ./probe_tizenapi/tizen_constructor.cpp \ + ./probe_event/gesture.cpp \ + ./probe_ui/tizen_capture.cpp \ + ./probe_ui/tizen_scenemanager.cpp \ + ./probe_ui/tizen_frameani.cpp \ + ./probe_ui/tizen_display.cpp + +DUMMY_SRCS = ./custom_chart/da_chart_dummy.c + +CAPI_TARGET = da_probe_capi.so +TIZEN_TARGET = da_probe_tizen.so +DUMMY_TARGET = libdaprobe.so + +COMMON_FLAGS = -D_GNU_SOURCE -fPIC -shared -Wall -funwind-tables -fomit-frame-pointer -Xlinker --no-undefined +CAPI_FLAGS = $(COMMON_FLAGS) +TIZEN_FLAGS = $(COMMON_FLAGS) -DTIZENAPP + +LIBDIR_COMMON = +LIBDIR_CAPI = $(LIBDIR_COMMON) +LIBDIR_TIZEN = $(LIBDIR_COMMON) -L/usr/lib/osp + +COMMON_LDFLAGS = -ldl -lpthread -lrt -lecore -levas -lecore_input -leina -lecore_x -lcapi-system-runtime-info -lcapi-appfw-application -lX11 -lXext +CAPI_LDFLAGS = $(COMMON_LDFLAGS) +TIZEN_LDFLAGS = $(COMMON_LDFLAGS) -lstdc++ -losp-uifw -losp-appfw +DUMMY_LDFLAGS = + +all: $(CAPI_TARGET) $(TIZEN_TARGET) $(DUMMY_TARGET) +capi: $(CAPI_TARGET) +tizen: $(TIZEN_TARGET) +dummy: $(DUMMY_TARGET) + +$(CAPI_TARGET): $(CAPI_SRCS) + $(CC) $(INC_CAPI) $(CAPI_FLAGS) $(LIBDIR_CAPI) -o $@ $(CAPI_SRCS) $(CAPI_LDFLAGS) + +$(TIZEN_TARGET): $(TIZEN_SRCS) + $(CC) $(INC_TIZEN) $(TIZEN_FLAGS) $(LIBDIR_TIZEN) -o $@ $(TIZEN_SRCS) $(TIZEN_LDFLAGS) + +$(DUMMY_TARGET): $(DUMMY_SRCS) + $(CC) $(INC_TIZEN) $(COMMON_FLAGS) -o $@ $(DUMMY_SRCS) $(DUMMY_LDFLAGS) + + +install: + [ -d "$(DESTDIR)/$(INSTALLDIR)" ] || mkdir -p $(DESTDIR)/$(INSTALLDIR) + install $(TIZEN_TARGET) $(DUMMY_TARGET) $(DESTDIR)/$(INSTALLDIR)/ + +clean: + rm -f *.so *.o + diff --git a/NOTICE b/NOTICE new file mode 100644 index 0000000..9ae1cd0 --- /dev/null +++ b/NOTICE @@ -0,0 +1,9 @@ +Copyright (c) 2013 Samsung Electronics Co., Ltd. All rights reserved. +Except as noted, this software is licensed under Lesser GNU Public License , Version 2.1. +Please, see the LICENSE.LGPLv2.1 file for Lesser General Public License terms and conditions. + +Several source codes may have its original copyright owner and/or +be licensed under other than Lesser GNU Public License , Version 2.1, say, MIT License. +Please, see copyright and license comments section in the header of each file, +and the LICENSE.MIT file for MIT License terms and conditions. + diff --git a/custom_chart/da_chart.c b/custom_chart/da_chart.c new file mode 100755 index 0000000..36c7def --- /dev/null +++ b/custom_chart/da_chart.c @@ -0,0 +1,592 @@ +/* + * DA probe + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Jaewon Lim + * Woojin Jung + * Juyoung Kim + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#include +#include // for signal +#include // for ualarm, sleep +#include // for timerfd +#include +#include // for errno +#include // for memset +#include // for uint64_t + +#include "daprobe.h" +#include "dahelper.h" +#include "probeinfo.h" +#define _USE_DA_ +#include "da_chart.h" + +#define ERR_THREAD_CREATE_FAIL -2001 // thread creation fail + +#define MAX_TITLE_LENGTH 16 +#define MAX_CHART_HANDLE 10 // cannot be exceeded 10 +#define MAX_SERIES_PER_CHART 4 // cannot be exceeded 10 +// chart handle is from 1 to 9 +// series handle is from 11 to 99 +// series handle 32 means that the series is 2nd series in 3rd chart. +// zero value handle means error + +// ===================================================================== +// global variable +// ===================================================================== + +typedef struct _chart_interval_callback +{ + da_handle chart_handle; + da_handle series_handle; + da_user_data_2_chart_data callback; + void* user_data; + struct _chart_interval_callback* next; +} chart_interval_callback; + +typedef struct +{ + int timerfd; + pthread_t thread_handle; + chart_interval_callback* callback_list; + pthread_mutex_t list_mutex; +} interval_manager; + +typedef struct +{ + int chart_handle_index; + int series_handle_index[MAX_CHART_HANDLE]; + int interval_for_series[MAX_CHART_HANDLE][MAX_SERIES_PER_CHART]; + interval_manager interval_10ms; + interval_manager interval_100ms; + interval_manager interval_1s; +} chart_handle_maintainer; + +chart_handle_maintainer chm; + +__thread pid_t cur_thread = -1; + + +// ===================================================================== +// internal macro definition +// ===================================================================== + +#define DECLARE_CHART_VARIABLE \ + da_handle __attribute__((unused)) ret = 0; \ + probeInfo_t probeInfo; \ + log_t log + +#define APPEND_LOG_CHART_RESULT(RESULT) \ + log.length += sprintf(log.data + log.length, "`,%d`,0x%p`,0`,2", \ + RESULT, CALLER_ADDRESS) + +#define APPEND_LOG_CHART(HANDLE, TYPE, TEXT, COLOR, VALUE) \ + log.length += sprintf(log.data + log.length, "`,`,%d`,%d`,%s`,%d`,%.3f", \ + HANDLE, TYPE, TEXT, COLOR, VALUE) + +// ===================================================================== +// timer thread routine for callback +// ===================================================================== + +void* _chart_timerThread(void* data) +{ + DECLARE_CHART_VARIABLE; + + uint64_t exp; + ssize_t readsize; + chart_interval_callback* cur; + float value; + sigset_t profsigmask; + interval_manager* pmanager = (interval_manager*)data; + + probeBlockStart(); + + sigemptyset(&profsigmask); + sigaddset(&profsigmask, SIGPROF); + pthread_sigmask(SIG_BLOCK, &profsigmask, NULL); + + while((readsize = read(pmanager->timerfd, &exp, sizeof(uint64_t))) > 0) + { + pthread_mutex_lock(&pmanager->list_mutex); + + cur = pmanager->callback_list; + while(cur != NULL) + { + value = cur->callback(cur->user_data); + + INIT_LOG; + setProbePoint(&probeInfo); + log.length = sprintf(log.data, "%d`,%d`,timerThread`,%lu`,%d`,%d`,`,`,0x%p`,0`,2`,`,%d`,0`,`,0`,%.3f", + LC_CUSTOM, probeInfo.eventIndex, probeInfo.currentTime, probeInfo.pID, + probeInfo.tID, CALLER_ADDRESS, cur->series_handle, value); + printLog(&log, MSG_LOG); + + cur = cur->next; + } + + pthread_mutex_unlock(&pmanager->list_mutex); + + sleep(0); + } + + probeBlockEnd(); + + return NULL; +} + +static int start_callback_thread(chart_interval interval) +{ + int* timerfd = NULL; + pthread_t* thread_handle = NULL; + interval_manager* pman = NULL; + struct itimerspec timevalue; + + if(interval == CHART_INTERVAL_10MSEC) + { + timerfd = &(chm.interval_10ms.timerfd); + thread_handle = &(chm.interval_10ms.thread_handle); + pman = &(chm.interval_10ms); + timevalue.it_value.tv_sec = 0; + timevalue.it_value.tv_nsec = 10000000L; + timevalue.it_interval.tv_sec = 0; + timevalue.it_interval.tv_nsec = 10000000L; + } + else if(interval == CHART_INTERVAL_100MSEC) + { + timerfd = &(chm.interval_100ms.timerfd); + thread_handle = &(chm.interval_100ms.thread_handle); + pman = &(chm.interval_100ms); + timevalue.it_value.tv_sec = 0; + timevalue.it_value.tv_nsec = 100000000L; + timevalue.it_interval.tv_sec = 0; + timevalue.it_interval.tv_nsec = 100000000L; + } + else if(interval == CHART_INTERVAL_1SEC) + { + timerfd = &(chm.interval_1s.timerfd); + thread_handle = &(chm.interval_1s.thread_handle); + pman = &(chm.interval_1s); + timevalue.it_value.tv_sec = 1; + timevalue.it_value.tv_nsec = 0; + timevalue.it_interval.tv_sec = 1; + timevalue.it_interval.tv_nsec = 0; + } + else + { + return ERR_WRONG_PARAMETER; + } + + if(*timerfd != -1 || *thread_handle != -1) + return 0; // already thread exist + + *timerfd = timerfd_create(CLOCK_REALTIME, 0); + if(*timerfd == -1) + return errno; + + if(timerfd_settime(*timerfd, 0, &timevalue, NULL) == -1) + return errno; + + if(pthread_create(thread_handle, NULL, _chart_timerThread, pman) < 0) + return ERR_THREAD_CREATE_FAIL; + + return 0; +} + + +// ===================================================================== +// internal utility function +// ===================================================================== + +static void add_to_callback_list(chart_interval interval, da_handle charthandle, da_handle series_handle, + da_user_data_2_chart_data callback, void* user_data) +{ + chart_interval_callback* newelem; + + newelem = (chart_interval_callback*)malloc(sizeof(chart_interval_callback)); + newelem->chart_handle = charthandle; + newelem->series_handle = series_handle; + newelem->callback = callback; + newelem->user_data = user_data; + + chm.interval_for_series[charthandle][series_handle % 10] = interval; + + switch(interval) + { + case CHART_INTERVAL_10MSEC: + pthread_mutex_lock(&chm.interval_10ms.list_mutex); + newelem->next = chm.interval_10ms.callback_list; + chm.interval_10ms.callback_list = newelem; + pthread_mutex_unlock(&chm.interval_10ms.list_mutex); + __sync_add_and_fetch(&(gTraceInfo.custom_chart_callback_count), 1); + break; + case CHART_INTERVAL_100MSEC: + pthread_mutex_lock(&chm.interval_100ms.list_mutex); + newelem->next = chm.interval_100ms.callback_list; + chm.interval_100ms.callback_list = newelem; + pthread_mutex_unlock(&chm.interval_100ms.list_mutex); + __sync_add_and_fetch(&(gTraceInfo.custom_chart_callback_count), 1); + break; + case CHART_INTERVAL_1SEC: + pthread_mutex_lock(&chm.interval_1s.list_mutex); + newelem->next = chm.interval_1s.callback_list; + chm.interval_1s.callback_list = newelem; + pthread_mutex_unlock(&chm.interval_1s.list_mutex); + __sync_add_and_fetch(&(gTraceInfo.custom_chart_callback_count), 1); + break; + default: + free(newelem); + break; + } +} + +static void remove_all_callback_list() +{ + chart_interval_callback* cur; + + pthread_mutex_lock(&chm.interval_10ms.list_mutex); + while(chm.interval_10ms.callback_list != NULL) + { + cur = chm.interval_10ms.callback_list; + chm.interval_10ms.callback_list = cur->next; + free(cur); + } + pthread_mutex_unlock(&chm.interval_10ms.list_mutex); + + pthread_mutex_lock(&chm.interval_100ms.list_mutex); + while(chm.interval_100ms.callback_list != NULL) + { + cur = chm.interval_100ms.callback_list; + chm.interval_100ms.callback_list = cur->next; + free(cur); + } + pthread_mutex_unlock(&chm.interval_100ms.list_mutex); + + pthread_mutex_lock(&chm.interval_1s.list_mutex); + while(chm.interval_1s.callback_list != NULL) + { + cur = chm.interval_1s.callback_list; + chm.interval_1s.callback_list = cur->next; + free(cur); + } + pthread_mutex_unlock(&chm.interval_1s.list_mutex); + + memset(&chm.interval_for_series, 0, sizeof(chm.interval_for_series)); + __sync_and_and_fetch(&(gTraceInfo.custom_chart_callback_count), 0); +} + +static void remove_from_callback_list(da_handle charthandle, da_handle series_handle) +{ + chart_interval_callback *prev, *cur; + chart_interval interval; + + interval = chm.interval_for_series[charthandle][series_handle % 10]; + chm.interval_for_series[charthandle][series_handle % 10] = 0; + + switch(interval) + { + case CHART_INTERVAL_10MSEC: + pthread_mutex_lock(&chm.interval_10ms.list_mutex); + + prev = NULL; + cur = chm.interval_10ms.callback_list; + while(cur != NULL) + { + if(cur->chart_handle == charthandle && cur->series_handle == series_handle) + { + if(prev) + prev->next = cur->next; + else + chm.interval_10ms.callback_list = cur->next; + + __sync_sub_and_fetch(&(gTraceInfo.custom_chart_callback_count), 1); + free(cur); + break; + } + + prev = cur; + cur = cur->next; + } + + pthread_mutex_unlock(&chm.interval_10ms.list_mutex); + break; + case CHART_INTERVAL_100MSEC: + pthread_mutex_lock(&chm.interval_100ms.list_mutex); + + prev = NULL; + cur = chm.interval_100ms.callback_list; + while(cur != NULL) + { + if(cur->chart_handle == charthandle && cur->series_handle == series_handle) + { + if(prev) + prev->next = cur->next; + else + chm.interval_100ms.callback_list = cur->next; + + __sync_sub_and_fetch(&(gTraceInfo.custom_chart_callback_count), 1); + free(cur); + break; + } + + prev = cur; + cur = cur->next; + } + + pthread_mutex_unlock(&chm.interval_100ms.list_mutex); + break; + case CHART_INTERVAL_1SEC: + pthread_mutex_lock(&chm.interval_1s.list_mutex); + + prev = NULL; + cur = chm.interval_1s.callback_list; + while(cur != NULL) + { + if(cur->chart_handle == charthandle && cur->series_handle == series_handle) + { + if(prev) + prev->next = cur->next; + else + chm.interval_1s.callback_list = cur->next; + + __sync_sub_and_fetch(&(gTraceInfo.custom_chart_callback_count), 1); + free(cur); + break; + } + + prev = cur; + cur = cur->next; + } + + pthread_mutex_unlock(&chm.interval_1s.list_mutex); + break; + default: + break; + } +} + + +// ===================================================================== +// constructor and destructor functions +// ===================================================================== + +void __attribute__((constructor)) _init_lib() +{ + probeBlockStart(); + + memset(&chm, 0, sizeof(chm)); + chm.interval_10ms.timerfd = -1; + chm.interval_100ms.timerfd = -1; + chm.interval_1s.timerfd = -1; + chm.interval_10ms.thread_handle = -1; + chm.interval_100ms.thread_handle = -1; + chm.interval_1s.thread_handle = -1; + pthread_mutex_init(&chm.interval_10ms.list_mutex, NULL); + pthread_mutex_init(&chm.interval_100ms.list_mutex, NULL); + pthread_mutex_init(&chm.interval_1s.list_mutex, NULL); + + probeBlockEnd(); +} + +void __attribute__((destructor)) _fini_lib() +{ + probeBlockStart(); + + remove_all_callback_list(); + if(chm.interval_10ms.timerfd != -1) + close(chm.interval_10ms.timerfd); + if(chm.interval_100ms.timerfd != -1) + close(chm.interval_100ms.timerfd); + if(chm.interval_1s.timerfd != -1) + close(chm.interval_1s.timerfd); + + if(chm.interval_10ms.thread_handle != -1) + { + pthread_join(chm.interval_10ms.thread_handle, NULL); + } + if(chm.interval_100ms.thread_handle != -1) + { + pthread_join(chm.interval_100ms.thread_handle, NULL); + } + if(chm.interval_1s.thread_handle != -1) + { + pthread_join(chm.interval_1s.thread_handle, NULL); + } + + probeBlockEnd(); +} + + +// ===================================================================== +// api definition +// ===================================================================== + +void da_mark(chart_color color, char* mark_text) +{ + DECLARE_CHART_VARIABLE; + + probeBlockStart(); + + INIT_LOG; + setProbePoint(&probeInfo); + APPEND_LOG_BASIC(LC_CUSTOM); + APPEND_LOG_INPUT("%s", ""); + APPEND_LOG_CHART_RESULT(0); + APPEND_LOG_CHART(0, 0, mark_text, color, 0.0f); + printLog(&log, MSG_LOG); + + probeBlockEnd(); +} + +da_handle da_create_chart(char* chart_name) +{ + DECLARE_CHART_VARIABLE; + + // check if there is available chart handle slot + if(chm.chart_handle_index + 1 >= MAX_CHART_HANDLE) + return ERR_MAX_CHART_NUMBER; + + // check if chart_name is null + if(chart_name == NULL) + return ERR_WRONG_PARAMETER; + + probeBlockStart(); + ret = ++(chm.chart_handle_index); + + INIT_LOG; + setProbePoint(&probeInfo); + APPEND_LOG_BASIC(LC_CUSTOM); + APPEND_LOG_INPUT("%s", ""); + APPEND_LOG_CHART_RESULT(ret); + APPEND_LOG_CHART(0, 0, chart_name, 0, 0.0f); + printLog(&log, MSG_LOG); + + probeBlockEnd(); + + return ret; +} + +da_handle da_create_series(da_handle charthandle, char* seriesname, + series_type type, chart_color color) +{ + DECLARE_CHART_VARIABLE; + + // check if charthandle is valid handle or not + if(charthandle <= 0 || charthandle > chm.chart_handle_index) + return ERR_WRONG_HANDLE; + + // chech if extra parameter is valid + if(seriesname == NULL) + return ERR_WRONG_PARAMETER; + + // check if there is available series spot + if(chm.series_handle_index[(int)charthandle] + 1 >= MAX_SERIES_PER_CHART) + return ERR_MAX_CHART_NUMBER; + + probeBlockStart(); + ret = ++(chm.series_handle_index[charthandle]); + ret += (10 * charthandle); + + INIT_LOG; + setProbePoint(&probeInfo); + APPEND_LOG_BASIC(LC_CUSTOM); + APPEND_LOG_INPUT("%s", ""); + APPEND_LOG_CHART_RESULT(ret); + APPEND_LOG_CHART(charthandle, type, seriesname, color, 0.0f); + printLog(&log, MSG_LOG); + + probeBlockEnd(); + + return ret; +} + +da_handle da_create_default_series(da_handle charthandle, char* seriesname) +{ + return da_create_series(charthandle, seriesname, + CHART_TYPE_AUTO, CHART_COLOR_AUTO); +} + +int da_set_callback(da_handle series_handle, da_user_data_2_chart_data callback, + void* data_addr, chart_interval interval) +{ + int cindex, sindex; + cindex = (int)(series_handle / 10); + sindex = series_handle % 10; + + // check series handle + if(cindex <= 0 || cindex > chm.chart_handle_index) + return ERR_WRONG_HANDLE; + + if(sindex > chm.series_handle_index[(int)cindex]) + return ERR_WRONG_HANDLE; + + // check rest parameters + if(interval == CHART_NO_CYCLE && callback != NULL) + return ERR_WRONG_PARAMETER; + + probeBlockStart(); + + // remove previously registered callback + remove_from_callback_list(cindex, series_handle); + + // register new callback + if(callback != NULL) + { + int re; + add_to_callback_list(interval, cindex, series_handle, callback, data_addr); + re = start_callback_thread(interval); + LOG("start callback thread return %d\n", re); + } + probeBlockEnd(); + + return 0; +} + +void da_log(da_handle series_handle, float uservalue) +{ + DECLARE_CHART_VARIABLE; + + // chech if series handle is valid + int cindex, sindex; + cindex = (int)(series_handle / 10); + sindex = series_handle % 10; + + if(cindex <= 0 || cindex > chm.chart_handle_index) + return; + + if(sindex > chm.series_handle_index[(int)cindex]) + return; + + probeBlockStart(); + + INIT_LOG; + setProbePoint(&probeInfo); + APPEND_LOG_BASIC(LC_CUSTOM); + APPEND_LOG_INPUT("%s", ""); + APPEND_LOG_CHART_RESULT(0); + APPEND_LOG_CHART(series_handle, 0, "", 0, uservalue); + printLog(&log, MSG_LOG); + + probeBlockEnd(); +} diff --git a/custom_chart/da_chart.h b/custom_chart/da_chart.h new file mode 100755 index 0000000..8f0e9a7 --- /dev/null +++ b/custom_chart/da_chart.h @@ -0,0 +1,110 @@ +/* + * DA probe + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Jaewon Lim + * Woojin Jung + * Juyoung Kim + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#ifndef __DA_CHART_H__ +#define __DA_CHART_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +// Error code +#define ERR_MAX_CHART_NUMBER -1001 // no more chart or series can be added +#define ERR_WRONG_HANDLE -1002 // chart or series handle is wrong handle +#define ERR_WRONG_PARAMETER -1003 // wrong parameter + +typedef enum +{ + CHART_TYPE_AUTO = 0, + CHART_TYPE_LINE = 1, + CHART_TYPE_BAR = 2, + CHART_TYPE_AREA = 3, + CHART_TYPE_STEP = 4 +} series_type; + +typedef enum +{ + CHART_COLOR_AUTO = 0, + CHART_COLOR_BLUE = 1, + CHART_COLOR_GREEN = 2, + CHART_COLOR_RED = 3, + CHART_COLOR_BROWN = 4, + CHART_COLOR_PURPLE = 5, + CHART_COLOR_NAVY = 6, + CHART_COLOR_CHOCOLATE = 7, + CHART_COLOR_INDIGO = 8, + CHART_COLOR_MAGENTA = 9, + CHART_COLOR_TEAL = 10 +} chart_color; + +typedef enum +{ + CHART_NO_CYCLE = 0, + CHART_INTERVAL_10MSEC = 1, + CHART_INTERVAL_100MSEC = 2, + CHART_INTERVAL_1SEC = 3 +} chart_interval; + +typedef int da_handle; +typedef float (* da_user_data_2_chart_data) (void* data_addr); + + +// api definition +#ifdef _USE_DA_ + +extern da_handle da_create_chart (char* chart_name); +extern da_handle da_create_series (da_handle charthandle, char* seriesname, + series_type type, chart_color color); +extern da_handle da_create_default_series (da_handle charthandle, char* seriesname); +extern int da_set_callback (da_handle series_handle, da_user_data_2_chart_data callback, + void* data_addr, chart_interval interval); +extern void da_log (da_handle series_handle, float uservalue); + + +extern void da_mark (chart_color color, char* mark_text); + +#else // _USE_DA_ (do not use da custom chart) + +#define da_create_chart(a) 0 +#define da_create_series(a, b, c, d) 0 +#define da_create_default_series(a, b) 0 +#define da_set_callback(a, b, c, d) 0 +#define da_log(a, b) + + +#define da_mark(color, text) + +#endif // _USE_DA_ + +#ifdef __cplusplus +} +#endif + +#endif // __DA_CHART_H__ diff --git a/custom_chart/da_chart_dummy.c b/custom_chart/da_chart_dummy.c new file mode 100755 index 0000000..79796d0 --- /dev/null +++ b/custom_chart/da_chart_dummy.c @@ -0,0 +1,65 @@ +/* + * DA probe + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Jaewon Lim + * Woojin Jung + * Juyoung Kim + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#define _USE_DA_ +#include "da_chart.h" + +// ===================================================================== +// api definition +// ===================================================================== + +void da_mark(chart_color color, char* mark_text) +{ +} + +da_handle da_create_chart(char* chart_name) +{ + return 0; +} + +da_handle da_create_series(da_handle charthandle, char* seriesname, + series_type type, chart_color color) +{ + return 0; +} + +da_handle da_create_default_series(da_handle charthandle, char* seriesname) +{ + return 0; +} + +int da_set_callback(da_handle series_handle, da_user_data_2_chart_data callback, void* data_addr, chart_interval interval) +{ + return 0; +} + +void da_log(da_handle series_handle, float uservalue) +{ +} diff --git a/dynamic-analysis-probe.manifest b/dynamic-analysis-probe.manifest new file mode 100644 index 0000000..86dbb26 --- /dev/null +++ b/dynamic-analysis-probe.manifest @@ -0,0 +1,5 @@ + + + + + diff --git a/helper/addr-capi.c b/helper/addr-capi.c new file mode 100644 index 0000000..4a3cd68 --- /dev/null +++ b/helper/addr-capi.c @@ -0,0 +1,58 @@ +/* + * DA probe + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Jaewon Lim + * Woojin Jung + * Juyoung Kim + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#include +#include "daprobe.h" +#include "dahelper.h" + +int get_map_address(void* sym, void** start, void** end); + +int getExecutableMappingAddress() +{ + int ret = 0; + void* main_symbol; + + probeBlockStart(); + main_symbol = dlsym(RTLD_NEXT, "main"); + if(main_symbol != NULL) + { + ret = get_map_address(main_symbol, &(gTraceInfo.exec_map.map_start), + &(gTraceInfo.exec_map.map_end)); + } + else + { + PRINTMSG("failed to get address of main"); + ret = 0; + } + probeBlockEnd(); + + return ret; +} + diff --git a/helper/addr-tizen.c b/helper/addr-tizen.c new file mode 100644 index 0000000..d1fc550 --- /dev/null +++ b/helper/addr-tizen.c @@ -0,0 +1,58 @@ +/* + * DA probe + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Jaewon Lim + * Woojin Jung + * Juyoung Kim + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#include +#include "daprobe.h" +#include "dahelper.h" + +int get_map_address(void* sym, void** start, void** end); + +int getExecutableMappingAddress() +{ + int ret = 0; + void* main_symbol; + + probeBlockStart(); + main_symbol = dlsym(RTLD_NEXT, "OspMain"); + if(main_symbol != NULL) + { + ret = get_map_address(main_symbol, &(gTraceInfo.exec_map.map_start), + &(gTraceInfo.exec_map.map_end)); + } + else + { + PRINTMSG("failed to get address of OspMain\n"); + ret = 0; + } + probeBlockEnd(); + + return ret; +} + diff --git a/helper/appfw-capi.c b/helper/appfw-capi.c new file mode 100644 index 0000000..7d52abb --- /dev/null +++ b/helper/appfw-capi.c @@ -0,0 +1,37 @@ +/* + * DA probe + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Jaewon Lim + * Woojin Jung + * Juyoung Kim + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#include + +void application_exit() +{ + app_efl_exit(); +} + diff --git a/helper/appfw-tizen.cpp b/helper/appfw-tizen.cpp new file mode 100644 index 0000000..9dc578c --- /dev/null +++ b/helper/appfw-tizen.cpp @@ -0,0 +1,60 @@ +/* + * DA probe + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Jaewon Lim + * Woojin Jung + * Juyoung Kim + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#include +#include +using namespace Tizen::App; + +#define UNKNOWN_USER_EVENT 5873 + +#ifdef __cplusplus +extern "C"{ +#endif + +void application_exit() +{ + App* self = App::GetInstance(); + if(self != NULL) + { + self->Terminate(); + // send unknown user event to main thread + // because this cause that main thread execute terminating routine without block + self->SendUserEvent(UNKNOWN_USER_EVENT, NULL); + } + else + { + app_efl_exit(); + } +} + +#ifdef __cplusplus +} +#endif + diff --git a/helper/btsym.c b/helper/btsym.c new file mode 100755 index 0000000..b6ea739 --- /dev/null +++ b/helper/btsym.c @@ -0,0 +1,481 @@ +/* Return list with names for address in backtrace. + Copyright (C) 1998,1999,2000,2001,2003,2009 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper , 1998. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + + +/* +2011-12-15 Jaewon Lim add hashing for symbols + +2011-12-08 Jaewon Lim get symbol data from binary's symtab when dladdr cannot resolve symbol +*/ + +#include // for assert +#include // for printf, sprintf +#include // for malloc +#include // for strlen +#include // for ptrdiff_t +#include // for program_invocation_name + +#include // for open, fstat +#include // for open, fstat +#include // for open +#include // for fstat +#include // for mmap, munmap + +#include "private_link.h" // for link_map, ElfW +#include "dahelper.h" +#include "dacollection.h" + +#if __ELF_NATIVE_CLASS == 32 +# define WORD_WIDTH 8 +#else +/* We assyme 64bits. */ +# define WORD_WIDTH 16 +#endif + +#define FILEPATH_MAX 1024 + +/* We use this macro to refer to ELF types independent of the native wordsize. + 'ElfW(TYPE)' is used in place of 'Elf32_TYPE' or 'Elf64_TYPE'. */ +#define ELFW(type) _ElfW (ELF, __ELF_NATIVE_CLASS, type) + +/* Result of the lookup functions and how to retrieve the base address. */ +typedef struct link_map *lookup_t; +#define LOOKUP_VALUE(map) map +#define LOOKUP_VALUE_ADDRESS(map) ((map) ? (map)->l_addr : 0) + +/* On some architectures a pointer to a function is not just a pointer + to the actual code of the function but rather an architecture + specific descriptor. */ +#ifndef ELF_FUNCTION_PTR_IS_SPECIAL +# define DL_SYMBOL_ADDRESS(map, ref) \ + (void *) (LOOKUP_VALUE_ADDRESS (map) + ref->st_value) +# define DL_LOOKUP_ADDRESS(addr) ((ElfW(Addr)) (addr)) +# define DL_DT_INIT_ADDRESS(map, start) (start) +# define DL_DT_FINI_ADDRESS(map, start) (start) +#endif + +/* On some architectures dladdr can't use st_size of all symbols this way. */ +#define DL_ADDR_SYM_MATCH(L, SYM, ADDR) \ + (((ADDR) >= (L)->l_addr + (SYM)->st_value) \ + && ((((SYM)->st_shndx == SHN_UNDEF || (SYM)->st_size == 0) \ + && ((ADDR) == (L)->l_addr + (SYM)->st_value)) \ + || ((ADDR) < (L)->l_addr + (SYM)->st_value + (SYM)->st_size))) + +// start of implementation by Jaewon Lim +struct _symdata +{ + ElfW(Shdr) symhdr; + ElfW(Shdr) strhdr; + ElfW(Sym)* symtab; + char* strtab; +}; + +typedef struct _symdata symdata_t; + +// get symbol data from file binary +static symdata_t* _get_symboldata(char* filepath) +{ + int fd; + struct stat st; + char *contents; + symdata_t* pdata; + + // first find in glist + pdata = (symdata_t*)find_glist(filepath); + if(pdata != NULL) + { + return pdata; + } + + fd = open(filepath, O_RDONLY | O_CLOEXEC); + if(fd == -1) + { + return pdata; + } + + if(fstat(fd, &st) == -1) + { + close(fd); + return pdata; + } + + contents = (char*)mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0); + if(likely(contents != NULL)) + { + ElfW(Ehdr) * elf_hdr = (ElfW(Ehdr) *)(contents); + ElfW(Shdr) * sec_hdr = (ElfW(Shdr) *)(contents + elf_hdr->e_shoff); + int i, symtab_idx = -1; + + for (i = 0; i < elf_hdr->e_shnum; ++i) + { + if(unlikely(sec_hdr[i].sh_type == SHT_SYMTAB)) + { + symtab_idx = i; + break; + } + } + + if(symtab_idx != -1) //there is symbol table + { + int strtab_idx = sec_hdr[symtab_idx].sh_link; + if(likely((strtab_idx != 0) && (sec_hdr[strtab_idx].sh_type == SHT_STRTAB))) // associated string table is valid + { + pdata = (symdata_t*)malloc(sizeof(symdata_t) + + sec_hdr[symtab_idx].sh_size + + sec_hdr[strtab_idx].sh_size); + + if(likely(pdata != NULL)) + { + memcpy(&(pdata->symhdr), &(sec_hdr[symtab_idx]), sizeof(ElfW(Shdr))); + memcpy(&(pdata->strhdr), &(sec_hdr[strtab_idx]), sizeof(ElfW(Shdr))); + pdata->symtab = (ElfW(Sym) *)(pdata + 1); + pdata->strtab = ((char*)pdata) + sizeof(symdata_t) + sec_hdr[symtab_idx].sh_size; + memcpy((void*)(pdata->symtab), (void*)(contents + sec_hdr[symtab_idx].sh_offset), sec_hdr[symtab_idx].sh_size); + memcpy((void*)(pdata->strtab), (void*)(contents + sec_hdr[strtab_idx].sh_offset), sec_hdr[strtab_idx].sh_size); + + if(add_to_glist(filepath, (void*)pdata) == 0) // fail to add + { + free(pdata); + pdata = NULL; + } + } + } + } + + munmap((void*)contents, st.st_size); + } + + close(fd); + + return pdata; +} + +int get_map_address(void* symbol, void** map_start, void** map_end) +{ + Dl_info info; + int status, ret = 0; + struct link_map* map = NULL; + + status = dladdr1(symbol, &info, (void**)&map, RTLD_DL_LINKMAP); + if(status && map != NULL) + { + *map_start = (void*)(map->l_map_start); + *map_end = (void*)(map->l_map_end); + ret = 1; + } + else + ret = 0; + + return ret; +} + +// end of implementation by Jaewon Lim + +char** cached_backtrace_symbols (void* const* array, int size) +{ + Dl_info info[MAX_STACK_DEPTH]; + int status[MAX_STACK_DEPTH]; + char* chararr[MAX_STACK_DEPTH]; + int cnt; + size_t total = 0; + char **result; + char* foundsym; + + memset(chararr, 0, MAX_STACK_DEPTH * sizeof(char*)); + + /* Fill in the information we can get from `dladdr'. */ + for (cnt = 0; cnt < size; ++cnt) + { + struct link_map* map; + + if(find_symbol_hash(array[cnt], &foundsym) <= 0) // not found or error + { + status[cnt] = dladdr1 (array[cnt], &info[cnt], (void**)&map, RTLD_DL_LINKMAP); + if (status[cnt] && info[cnt].dli_fname && info[cnt].dli_fname[0] != '\0') + { + /* We have some info, compute the length of the string which will be + "(+offset) [address]. */ + total += (strlen (info[cnt].dli_fname ?: "") + + strlen (info[cnt].dli_sname ?: "") + + 3 + WORD_WIDTH + 3 + WORD_WIDTH + 5); + + /* The load bias is more useful to the user than the load + address. The use of these addresses is to calculate an + address in the ELF file, so its prelinked bias is not + something we want to subtract out. */ + info[cnt].dli_fbase = (void *) map->l_addr; + } + else + total += 5 + WORD_WIDTH; + } + else // there is a entry for key + { + status[cnt] = 0; + chararr[cnt] = foundsym; + if(chararr[cnt] != NULL) + total += (strlen(chararr[cnt]) + 1); + else + { + // this never happened + total += 100; + } + } + } + + /* Allocate memory for the result. */ + result = (char **) malloc (size * sizeof (char *) + total); + if (result != NULL) + { + char *last = (char *) (result + size); + + for (cnt = 0; cnt < size; ++cnt) + { + result[cnt] = last; + + if(chararr[cnt] != NULL) // there is a cache + { + last += (1 + sprintf(last, "%s", chararr[cnt])); + } + else // there is no cache + { + int tstrlen; + if (status[cnt] && info[cnt].dli_fname != NULL && info[cnt].dli_fname[0] != '\0') + { + // We found no symbol name to use, so describe it as relative to the file. + if (info[cnt].dli_sname == NULL) + info[cnt].dli_saddr = info[cnt].dli_fbase; + + if (info[cnt].dli_sname == NULL && info[cnt].dli_saddr == 0) + { + tstrlen = sprintf (last, "%s(%s) [%p]", info[cnt].dli_fname ?: "", info[cnt].dli_sname ?: "", array[cnt]); + } + else + { + char sign; + ptrdiff_t offset; + if (array[cnt] >= (void *) info[cnt].dli_saddr) + { + sign = '+'; + offset = array[cnt] - info[cnt].dli_saddr; + } + else + { + sign = '-'; + offset = info[cnt].dli_saddr - array[cnt]; + } + + tstrlen = sprintf (last, "%s(%s%c%#tx) [%p]", + info[cnt].dli_fname ?: "", + info[cnt].dli_sname ?: "", + sign, offset, array[cnt]); + } + } + else + { + tstrlen = sprintf (last, "[%p]", array[cnt]); + } + tstrlen++; + + add_symbol_hash(array[cnt], last, tstrlen); + + last += tstrlen; + } + } + + assert (last <= (char *) result + size * sizeof (char *) + total); + } + else // fail to malloc + { + // do nothing + } + + return result; +} + +char** da_backtrace_symbols (void* const* array, int size) +{ + Dl_info info[MAX_STACK_DEPTH]; + int status[MAX_STACK_DEPTH]; + char* chararr[MAX_STACK_DEPTH]; + int cnt; + size_t total = 0; + char **result; + char* foundsym; + + memset(chararr, 0, MAX_STACK_DEPTH * sizeof(char*)); + + /* Fill in the information we can get from `dladdr'. */ + for (cnt = 0; cnt < size; ++cnt) + { + struct link_map* map; + + if(find_symbol_hash(array[cnt], &foundsym) <= 0) // not found or error + { + status[cnt] = dladdr1 (array[cnt], &info[cnt], (void**)&map, RTLD_DL_LINKMAP); + if(info[cnt].dli_sname == NULL) + { + char filepath[FILEPATH_MAX]; // for file path + + /* If this is the main program the information is incomplete. */ + if (map->l_name[0] == '\0' && map->l_type == lt_executable) + { + strcpy(filepath, program_invocation_name); + } + else + { + int len; + if(map->l_origin) + { + strcpy(filepath, map->l_origin); + len = strlen(filepath); + if(len > 0 && filepath[len-1] != '/') + { + filepath[len] = '/'; + filepath[len+1] = '\0'; + } + } + else + filepath[0] = '\0'; + strcat(filepath, map->l_name); + } + + symdata_t* pdata = _get_symboldata(filepath); + if(pdata != NULL) + { + ElfW(Sym) * sym_ent = pdata->symtab; + char* strtab = pdata->strtab; + int i, num_syms = pdata->symhdr.sh_size / pdata->symhdr.sh_entsize; + + for(i = 0; i < num_syms; ++i) + { + if (ELFW(ST_TYPE) (sym_ent[i].st_info) != STT_TLS + && (sym_ent[i].st_shndx != SHN_UNDEF || sym_ent[i].st_value != 0) + && DL_ADDR_SYM_MATCH (map, &(sym_ent[i]), DL_LOOKUP_ADDRESS (array[cnt])) + && sym_ent[i].st_name < pdata->strhdr.sh_size) + { + // We found a symbol close by. Fill in its name and exact address. + info[cnt].dli_sname = strtab + ((ElfW(Sym) *)(sym_ent + i))->st_name; + info[cnt].dli_saddr = DL_SYMBOL_ADDRESS (map, ((ElfW(Sym) *)(sym_ent + i))); + break; + } + } + } + } + + if (status[cnt] && info[cnt].dli_fname && info[cnt].dli_fname[0] != '\0') + { + /* We have some info, compute the length of the string which will be + "(+offset) [address]. */ + total += (strlen (info[cnt].dli_fname ?: "") + + strlen (info[cnt].dli_sname ?: "") + + 3 + WORD_WIDTH + 3 + WORD_WIDTH + 5); + + /* The load bias is more useful to the user than the load + address. The use of these addresses is to calculate an + address in the ELF file, so its prelinked bias is not + something we want to subtract out. */ +// info[cnt].dli_fbase = (void *) map->l_addr; + } + else + total += 5 + WORD_WIDTH; + } + else // there is a entry for key + { + chararr[cnt] = foundsym; + if(chararr[cnt] != NULL) + total += (strlen(chararr[cnt]) + 1); + else + { + assert(false); + total += 100; + } + } + } + + /* Allocate memory for the result. */ + result = (char **) malloc (size * sizeof (char *) + total); + if (result != NULL) + { + char *last = (char *) (result + size); + + for (cnt = 0; cnt < size; ++cnt) + { + result[cnt] = last; + + if(chararr[cnt] != NULL) // there is a cache + { + last += (1 + sprintf(last, "%s", chararr[cnt])); + } + else // there is no cache + { + int tstrlen; + if (status[cnt] && info[cnt].dli_fname != NULL && info[cnt].dli_fname[0] != '\0') + { + // We found no symbol name to use, so describe it as relative to the file. + if (info[cnt].dli_sname == NULL) + info[cnt].dli_saddr = info[cnt].dli_fbase; + + if (info[cnt].dli_sname == NULL && info[cnt].dli_saddr == 0) + { + tstrlen = sprintf (last, "%s(%s) [%p]", info[cnt].dli_fname ?: "", info[cnt].dli_sname ?: "", array[cnt]); + } + else + { + char sign; + ptrdiff_t offset; + if (array[cnt] >= (void *) info[cnt].dli_saddr) + { + sign = '+'; + offset = array[cnt] - info[cnt].dli_saddr; + } + else + { + sign = '-'; + offset = info[cnt].dli_saddr - array[cnt]; + } + + tstrlen = sprintf (last, "%s(%s%c%#tx) [%p]", + info[cnt].dli_fname ?: "", + info[cnt].dli_sname ?: "", + sign, offset, array[cnt]); + } + } + else + { + tstrlen = sprintf (last, "[%p]", array[cnt]); + } + tstrlen++; + + add_symbol_hash(array[cnt], last, tstrlen); + + last += tstrlen; + } + } + + assert (last <= (char *) result + size * sizeof (char *) + total); + } + else // fail to malloc + { + // do nothing + } + + return result; +} + diff --git a/helper/dacapture.c b/helper/dacapture.c new file mode 100755 index 0000000..475b644 --- /dev/null +++ b/helper/dacapture.c @@ -0,0 +1,437 @@ +/* + * DA probe + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Jaewon Lim + * Woojin Jung + * Juyoung Kim + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Contributors: + * - S-Core Co., Ltd + * + */ +/* + * We refer to the Evas example source code with BSD + * (Evas/src/examples/evas-buffer-simple.c) + * + */ + +#include // for system +#include // for stat, getpid +#include // fot stat, chmod +#include // fot stat, getpid +#include // for shmget, shmat + +#include +#include +#include + +#include +#include +#include + +#include "daprobe.h" +#include "dahelper.h" + +#define SCREENSHOT_DIRECTORY "/tmp/da" + +#define MAX_HEIGHT 720 +#define CAPTURE_TIMEOUT 2.0 + +typedef struct _screenshot_data +{ + XImage* ximage; + Display* dpy; + XShmSegmentInfo x_shm_info; +} screenshot_data; + +/* +int convert_image( void* srcbuf, void* dstbuf, + pixman_format_code_t src_format, + pixman_format_code_t dst_format, + int src_width, int src_height, + int dst_width, int dst_height, + int rotate) +{ + pixman_image_t * src_img; + pixman_image_t * dst_img; + pixman_transform_t transform; + + int src_stride, dst_stride; + int src_bpp; + int dst_bpp; + pixman_op_t op; + int rotate_step; + int ret = False; + + return_val_if_fail (srcbuf != NULL, False); + return_val_if_fail (dstbuf != NULL, False); + return_val_if_fail (rotate <= 360 && rotate >= -360, False); + + op = PIXMAN_OP_SRC; + + src_bpp = PIXMAN_FORMAT_BPP (src_format) / 8; + return_val_if_fail (src_bpp > 0, False); + + dst_bpp = PIXMAN_FORMAT_BPP (dst_format) / 8; + return_val_if_fail (dst_bpp > 0, False); + + rotate_step = (rotate + 360) / 90 % 4; + + src_stride = src_width * src_bpp; + dst_stride = dst_width * dst_bpp; + + src_img = pixman_image_create_bits (src_format, src_width, src_height, srcbuf, src_stride); + dst_img = pixman_image_create_bits (dst_format, dst_width, dst_height, dstbuf, dst_stride); + + goto_if_fail (src_img != NULL, CANT_CONVERT); + goto_if_fail (dst_img != NULL, CANT_CONVERT); + + pixman_transform_init_identity (&transform); + + if (rotate_step > 0) + { + int c, s, tx = 0, ty = 0; + switch (rotate_step) + { + case 1: + // 270 degrees + c = 0; + s = -pixman_fixed_1; + ty = pixman_int_to_fixed (dst_width); + break; + case 2: + // 180 degrees + c = -pixman_fixed_1; + s = 0; + tx = pixman_int_to_fixed (dst_width); + ty = pixman_int_to_fixed (dst_height); + break; + case 3: + // 90 degrees + c = 0; + s = pixman_fixed_1; + tx = pixman_int_to_fixed (dst_height); + break; + default: + // 0 degrees + c = 0; + s = 0; + break; + } + pixman_transform_rotate (&transform, NULL, c, s); + pixman_transform_translate (&transform, NULL, tx, ty); + } + + pixman_image_set_transform (src_img, &transform); + + pixman_image_composite (op, src_img, NULL, dst_img, + 0, 0, 0, 0, 0, 0, dst_width, dst_height); + + ret = True; + +CANT_CONVERT: + if (src_img) + pixman_image_unref (src_img); + if (dst_img) + pixman_image_unref (dst_img); + + return ret; +} +*/ + +static char* captureScreenShotX(int* pwidth, int* pheight, screenshot_data* sdata) +{ + Window root; +// Atom atom_rotation; + + sdata->dpy = XOpenDisplay(NULL); + if(unlikely(sdata->dpy == NULL)) + { + PRINTMSG("XOpenDisplay failed!\n"); + return NULL; + } + + *pwidth = DisplayWidth(sdata->dpy, DefaultScreen(sdata->dpy)); + *pheight = DisplayHeight(sdata->dpy, DefaultScreen(sdata->dpy)); + + root = RootWindow(sdata->dpy, DefaultScreen(sdata->dpy)); + + sdata->ximage = XShmCreateImage(sdata->dpy, DefaultVisualOfScreen (DefaultScreenOfDisplay (sdata->dpy)), 24, + ZPixmap, NULL, &sdata->x_shm_info, (unsigned int)*pwidth, (unsigned int)*pheight); + + if(sdata->ximage != NULL) + { + sdata->x_shm_info.shmid = shmget(IPC_PRIVATE, sdata->ximage->bytes_per_line * sdata->ximage->height, IPC_CREAT | 0777); + sdata->x_shm_info.shmaddr = sdata->ximage->data = shmat(sdata->x_shm_info.shmid, 0, 0); + sdata->x_shm_info.readOnly = False; + + if(XShmAttach(sdata->dpy, &sdata->x_shm_info)) + { + if(XShmGetImage(sdata->dpy, root, sdata->ximage, 0, 0, AllPlanes)) + { + XSync (sdata->dpy, False); + return sdata->ximage->data; + } + else + { + PRINTMSG("XShmGetImage failed !\n"); + } + + XShmDetach (sdata->dpy, &sdata->x_shm_info); + } + else + { + PRINTMSG("XShmAttach failed !\n"); + } + + shmdt (sdata->x_shm_info.shmaddr); + shmctl (sdata->x_shm_info.shmid, IPC_RMID, NULL); + XDestroyImage(sdata->ximage); + sdata->ximage = NULL; + } + else + { + PRINTMSG("XShmCreateImage failed!\n"); + } + + return NULL; +} + +static void releaseScreenShotX(screenshot_data* sdata) +{ + if(sdata->ximage) + { + XShmDetach (sdata->dpy, &sdata->x_shm_info); + shmdt (sdata->x_shm_info.shmaddr); + shmctl (sdata->x_shm_info.shmid, IPC_RMID, NULL); + XDestroyImage(sdata->ximage); + } + else { } + + if(sdata->dpy) + { + XCloseDisplay(sdata->dpy); + } +} + +static Evas* create_canvas(int width, int height) +{ + Evas* canvas; + Evas_Engine_Info_Buffer* einfo; + int method; + void* pixels; + + method = evas_render_method_lookup("buffer"); + if(unlikely(method <= 0)) + { + PRINTMSG("ERROR: evas was not compiled with 'buffer' engine!\n"); + return NULL; + } + + canvas = evas_new(); + if(unlikely(canvas == NULL)) + { + PRINTMSG("ERROR: could not instantiate new evas canvas.\n"); + return NULL; + } + + evas_output_method_set(canvas, method); + evas_output_size_set(canvas, width, height); + evas_output_viewport_set(canvas, 0, 0, width, height); + + einfo = (Evas_Engine_Info_Buffer*)evas_engine_info_get(canvas); + if(unlikely(einfo == NULL)) + { + PRINTMSG("ERROR: could not get evas engine info!\n"); + evas_free(canvas); + return NULL; + } + + // ARGB32 is sizeof(int), that is 4 bytes, per pixel + pixels = malloc(width * height * sizeof(int)); + if(unlikely(pixels == NULL)) + { + PRINTMSG("ERROR: could not allocate canvas pixels!\n"); + evas_free(canvas); + return NULL; + } + + einfo->info.depth_type = EVAS_ENGINE_BUFFER_DEPTH_ARGB32; + einfo->info.dest_buffer = pixels; + einfo->info.dest_buffer_row_bytes = width * sizeof(int); + einfo->info.use_color_key = 0; + einfo->info.alpha_threshold = 0; + einfo->info.func.new_update_region = NULL; + einfo->info.func.free_update_region = NULL; + if(unlikely(evas_engine_info_set(canvas, (Evas_Engine_Info*)einfo) == EINA_FALSE)) + { + PRINTMSG("ERROR: could not set evas engine info!\n"); + evas_free(canvas); + return NULL; + } + + return canvas; +} + +static void destroy_canvas(Evas* canvas) +{ + Evas_Engine_Info_Buffer* einfo; + + einfo = (Evas_Engine_Info_Buffer*)evas_engine_info_get(canvas); + if(unlikely(einfo == NULL)) + { + PRINTMSG("ERROR: could not get evas engine info!\n"); + } + else + { + free(einfo->info.dest_buffer); + } + evas_free(canvas); +} + +int captureScreen() +{ + char dstpath[32]; + char* scrimage; + int width, height; + Evas* ev = NULL; + Evas_Object* img; + screenshot_data sdata; + DECLARE_COMMON_VARIABLE; + int ret = 0; + + probeBlockStart(); + + setProbePoint(&probeInfo); + sdata.ximage = NULL; + scrimage = captureScreenShotX(&width, &height, &sdata); + if(scrimage != NULL) + { + ev = create_canvas(width, height); + if(likely(ev != NULL)) + { + sprintf(dstpath, SCREENSHOT_DIRECTORY "/%d_%d.png", getpid(), probeInfo.eventIndex); + + // make image buffer + if((img = evas_object_image_add(ev)) != NULL) + { + //image buffer set + evas_object_image_data_set(img, NULL); + evas_object_image_size_set(img, width, height); + evas_object_image_data_set(img, scrimage); + + // resize image + if(height > MAX_HEIGHT) + { + width = width * MAX_HEIGHT / height; + height = MAX_HEIGHT; + evas_object_resize(img, width, height); + evas_object_image_fill_set(img, 0, 0, width, height); + } + evas_object_image_data_update_add(img, 0, 0, width, height); + + //save file + if(evas_object_image_save(img, dstpath, NULL, "compress=5") != 0) + { + chmod(dstpath, 0777); + + INIT_LOG; + APPEND_LOG_BASIC_NAME(LC_SNAPSHOT, "captureScreen"); + APPEND_LOG_COMMON_NONE(0); + log.length += sprintf(log.data + log.length, "`,%s`,%d", dstpath, getOrientation()); + printLog(&log, MSG_LOG); + } + else + { + PRINTMSG("captureScreen : evas_object_image_save failed\n"); + ret = -1; + } + } + else + { + PRINTMSG("captureScreen : evas_object_image_add failed\n"); + ret = -1; + } + } + else + { + PRINTMSG("captureScreen : create canvas failed\n"); + ret = -1; + } + } + else + { + PRINTMSG("captureScreen : captureScreenShotX failed\n"); + ret = -1; + } + + // release resources + releaseScreenShotX(&sdata); + if(ev) + destroy_canvas(ev); + + probeBlockEnd(); + + return ret; +} + +int initialize_screencapture() +{ + // remove all previous screenshot in dir +// remove_indir(SCREENSHOT_DIRECTORY); + + // make screenshot directory +// mkdir(SCREENSHOT_DIRECTORY, 0777); + + return 0; +} + +int finalize_screencapture() +{ + return 0; +} + +// ======================================================================= +// screen shot manipulation functions +// ======================================================================= + +static Eina_Bool _captureTimer(void* data) +{ + probeBlockStart(); + SCREENSHOT_TIMEOUT(); + probeBlockEnd(); + + return ECORE_CALLBACK_CANCEL; +} + +int activateCaptureTimer() +{ + ecore_timer_add(CAPTURE_TIMEOUT, _captureTimer, NULL); + return 0; +} + +void _cb_render_post(void* data, Evas* e, void* eventinfo) +{ + probeBlockStart(); + SCREENSHOT_DONE(); + probeBlockEnd(); +} + diff --git a/helper/dacollection.c b/helper/dacollection.c new file mode 100755 index 0000000..ffeac39 --- /dev/null +++ b/helper/dacollection.c @@ -0,0 +1,838 @@ +/* + * DA probe + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Jaewon Lim + * Woojin Jung + * Juyoung Kim + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#include // for assert +#include // for malloc, free +#include // for strlen, strcpy +#include // for pthread_mutex_t + +#include "dahelper.h" +#include "daerror.h" +#include "dacollection.h" + +// hash table variable +__hashInfo _hashinfo = +{ + NULL, // khash_t(symbol)* symHash + PTHREAD_MUTEX_INITIALIZER, // pthread_mutex_t symHashMutex + NULL, // khash_t(allocmap)* memHash + PTHREAD_MUTEX_INITIALIZER, // pthread_mutex_t memHashMutex + NULL, // khash_t(uiobject)* uiobjHash + PTHREAD_MUTEX_INITIALIZER, // pthread_mutex_t uiobjHashMutex + NULL, // khash_t(object)* objHash + PTHREAD_MUTEX_INITIALIZER, // pthread_mutex_t objHashMutex + NULL, // khash_t(detector)* dttHash + PTHREAD_MUTEX_INITIALIZER // pthread_mutex_t dttHashMutex +}; + +// glist typedef and variable +struct _element +{ + int keylen; + char* keystr; + void* dataptr; + struct _element* next; + struct _element* prev; +}; + +typedef struct _element element_t; + +element_t* gsymbol_list = NULL; +pthread_mutex_t glist_mutex = PTHREAD_MUTEX_INITIALIZER; + +// ********************************************************************************************* +// hash table related implemenation +// ********************************************************************************************* + +int initialize_hash_table() +{ + SYMBOLHASH_LOCK; + SYMBOLHASH = kh_init(symbol); + SYMBOLHASH_UNLOCK; + + MEMORYHASH_LOCK; + MEMORYHASH = kh_init(allocmap); + MEMORYHASH_UNLOCK; + + UIOBJECTHASH_LOCK; + UIOBJECTHASH = kh_init(uiobject); + UIOBJECTHASH_UNLOCK; + + OBJECTHASH_LOCK; + OBJECTHASH = kh_init(object); + OBJECTHASH_UNLOCK; + + DETECTORHASH_LOCK; + DETECTORHASH = kh_init(detector); + DETECTORHASH_UNLOCK; + + return 0; +} + +int finalize_hash_table() +{ + if(SYMBOLHASH) + { + khiter_t k; + char* val; + + SYMBOLHASH_LOCK; + for(k = kh_begin(SYMBOLHASH); k != kh_end(SYMBOLHASH); k++) + { + if(kh_exist(SYMBOLHASH, k)) + { + val = kh_value(SYMBOLHASH, k); + free(val); + } + } + kh_destroy(symbol, SYMBOLHASH); + SYMBOLHASH = NULL; + SYMBOLHASH_UNLOCK; + } + + if(MEMORYHASH) + { + MEMORYHASH_LOCK; + kh_destroy(allocmap, MEMORYHASH); + MEMORYHASH = NULL; + MEMORYHASH_UNLOCK; + } + + if(UIOBJECTHASH) + { + khiter_t k; + _uiobjectinfo* val; + + UIOBJECTHASH_LOCK; + for(k = kh_begin(UIOBJECTHASH); k != kh_end(UIOBJECTHASH); k++) + { + if(kh_exist(UIOBJECTHASH, k)) + { + val = kh_value(UIOBJECTHASH, k); + if(likely(val->type != 0)) free(val->type); + if(likely(val->name != 0)) free(val->name); + free(val); + } + } + kh_destroy(uiobject, UIOBJECTHASH); + UIOBJECTHASH = NULL; + UIOBJECTHASH_UNLOCK; + } + + if(OBJECTHASH) + { + OBJECTHASH_LOCK; + kh_destroy(object, OBJECTHASH); + OBJECTHASH = NULL; + OBJECTHASH_UNLOCK; + } + + if(DETECTORHASH) + { + DETECTORHASH_LOCK; + kh_destroy(detector, DETECTORHASH); + DETECTORHASH = NULL; + DETECTORHASH_UNLOCK; + } + + return 0; +} + +/*********************************************************** + * symbol hash related functions + ***********************************************************/ +// return 0 if there is no entry in hash +// return 1 if there is entry in hash +// return negative value if error occurred +int find_symbol_hash(void* ptr, char** psymbol) +{ + khiter_t k; + int ret = 0; + + if(unlikely(SYMBOLHASH == 0)) + return ERR_NOTINITIALIZED; + + if(unlikely(ptr == NULL)) + return ERR_WRONGPARAMETER; + + if(unlikely(psymbol == NULL)) + return ERR_WRONGPARAMETER; + + probeBlockStart(); + + SYMBOLHASH_LOCK; + k = kh_get(symbol, SYMBOLHASH, (uint32_t)ptr); + if(k == kh_end(SYMBOLHASH)) // there is no entry for key + { + ret = 0; + } + else + { + *psymbol = kh_value(SYMBOLHASH, k); + ret = 1; + } + SYMBOLHASH_UNLOCK; + probeBlockEnd(); + return ret; +} + +// return 0 if succeed +// return 1 if there is already exist in hash +// return negative value if other error occurred +int add_symbol_hash(void* ptr, const char* str, int strlen) +{ + khiter_t k; + int rethash, ret = 0; + + if(unlikely(SYMBOLHASH == 0)) + return ERR_NOTINITIALIZED; + + if(unlikely(ptr == NULL)) + return ERR_WRONGPARAMETER; + + if(unlikely(str == NULL)) + return ERR_WRONGPARAMETER; + + probeBlockStart(); + + SYMBOLHASH_LOCK; + k = kh_put(symbol, SYMBOLHASH, (uint32_t)ptr, &rethash); + if(likely(rethash != 0)) // succeed to add in hash table + { + char* tlast = (char*)malloc(strlen); + if(likely(tlast != NULL)) + { + memcpy(tlast, str, strlen); + kh_value(SYMBOLHASH, k) = tlast; + } + else + { + kh_del(symbol, SYMBOLHASH, k); + ret = ERR_OUTOFMEMORY; + } + } + else + { + // TODO : error handling + ret = 1; + } + SYMBOLHASH_UNLOCK; + probeBlockEnd(); + return ret; +} + +/*********************************************************** + * memory hash related functions + ***********************************************************/ +// return 0 if succeed +// return 1 if key is already exist in hash table +// return negative value if other error occurred +int add_memory_hash(void* ptr, size_t size, unsigned short type, unsigned short caller) +{ + khiter_t k; + int rethash, ret = 0; + size_t memsize; + uint64_t meminfo; + + if(unlikely(MEMORYHASH == 0)) + return ERR_NOTINITIALIZED; + + if(unlikely(ptr == NULL)) + return ERR_WRONGPARAMETER; + + probeBlockStart(); + MEMORYHASH_LOCK; + k = kh_put(allocmap, MEMORYHASH, (uint32_t)ptr, &rethash); + if(likely(rethash != 0)) // succeed to add in hash table + { + kh_value(MEMORYHASH, k) = MAKE_MEMINFO(caller, type, size); + update_heap_memory_size(true, size); + } + else + { + // key is already exist in hash + // update memory info + meminfo = kh_value(MEMORYHASH, k); + memsize = GET_MEMSIZE(meminfo); + if(memsize == size) + { + kh_value(MEMORYHASH, k) = MAKE_MEMINFO(caller, type, size); + } + ret = 1; + } + MEMORYHASH_UNLOCK; + probeBlockEnd(); + return ret; +} + +// return 0 if succeed +// return 1 if key is not in hash table +// return negative if other error occurred +int del_memory_hash(void* ptr, unsigned short type, unsigned short* caller) +{ + khiter_t k; + int ret = 0; + uint32_t size; + uint64_t meminfo; + + if(unlikely(MEMORYHASH == 0)) + return ERR_NOTINITIALIZED; + + if(unlikely(ptr == NULL)) + return ERR_WRONGPARAMETER; + + probeBlockStart(); + MEMORYHASH_LOCK; + k = kh_get(allocmap, MEMORYHASH, (uint32_t)ptr); + if(likely(k != kh_end(MEMORYHASH))) + { // there is entry in hash table + meminfo = kh_value(MEMORYHASH, k); + if(unlikely(type != GET_MEMTYPE(meminfo))) + { + ret = -1; + } + else + { + size = GET_MEMSIZE(meminfo); + if(caller != NULL) + *caller = GET_MEMCALLER(meminfo); + update_heap_memory_size(false, size); + kh_del(allocmap, MEMORYHASH, k); + } + } + else + { + ret = 1; // there is not entry in hash table + } + MEMORYHASH_UNLOCK; + probeBlockEnd(); + + return ret; +} + +/*********************************************************** + * uiobject hash related functions + ***********************************************************/ +// return 0 if there is no entry in hash +// return 1 if there is entry in hash +// return negative value if error occurred +int find_uiobject_hash(void* ptr, char** type, char** classname) +{ + khiter_t k; + int ret = 0; + + if(unlikely(UIOBJECTHASH == 0)) + return ERR_NOTINITIALIZED; + + if(unlikely(ptr == NULL)) + return ERR_WRONGPARAMETER; + + if(unlikely(type == NULL)) + return ERR_WRONGPARAMETER; + + if(unlikely(classname == NULL)) + return ERR_WRONGPARAMETER; + + probeBlockStart(); + + UIOBJECTHASH_LOCK; + k = kh_get(uiobject, UIOBJECTHASH, (uint32_t)ptr); + if(unlikely(k == kh_end(UIOBJECTHASH))) // there is no entry for key + { + ret = 0; + } + else + { + *classname = kh_value(UIOBJECTHASH, k)->name; + *type = kh_value(UIOBJECTHASH, k)->type; + ret = 1; + } + UIOBJECTHASH_UNLOCK; + probeBlockEnd(); + return ret; +} + +// return 0 if succeed +// return 1 if there is no entry in hash +// return negative value if other error occurred +int add_uiobject_hash_class(void* ptr, const char* classname) +{ + int str_len; + khiter_t k; + int rethash, ret = 0; + + if(unlikely(UIOBJECTHASH == 0)) + return ERR_NOTINITIALIZED; + + if(unlikely(ptr == NULL)) + return ERR_WRONGPARAMETER; + + if(unlikely(classname == NULL)) + return ERR_WRONGPARAMETER; + + probeBlockStart(); + + str_len = strlen(classname) + 1; + + UIOBJECTHASH_LOCK; + k = kh_put(uiobject, UIOBJECTHASH, (uint32_t)ptr, &rethash); + if(likely(rethash == 0)) // entry is already in hash table + { + if(likely(kh_value(UIOBJECTHASH, k) != NULL)) + { + if(kh_value(UIOBJECTHASH, k)->name == NULL) + { + char* tlast = (char*)malloc(str_len); + if(likely(tlast != NULL)) + { + memcpy(tlast, classname, str_len); + kh_value(UIOBJECTHASH, k)->name = tlast; + } + else + { + kh_value(UIOBJECTHASH, k)->name = NULL; + ret = ERR_OUTOFMEMORY; // out of memory + } + } + else + ret = ERR_ALREADYEXIST; + } + else // not possible + ret = ERR_NOTEXIST; // there is entry but there is no value + } + else // error + ret = 1; // there is no entry + + UIOBJECTHASH_UNLOCK; + probeBlockEnd(); + return ret; +} + +// return 0 if succeed +// return 1 if there is already exist in hash +// return negative value if other error occurred +int add_uiobject_hash_type(void* ptr, const char* type) +{ + int str_len; + khiter_t k; + int rethash, ret = 0; + + if(unlikely(UIOBJECTHASH == 0)) + return ERR_NOTINITIALIZED; + + if(unlikely(ptr == NULL)) + return ERR_WRONGPARAMETER; + + if(unlikely(type == NULL)) + return ERR_WRONGPARAMETER; + + probeBlockStart(); + + str_len = strlen(type) + 1; + + UIOBJECTHASH_LOCK; + k = kh_put(uiobject, UIOBJECTHASH, (uint32_t)ptr, &rethash); + if(likely(rethash != 0)) // succeed to add in hash table + { + char* tlast; + _uiobjectinfo* newentry; + + newentry = (_uiobjectinfo*)calloc(1, sizeof(_uiobjectinfo)); + if(likely(newentry != NULL)) + { + kh_value(UIOBJECTHASH, k) = newentry; + + tlast = (char*)malloc(str_len); + if(likely(tlast != NULL)) + { + memcpy(tlast, type, str_len); + kh_value(UIOBJECTHASH, k)->type = tlast; + } + else + { + kh_value(UIOBJECTHASH, k)->type = NULL; + ret = ERR_OUTOFMEMORY; + } + } + else + { + kh_del(uiobject, UIOBJECTHASH, k); + ret = ERR_OUTOFMEMORY; + } + } + else + ret = 1; + + UIOBJECTHASH_UNLOCK; + probeBlockEnd(); + return ret; +} + +// return 0 if succeed +// return 1 if key is not in hash table +// return negative value if other error occurred +int del_uiobject_hash(void* ptr) +{ + khiter_t k; + _uiobjectinfo* val; + int ret = 0; + + if(unlikely(UIOBJECTHASH == 0)) + return ERR_NOTINITIALIZED; + + if(unlikely(ptr == NULL)) + return ERR_WRONGPARAMETER; + + probeBlockStart(); + UIOBJECTHASH_LOCK; + k = kh_get(uiobject, UIOBJECTHASH, (uint32_t)ptr); + if(likely(k != kh_end(UIOBJECTHASH))) // there is entry in hash table + { + val = kh_value(UIOBJECTHASH, k); + kh_del(uiobject, UIOBJECTHASH, k); + if(likely(val->type != NULL)) free(val->type); + if(likely(val->name != NULL)) free(val->name); + free(val); + } + else + { + ret = 1; + } + UIOBJECTHASH_UNLOCK; + probeBlockEnd(); + + return ret; +} + +/*********************************************************** + * object hash related functions + ***********************************************************/ +// return 0 if there is no entry in hash +// return 1 if there is entry in hash +// return negative value if error occurred +int find_object_hash(void* ptr, unsigned short *caller) +{ + khiter_t k; + int ret = 0; + + if(unlikely(OBJECTHASH == 0)) + return ERR_NOTINITIALIZED; + + if(unlikely(ptr == NULL)) + return ERR_WRONGPARAMETER; + + if(unlikely(caller == NULL)) + return ERR_WRONGPARAMETER; + + probeBlockStart(); + + OBJECTHASH_LOCK; + k = kh_get(object, OBJECTHASH, (uint32_t)ptr); + if(unlikely(k == kh_end(OBJECTHASH))) // there is no entry for key + { + ret = 0; + } + else + { + *caller = kh_value(OBJECTHASH, k); + ret = 1; + } + OBJECTHASH_UNLOCK; + probeBlockEnd(); + return ret; +} + +// return 0 if succeed +// return 1 if there is no entry in hash +// return negative value if other error occurred +int add_object_hash(void* ptr, unsigned short caller) +{ + khiter_t k; + int rethash, ret = 0; + + if(unlikely(OBJECTHASH == 0)) + return ERR_NOTINITIALIZED; + + if(unlikely(ptr == NULL)) + return ERR_WRONGPARAMETER; + + probeBlockStart(); + + OBJECTHASH_LOCK; + k = kh_put(object, OBJECTHASH, (uint32_t)ptr, &rethash); + if(likely(rethash != 0)) // entry is already in hash table + { + kh_value(OBJECTHASH, k) = caller; + } + else + { + // TODO : error handling + ret = 1; + } + + OBJECTHASH_UNLOCK; + probeBlockEnd(); + return ret; +} + +// return 0 if succeed +// return 1 if key is not in hash table +// return negative value if other error occurred +int del_object_hash(void* ptr, unsigned short *caller) +{ + khiter_t k; + int ret = 0; + + if(unlikely(OBJECTHASH == 0)) + return ERR_NOTINITIALIZED; + + if(unlikely(ptr == NULL)) + return ERR_WRONGPARAMETER; + + if(unlikely(caller == NULL)) + return ERR_WRONGPARAMETER; + + probeBlockStart(); + + OBJECTHASH_LOCK; + k = kh_get(object, OBJECTHASH, (uint32_t)ptr); + if(likely(k != kh_end(OBJECTHASH))) // there is entry in hash table + { + *caller = kh_value(OBJECTHASH, k); + kh_del(object, OBJECTHASH, k); + } + else + { + ret = 1; + } + OBJECTHASH_UNLOCK; + probeBlockEnd(); + + return ret; +} + +/*********************************************************** + * detector hash related functions + ***********************************************************/ +// return 0 if succeed +// return 1 if there is already exist in hash +// return negative value if other error occurred +int add_detector_hash(void* ptr, void* listener) +{ + khiter_t k; + int rethash, ret = 0; + + if(unlikely(DETECTORHASH == 0)) + return ERR_NOTINITIALIZED; + + if(unlikely(ptr == NULL)) + return ERR_WRONGPARAMETER; + + if(unlikely(listener == NULL)) + return ERR_WRONGPARAMETER; + + probeBlockStart(); + + DETECTORHASH_LOCK; + k = kh_put(detector, DETECTORHASH, (uint32_t)ptr, &rethash); + if(likely(rethash != 0)) // succeed to add in hash table + { + kh_value(DETECTORHASH, k) = listener; + } + else + { + // TODO : error handling + ret = 1; + } + DETECTORHASH_UNLOCK; + probeBlockEnd(); + return ret; +} + +// return 0 if succeed +// return 1 if key is not in hash table +// return negative value if other error occurred +int del_detector_hash(void* ptr) +{ + khiter_t k; + int ret = 0; + + if(unlikely(DETECTORHASH == 0)) + return ERR_NOTINITIALIZED; + + if(unlikely(ptr == NULL)) + return ERR_WRONGPARAMETER; + + probeBlockStart(); + DETECTORHASH_LOCK; + k = kh_get(detector, DETECTORHASH, (uint32_t)ptr); + if(likely(k != kh_end(DETECTORHASH))) // there is entry in hash table + { + kh_del(detector, DETECTORHASH, k); + } + else + { + ret = 1; + } + DETECTORHASH_UNLOCK; + probeBlockEnd(); + + return ret; +} + + +// ********************************************************************************************* +// glist implemenation +// ********************************************************************************************* + +// all function to call this function have to use mutex_lock +static element_t* find_element(char* key) +{ + element_t* res; + int keylen; + + if(unlikely(key == NULL)) + return NULL; + + keylen = strlen(key); + +// pthread_mutex_lock(&glist_mutex); // this is commented because of static function + res = gsymbol_list; + while(res != NULL) + { + if(keylen == res->keylen && (strcmp(key, res->keystr) == 0)) + break; + res = res->next; + } +// pthread_mutex_unlock(&glist_mutex); // this is commented because of static function + + return res; +} + +int add_to_glist(char* key, void* data) +{ + element_t* elm; + int ret = 0; + + if(unlikely(key == NULL || data == NULL)) + return 0; + + pthread_mutex_lock(&glist_mutex); + elm = find_element(key); + if(elm == NULL) + { + elm = (element_t*)malloc(sizeof(element_t)); + if(likely(elm != NULL)) + { + elm->keylen = strlen(key); + elm->keystr = (char*)malloc(elm->keylen + 1); + if(likely(elm->keystr != NULL)) + { + strcpy(elm->keystr, key); + elm->dataptr = data; + elm->next = gsymbol_list; + elm->prev = NULL; + if(gsymbol_list) + gsymbol_list->prev = elm; + gsymbol_list = elm; + ret = 1; + } + else + { + free(elm); + } + } + } + pthread_mutex_unlock(&glist_mutex); + + return ret; +} + +int remove_from_glist(char* key) +{ + element_t* elm; + int ret = 0; + + pthread_mutex_lock(&glist_mutex); + elm = find_element(key); + if(elm != NULL) + { + if(elm->prev) + elm->prev->next = elm->next; + if(elm->next) + elm->next->prev = elm->prev; + if(gsymbol_list == elm) + gsymbol_list = gsymbol_list->next; + } + pthread_mutex_unlock(&glist_mutex); + + if(elm != NULL) + { + free(elm->dataptr); + free(elm->keystr); + free(elm); + ret = 1; + } + + return ret; +} + +int remove_all_glist() +{ + element_t* elm; + + pthread_mutex_lock(&glist_mutex); + while(gsymbol_list != NULL) + { + elm = gsymbol_list; + gsymbol_list = elm->next; + free(elm->dataptr); + free(elm->keystr); + free(elm); + } + pthread_mutex_unlock(&glist_mutex); + + return 1; +} + +void* find_glist(char* key) +{ + element_t* elm; + + pthread_mutex_lock(&glist_mutex); + elm = find_element(key); + pthread_mutex_unlock(&glist_mutex); + + if(elm) + return elm->dataptr; + else + return NULL; +} + diff --git a/helper/dahelper.c b/helper/dahelper.c new file mode 100755 index 0000000..fc4496f --- /dev/null +++ b/helper/dahelper.c @@ -0,0 +1,109 @@ +/* + * DA probe + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Jaewon Lim + * Woojin Jung + * Juyoung Kim + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#include // for wcslen +#include // for unlink +#include +#include // for opendir, readdir + +#include "dahelper.h" + +char *lib_string[NUM_ORIGINAL_LIBRARY] = {"libc.so.6", "libpthread.so.0", + "libelementary.so", "libosp-uifw.so", "libosp-appfw.so", "libosp-web.so", + "libecore_input_evas.so.1", "libdaemon.so.0", "libcapi-appfw-application.so.0"}; +void *lib_handle[NUM_ORIGINAL_LIBRARY]; + +/* trace info global variable */ +__traceInfo gTraceInfo = +{ + { + 1, // int eventIndex + PTHREAD_MUTEX_INITIALIZER // pthread_mutex_t eventMutex + }, // __indexInfo + { + -1, // int daemonSock + PTHREAD_MUTEX_INITIALIZER // ptrhread_mutex_t sockMutex + }, // __socketInfo + { + {0, }, // char appName[128] + 0 // unsigned int startTime + }, // __appInfo + { + 0, // int state + PTHREAD_MUTEX_INITIALIZER // ptrhread_mutex_t ssMutex + }, // __screenshotInfo + { + NULL, // map_start + NULL // map_end + }, // __mapInfo + -1, // int stateTouch + 0, // int init_complete + 0, // int custom_chart_callback_count + 0 // unsigned long optionflag +}; + +void WcharToChar(char* pstrDest, const wchar_t* pwstrSrc) +{ + int nLen=(int)wcslen(pwstrSrc); + wcstombs(pstrDest, pwstrSrc, nLen+1); +} + +// return 0 if succeed +// return -1 if error occured +int remove_indir(const char *dirname) +{ + DIR *dir; + struct dirent *entry; + char path[MAX_PATH_LENGTH]; + + dir = opendir(dirname); + if(dir == NULL) + { + return -1; + } + + while((entry = readdir(dir)) != NULL) + { + if (strcmp(entry->d_name, ".") && strcmp(entry->d_name, "..")) + { + snprintf(path, (size_t) MAX_PATH_LENGTH, "%s/%s", dirname, entry->d_name); + if (entry->d_type != DT_DIR) // file + { + unlink(path); + } + else { } // directory + } + } + closedir(dir); + + return 0; +} + + diff --git a/helper/libdaprobe.c b/helper/libdaprobe.c new file mode 100755 index 0000000..646f412 --- /dev/null +++ b/helper/libdaprobe.c @@ -0,0 +1,793 @@ +/* + * DA probe + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Jaewon Lim + * Woojin Jung + * Juyoung Kim + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#include // for sprintf +#include // for getenv +#include // for strstr +#include // for bool +#include // fot uint32_t,uint64_t +#include // for va_list, va_arg(__appendTypeLog) +#include // for backtrace, backtrace_symbols +#include // for write, alarm function, syscall +#include // for pthread_mutex_lock +#include + +#include // for syscall +#include // for gettimeofday +#include // for socket, connect +#include // for sockaddr_un +#include // for timerfd + +#include "probeinfo.h" +#include "dautil.h" +#include "dahelper.h" +#include "dacollection.h" +#include "da_sync.h" + +#define APP_INSTALL_PATH "/opt/apps" +#define TIZEN_APP_POSTFIX ".exe" +#define UDS_NAME "/tmp/da.socket" +#define TIMERFD_INTERVAL 100000000 // 0.1 sec + +__thread int gProbeBlockCount = 0; +__thread int gProbeDepth = 0; +__thread pid_t gTid = -1; + +int g_timerfd = 0; +long g_total_alloc_size = 0; +pthread_t g_recvthread_id; + +int getExecutableMappingAddress(); + +/****************************************************************************** + * internal functions + (this means that these functions do not need to set enter/exit flag) + ******************************************************************************/ + +// runtime configure the probe option +static void _configure(char* configstr) +{ + char buf[64]; + gTraceInfo.optionflag = atoi(configstr); + + sprintf(buf, "configure in probe : %s, %lx\n", configstr, gTraceInfo.optionflag); + PRINTMSG(buf); + + if(isOptionEnabled(OPT_FUNC)) + { + __profil(1); + } + else + { + __profil(0); + } +} + +// create socket to daemon and connect +static int createSocket(void) +{ + ssize_t recvlen; + int clientLen, ret = 0; + struct sockaddr_un clientAddr; + char buf[16]; + log_t log; + + if((gTraceInfo.socket.daemonSock = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0)) != -1) + { + bzero(&clientAddr, sizeof(clientAddr)); + clientAddr.sun_family = AF_UNIX; + sprintf(clientAddr.sun_path, "%s", UDS_NAME); + + clientLen = sizeof(clientAddr); + if(connect(gTraceInfo.socket.daemonSock, (struct sockaddr *)&clientAddr, clientLen) >= 0) + { + // recv initial configuration value + recvlen = recv(gTraceInfo.socket.daemonSock, &log, + sizeof(log.type) + sizeof(log.length), MSG_WAITALL); + + if(recvlen > 0) // recv succeed + { + if(log.length > 0) + { + if(log.length >= DA_LOG_MAX) + log.length = DA_LOG_MAX - 1; + recvlen = recv(gTraceInfo.socket.daemonSock, log.data, + log.length, MSG_WAITALL); + } + else + { + log.length = 0; + } + + log.data[log.length] = '\0'; + + if(log.type == MSG_CONFIG) + { + _configure(log.data); + } + else + { + // unexpected case + } + } + else if(recvlen < 0) + { + char buf[64]; + sprintf(buf, "recv failed in socket creation with error(%d)\n", recvlen); + PRINTMSG(buf); + } + else // closed by other peer + { + + } + sprintf(buf, "%d|%u", getpid(), gTraceInfo.app.startTime); + printLogStr(buf, MSG_PID); + PRINTMSG("createSocket connect() success\n"); + } + else + { + close(gTraceInfo.socket.daemonSock); + gTraceInfo.socket.daemonSock = -1; + ret = -1; + } + } + else + { + ret = -1; + } + + return ret; +} + + +// parse backtrace string and find out the caller of probed api function +// return 0 if caller is user binary, otherwise return 1 +static int determineCaller(char* tracestring) +{ + char *substr; + + // determine whether saveptr (caller binary name) is user binary or not + substr = strstr(tracestring, APP_INSTALL_PATH); + + if(substr == NULL) // not user binary + { + return 1; + } + else // user binary + { +#ifdef TIZENAPP + substr = strstr(tracestring, TIZEN_APP_POSTFIX); + if(substr == NULL) + return 1; +#endif + return 0; + } +} + +// return current thread id +static pid_t _gettid() +{ + if(gTid == -1) + gTid = syscall(__NR_gettid); // syscall is very expensive + return gTid; +} + +static void* recvThread(void* data) +{ + fd_set readfds, workfds; + int maxfd = 0, rc; + uint64_t xtime; + ssize_t recvlen; + log_t log; + sigset_t profsigmask; + + if(gTraceInfo.socket.daemonSock == -1) + return NULL; + + probeBlockStart(); + + sigemptyset(&profsigmask); + sigaddset(&profsigmask, SIGPROF); + pthread_sigmask(SIG_BLOCK, &profsigmask, NULL); + + FD_ZERO(&readfds); + if(g_timerfd > 0) + { + maxfd = g_timerfd; + FD_SET(g_timerfd, &readfds); + } + if(maxfd < gTraceInfo.socket.daemonSock) + maxfd = gTraceInfo.socket.daemonSock; + FD_SET(gTraceInfo.socket.daemonSock, &readfds); + + while(1) + { + workfds = readfds; + rc = select(maxfd + 1, &workfds, NULL, NULL, NULL); + if(rc < 0) + { + continue; + } + + if(g_timerfd > 0 && FD_ISSET(g_timerfd, &workfds)) + { + recvlen = read(g_timerfd, &xtime, sizeof(xtime)); + if(recvlen > 0) + { + log.length = sprintf(log.data, "%ld", g_total_alloc_size); + printLog(&log, MSG_ALLOC); + } + else + { + // read failed + } + continue; + } + else if(FD_ISSET(gTraceInfo.socket.daemonSock, &workfds)) + { + recvlen = recv(gTraceInfo.socket.daemonSock, &log, + sizeof(log.type) + sizeof(log.length), MSG_WAITALL); + + if(recvlen > 0) // recv succeed + { + if(log.length > 0) + { + if(log.length >= DA_LOG_MAX) + log.length = DA_LOG_MAX - 1; + recvlen = recv(gTraceInfo.socket.daemonSock, log.data, + log.length, MSG_WAITALL); + } + else + { + log.length = 0; + } + + log.data[log.length] = '\0'; + + if(log.type == MSG_CONFIG) + { + _configure(log.data); + } + else if(log.type == MSG_STOP) + { + application_exit(); + } + else + { + char buf[64]; + sprintf(buf, "recv unknown message(%d)\n", log.type); + PRINTMSG(buf); + continue; + } + } + else if(recvlen == 0) // closed by other peer + { + close(gTraceInfo.socket.daemonSock); + gTraceInfo.socket.daemonSock = -1; + break; + } + else // recv error + { + char buf[64]; + sprintf(buf, "recv failed in recv thread with error(%d)\n", recvlen); + PRINTMSG(buf); + continue; + } + } + else // unknown case + { + PRINTMSG("unknown fd in recvThread\n"); + continue; + } + } + + probeBlockEnd(); + return NULL; +} + +/***************************************************************************** + * initialize / finalize function + *****************************************************************************/ + +void __attribute__((constructor)) _init_probe() +{ + struct timeval ttime; + struct itimerspec ctime; + + probeBlockStart(); + + initialize_hash_table(); + + initialize_screencapture(); + + initialize_event(); + + getExecutableMappingAddress(); + + // get app start time + gettimeofday(&ttime, NULL); + gTraceInfo.app.startTime = ((ttime.tv_sec * 10000 + (ttime.tv_usec/100))); + + // create socket for communication with da_daemon + if(createSocket() == 0) + { + // create timerfd + g_timerfd = timerfd_create(CLOCK_REALTIME, TFD_CLOEXEC); + if(g_timerfd > 0) + { + ctime.it_value.tv_sec = 0; + ctime.it_value.tv_nsec = TIMERFD_INTERVAL; + ctime.it_interval.tv_sec = 0; + ctime.it_interval.tv_nsec = TIMERFD_INTERVAL; + if(0 > timerfd_settime(g_timerfd, 0, &ctime, NULL)) + { + PRINTMSG("failed to set timerfd\n"); + close(g_timerfd); + g_timerfd = 0; + } + } + else + { + PRINTMSG("failed to create timerdf\n"); + } + + // create recv Thread + if(pthread_create(&g_recvthread_id, NULL, recvThread, NULL) < 0) // thread creation failed + { + PRINTMSG("failed to crate recv thread\n"); + } + update_heap_memory_size(true, 0); + } + else + { + + } + + PRINTMSG("dynamic analyzer probe helper so loading...\n"); + + gTraceInfo.init_complete = 1; + probeBlockEnd(); +} + +void __attribute__((destructor)) _fini_probe() +{ + int i; + probeBlockStart(); + + gTraceInfo.init_complete = -1; + PRINTMSG("dynamic analyzer probe helper so unloading...\n"); + + remove_all_glist(); + + // close timerfd + if(g_timerfd > 0) + close(g_timerfd); + + // close socket + if(gTraceInfo.socket.daemonSock != -1) + { + printLogStr(NULL, MSG_TERMINATE); + close(gTraceInfo.socket.daemonSock); + gTraceInfo.socket.daemonSock = -1; + } + + finalize_event(); + + finalize_screencapture(); + + finalize_hash_table(); + + for(i = 0; i < NUM_ORIGINAL_LIBRARY; i++) + { + if(lib_handle[i] != NULL) + { + dlclose(lib_handle[i]); + } + } + + probeBlockEnd(); +} + + +/************************************************************************** + * Helper APIs + **************************************************************************/ + +/************************************************************************ + * manipulate and print log functions + ************************************************************************/ + +bool printLog(log_t* log, int msgType) +{ + int res; + if(unlikely(gTraceInfo.socket.daemonSock == -1)) + return false; + + if(unlikely(log == NULL)) + return false; + + probeBlockStart(); + log->type = msgType; + real_pthread_mutex_lock(&(gTraceInfo.socket.sockMutex)); + res = send(gTraceInfo.socket.daemonSock, log, sizeof(log->type) + sizeof(log->length) + log->length, 0); + real_pthread_mutex_unlock(&(gTraceInfo.socket.sockMutex)); + probeBlockEnd(); + + return true; +} + +bool printLogStr(const char* str, int msgType) +{ + int res; + log_t log; + + if(unlikely(gTraceInfo.socket.daemonSock == -1)) + return false; + + probeBlockStart(); + + log.type = msgType; + if(str) + { + sprintf(log.data, "%s", str); + log.length = strlen(str); + } + else + { + log.length = 0; + } + + real_pthread_mutex_lock(&(gTraceInfo.socket.sockMutex)); + res = send(gTraceInfo.socket.daemonSock, &log, sizeof(log.type) + sizeof(log.length) + log.length, MSG_DONTWAIT); + real_pthread_mutex_unlock(&(gTraceInfo.socket.sockMutex)); + + probeBlockEnd(); + + return true; +} + +// return 0 for successful case +// return non-zero for error +// if token is NULL then use DEFAULT TOKEN "`," +// if token is not NULL then insert DEFAULT TOKEN before append input +int __appendTypeLog(log_t* log, int nInput, char* token, ...) +{ + static char* default_token = DEFAULT_TOKEN; + va_list p_arg; + int i, type; + char* seperator = default_token; + + if(nInput <= 0 || log == NULL) + return -1; + + probeBlockStart(); + + va_start(p_arg, token); + + if(token != NULL) + seperator = token; + + for(i = 0; i < nInput; i++) + { + type = va_arg(p_arg, int); + + if(likely(log->length > 0)) // append token or default token + { + if(unlikely(i == 0)) + log->length += sprintf(log->data + log->length, "%s", default_token); + else + log->length += sprintf(log->data + log->length, "%s", seperator); + } + + switch(type) + { + case VT_INT: + log->length += sprintf(log->data + log->length, "%d", va_arg(p_arg, int)); + break; + case VT_UINT: + log->length += sprintf(log->data + log->length, "%u", va_arg(p_arg, unsigned int)); + break; + case VT_LONG: + log->length += sprintf(log->data + log->length, "%ld", va_arg(p_arg, long)); + break; + case VT_ULONG: + log->length += sprintf(log->data + log->length, "%lu", va_arg(p_arg, unsigned long)); + break; + case VT_STR: + log->length += sprintf(log->data + log->length, "%s", va_arg(p_arg, char*)); + break; + case VT_CHAR: // 'char' is promoted to 'int' when passed through '...' + log->length += sprintf(log->data + log->length, "%c", va_arg(p_arg, int)); + break; + case VT_PTR: + log->length += sprintf(log->data + log->length, "%p", va_arg(p_arg, void*)); + break; + case VT_NULL: + va_arg(p_arg, unsigned int); + break; + case VT_OFF_T: + log->length += sprintf(log->data + log->length, "%ld", va_arg(p_arg, off_t)); + break; + case VT_SIZE_T: + log->length += sprintf(log->data + log->length, "%u", va_arg(p_arg, size_t)); + break; + case VT_SSIZE_T: + log->length += sprintf(log->data + log->length, "%d", va_arg(p_arg, ssize_t)); + break; + case VT_SOCKLEN_T: + log->length += sprintf(log->data + log->length, "%u", va_arg(p_arg, socklen_t)); + break; + case VT_UINT16_T: // 'uint16_t' is promoted to 'int' when passed through '...' + log->length += sprintf(log->data + log->length, "%u", va_arg(p_arg, int)); + break; + case VT_UINT32_T: + log->length += sprintf(log->data + log->length, "%u", va_arg(p_arg, uint32_t)); + break; + case VT_UINT64_T: + log->length += sprintf(log->data + log->length, "%llu", va_arg(p_arg, uint64_t)); + break; + case VT_MODE_T: + log->length += sprintf(log->data + log->length, "%u", va_arg(p_arg, mode_t)); + break; +/* case VT_DEV_T: + log->length += sprintf(log->data + log->length, "%lu", va_arg(p_arg, dev_t)); + break; + case VT_NFDS_T: + log->length += sprintf(log->data + log->length, "%lu", va_arg(p_arg, nfds_t)); + break;*/ + default: + va_end(p_arg); + probeBlockEnd(); + return -1; + } + } + + va_end(p_arg); + + probeBlockEnd(); + return 0; +} + +// get backtrace string +// return stack depth if succeed, otherwise return 0 +// parameter 'log' cannot be null +int getBacktraceString(log_t* log, int bufsize) +{ + void* array[MAX_STACK_DEPTH]; + char** strings = NULL; + size_t i, size; + int initsize; + int stringlen; + + if(log == NULL) + return 0; + + probeBlockStart(); + + initsize = log->length; + log->data[log->length] = '\0'; // is this necessary ? + size = backtrace(array, MAX_STACK_DEPTH); + if(likely(size > TRIM_STACK_DEPTH)) + { + strings = BACKTRACE_SYMBOLS(array + TRIM_STACK_DEPTH, size - TRIM_STACK_DEPTH); + + if(likely(strings != NULL)) + { + for(i = TRIM_STACK_DEPTH; i < size; i++) + { + stringlen = strlen(strings[i - TRIM_STACK_DEPTH]) + 14; + if(log->length + stringlen >= bufsize + initsize) + break; + + log->length += sprintf(log->data + log->length, "%010u`,%s`,", (unsigned int)(array[i]), strings[i - TRIM_STACK_DEPTH]); + } + log->data[log->length-2] = '\0'; + log->length -= 2; + free(strings); + } + else // failed to get backtrace symbols + { + // just print trace address + for(i = TRIM_STACK_DEPTH; i < size; i++) + { + stringlen = 23; + if(log->length + stringlen >= bufsize + initsize) + break; + + log->length += sprintf(log->data + log->length, "%010u`,(unknown)`,", (unsigned int)(array[i])); + } + log->data[log->length-2] = '\0'; + log->length -= 2; + } + + probeBlockEnd(); + return (int)(size - TRIM_STACK_DEPTH); + } + else + { + probeBlockEnd(); + return 0; + } +} + +/************************************************************************* + * probe block control functions + *************************************************************************/ +int preBlockBegin(void* caller, bool bFiltering, enum DaOptions option) +{ + bool user = false; + void* tarray[1]; + char** strings; + + if(gProbeBlockCount != 0 || gProbeDepth != 0) + return 0; + + if(gTraceInfo.init_complete <= 0) + return 0; + + if((gTraceInfo.optionflag & option) == 0) + return 0; + + probeBlockStart(); + + if(gTraceInfo.exec_map.map_start != NULL) + { + // address comparison + if(caller >= gTraceInfo.exec_map.map_start && + caller <= gTraceInfo.exec_map.map_end) + { + user = true; + } + else + { + // nothing to do + } + } + else + { + // backtrace for filtering + tarray[0] = caller; + strings = BACKTRACE_SYMBOLS(tarray, 1); + if(strings != NULL) + { + if((determineCaller(strings[0]) == 0)) + user = true; + free(strings); + } + else + { + // nothing to do + } + } + + if(user) + { + probingStart(); + return 2; // user call + } + else + { + if(bFiltering) + { + probeBlockEnd(); + return 0; // not probing + } + else + { + probingStart(); + return 1; // internal call + } + } +} + +int postBlockBegin(int preresult) +{ + if(preresult) + { + probeBlockStart(); + } + + return preresult; +} + +void preBlockEnd() +{ + probeBlockEnd(); +} + +void postBlockEnd() +{ + probingEnd(); + probeBlockEnd(); +} + +/************************************************************************* + * helper info getter functions + *************************************************************************/ +// return current time in 1/10000 sec unit +unsigned long getCurrentTime() +{ + struct timeval cTime; + + gettimeofday(&cTime, NULL); + + return (unsigned long)((cTime.tv_sec * 10000 + (cTime.tv_usec/100))); +} + +unsigned int getCurrentEventIndex() +{ + return gTraceInfo.index.eventIndex; +} + +/************************************************************************ + * probe functions + ************************************************************************/ +bool setProbePoint(probeInfo_t* iProbe) +{ + if(unlikely(iProbe == NULL)) + { + return false; + } + + probeBlockStart(); + + // atomic operaion(gcc builtin) is more expensive then pthread_mutex + real_pthread_mutex_lock(&(gTraceInfo.index.eventMutex)); + iProbe->eventIndex = gTraceInfo.index.eventIndex++; + real_pthread_mutex_unlock(&(gTraceInfo.index.eventMutex)); + + iProbe->currentTime = getCurrentTime(); + iProbe->pID = getpid(); + iProbe->tID = _gettid(); + iProbe->callDepth = gProbeDepth; + + probeBlockEnd(); + return true; +} + +// update heap memory size through socket +// return 0 if size is updated through socket +// return 1 if size is updated into global variable +int update_heap_memory_size(bool isAdd, size_t size) +{ + long tmp; + if(isAdd) + { + tmp = __sync_add_and_fetch(&g_total_alloc_size, (long)size); + } + else + { + tmp = __sync_sub_and_fetch(&g_total_alloc_size, (long)size); + } + + return 0; +} + + diff --git a/helper/private_link.h b/helper/private_link.h new file mode 100644 index 0000000..443d911 --- /dev/null +++ b/helper/private_link.h @@ -0,0 +1,374 @@ +/* Data structure for communication from the run-time dynamic linker for + loaded ELF shared objects. + Copyright (C) 1995-2006, 2007 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#ifndef _PRIVATE_LINK_H +#define _PRIVATE_LINK_H 1 + +#ifdef _LINK_H +# error this should be impossible +#endif + +/* Get most of the contents from the public header, but we define a + different `struct link_map' type for private use. The la_objopen + prototype uses the type, so we have to declare it separately. */ +#define link_map link_map_public +#define la_objopen la_objopen_wrongproto +#include +#undef link_map +#undef la_objopen + +struct link_map; +extern unsigned int la_objopen (struct link_map *__map, Lmid_t __lmid, uintptr_t *__cookie); + +#include // for ptrdiff_t +//#include +//#include + +/* Number of extra dynamic section entries for this architecture. + By default there are none. */ +#define DT_THISPROCNUM 0 + +// The type of the return value of fixup/profile_fixup. +#define DL_FIXUP_VALUE_TYPE ElfW(Addr) +// Construct a value of type DL_FIXUP_VALUE_TYPE from a code address and a link map. +#define DL_FIXUP_MAKE_VALUE(map, addr) (addr) +// Extract the code address from a value of type DL_FIXUP_MAKE_VALUE. +#define DL_FIXUP_VALUE_CODE_ADDR(value) (value) +#define DL_FIXUP_VALUE_ADDR(value) (value) +#define DL_FIXUP_ADDR_VALUE(addr) (addr) + +struct link_map_machine +{ + // empty by default +}; + +/* Some internal data structures of the dynamic linker used in the + linker map. We only provide forward declarations. */ + +/* For the version handling we need an array with only names and their + hash values. */ +struct r_found_version +{ + const char *name; + ElfW(Word) hash; + int hidden; + const char *filename; +}; + +/* We want to cache information about the searches for shared objects. */ + +enum r_dir_status { unknown, nonexisting, existing }; + +struct r_search_path_elem +{ + /* This link is only used in the `all_dirs' member of `r_search_path'. */ + struct r_search_path_elem *next; + + /* Strings saying where the definition came from. */ + const char *what; + const char *where; + + /* Basename for this search path element. The string must end with a slash character. */ + const char *dirname; + size_t dirnamelen; + + enum r_dir_status status[0]; +}; + +/* A data structure for a simple single linked list of strings. */ +struct libname_list +{ + const char *name; /* Name requested (before search). */ + struct libname_list *next; /* Link to next name for this object. */ + int dont_free; /* Flag whether this element should be freed + if the object is not entirely unloaded. */ +}; + +/* Forward declaration. */ +struct link_map; + +/* Structure to describe a single list of scope elements. The lookup + functions get passed an array of pointers to such structures. */ +struct r_scope_elem +{ + /* Array of maps for the scope. */ + struct link_map **r_list; + /* Number of entries in the scope. */ + unsigned int r_nlist; +}; + + +/* Structure to record search path and allocation mechanism. */ +struct r_search_path_struct +{ + struct r_search_path_elem **dirs; + int malloced; +}; + + +/* Structure describing a loaded shared object. The `l_next' and `l_prev' + members form a chain of all the shared objects loaded at startup. + + These data structures exist in space used by the run-time dynamic linker; + modifying them may have disastrous results. + + This data structure might change in future, if necessary. User-level + programs must avoid defining objects of this type. */ + +struct link_map + { + /* These first few members are part of the protocol with the debugger. + This is the same format used in SVR4. */ + + ElfW(Addr) l_addr; /* Base address shared object is loaded at. */ + char *l_name; /* Absolute file name object was found in. */ + ElfW(Dyn) *l_ld; /* Dynamic section of the shared object. */ + struct link_map *l_next, *l_prev; /* Chain of loaded objects. */ + + /* All following members are internal to the dynamic linker. + They may change without notice. */ + + /* This is an element which is only ever different from a pointer to + the very same copy of this type for ld.so when it is used in more + than one namespace. */ + struct link_map *l_real; + + /* Number of the namespace this link map belongs to. */ + Lmid_t l_ns; + + struct libname_list *l_libname; + /* Indexed pointers to dynamic section. + [0,DT_NUM) are indexed by the processor-independent tags. + [DT_NUM,DT_NUM+DT_THISPROCNUM) are indexed by the tag minus DT_LOPROC. + [DT_NUM+DT_THISPROCNUM,DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM) are + indexed by DT_VERSIONTAGIDX(tagvalue). + [DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM, + DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM+DT_EXTRANUM) are indexed by + DT_EXTRATAGIDX(tagvalue). + [DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM+DT_EXTRANUM, + DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM+DT_EXTRANUM+DT_VALNUM) are + indexed by DT_VALTAGIDX(tagvalue) and + [DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM+DT_EXTRANUM+DT_VALNUM, + DT_NUM+DT_THISPROCNUM+DT_VERSIONTAGNUM+DT_EXTRANUM+DT_VALNUM+DT_ADDRNUM) + are indexed by DT_ADDRTAGIDX(tagvalue), see . */ + + ElfW(Dyn) *l_info[DT_NUM + DT_THISPROCNUM + DT_VERSIONTAGNUM + + DT_EXTRANUM + DT_VALNUM + DT_ADDRNUM]; + const ElfW(Phdr) *l_phdr; /* Pointer to program header table in core. */ + ElfW(Addr) l_entry; /* Entry point location. */ + ElfW(Half) l_phnum; /* Number of program header entries. */ + ElfW(Half) l_ldnum; /* Number of dynamic segment entries. */ + + /* Array of DT_NEEDED dependencies and their dependencies, in + dependency order for symbol lookup (with and without + duplicates). There is no entry before the dependencies have + been loaded. */ + struct r_scope_elem l_searchlist; + + /* We need a special searchlist to process objects marked with + DT_SYMBOLIC. */ + struct r_scope_elem l_symbolic_searchlist; + + /* Dependent object that first caused this object to be loaded. */ + struct link_map *l_loader; + + /* Array with version names. */ + struct r_found_version *l_versions; + unsigned int l_nversions; + + /* Symbol hash table. */ + Elf_Symndx l_nbuckets; + Elf32_Word l_gnu_bitmask_idxbits; + Elf32_Word l_gnu_shift; + const ElfW(Addr) *l_gnu_bitmask; + union + { + const Elf32_Word *l_gnu_buckets; + const Elf_Symndx *l_chain; + }; + union + { + const Elf32_Word *l_gnu_chain_zero; + const Elf_Symndx *l_buckets; + }; + + unsigned int l_direct_opencount; /* Reference count for dlopen/dlclose. */ + enum /* Where this object came from. */ + { + lt_executable, /* The main executable program. */ + lt_library, /* Library needed by main executable. */ + lt_loaded /* Extra run-time loaded shared object. */ + } l_type:2; + unsigned int l_relocated:1; /* Nonzero if object's relocations done. */ + unsigned int l_init_called:1; /* Nonzero if DT_INIT function called. */ + unsigned int l_global:1; /* Nonzero if object in _dl_global_scope. */ + unsigned int l_reserved:2; /* Reserved for internal use. */ + unsigned int l_phdr_allocated:1; /* Nonzero if the data structure pointed + to by `l_phdr' is allocated. */ + unsigned int l_soname_added:1; /* Nonzero if the SONAME is for sure in + the l_libname list. */ + unsigned int l_faked:1; /* Nonzero if this is a faked descriptor + without associated file. */ + unsigned int l_need_tls_init:1; /* Nonzero if GL(dl_init_static_tls) + should be called on this link map + when relocation finishes. */ + unsigned int l_used:1; /* Nonzero if the DSO is used. */ + unsigned int l_auditing:1; /* Nonzero if the DSO is used in auditing. */ + unsigned int l_audit_any_plt:1; /* Nonzero if at least one audit module + is interested in the PLT interception.*/ + unsigned int l_removed:1; /* Nozero if the object cannot be used anymore + since it is removed. */ + unsigned int l_contiguous:1; /* Nonzero if inter-segment holes are + mprotected or if no holes are present at + all. */ + + /* Collected information about own RPATH directories. */ + struct r_search_path_struct l_rpath_dirs; + + /* Collected results of relocation while profiling. */ + struct reloc_result + { + DL_FIXUP_VALUE_TYPE addr; + struct link_map *bound; + unsigned int boundndx; + uint32_t enterexit; + unsigned int flags; + } *l_reloc_result; + + /* Pointer to the version information if available. */ + ElfW(Versym) *l_versyms; + + /* String specifying the path where this object was found. */ + const char *l_origin; + + /* Start and finish of memory map for this object. l_map_start + need not be the same as l_addr. */ + ElfW(Addr) l_map_start, l_map_end; + /* End of the executable part of the mapping. */ + ElfW(Addr) l_text_end; + + /* Default array for 'l_scope'. */ + struct r_scope_elem *l_scope_mem[4]; + /* Size of array allocated for 'l_scope'. */ + size_t l_scope_max; + /* This is an array defining the lookup scope for this link map. + There are initially at most three different scope lists. */ + struct r_scope_elem **l_scope; + + /* A similar array, this time only with the local scope. This is + used occasionally. */ + struct r_scope_elem *l_local_scope[2]; + + /* This information is kept to check for sure whether a shared + object is the same as one already loaded. */ + dev_t l_dev; + ino64_t l_ino; + + /* Collected information about own RUNPATH directories. */ + struct r_search_path_struct l_runpath_dirs; + + /* List of object in order of the init and fini calls. */ + struct link_map **l_initfini; + + /* List of the dependencies introduced through symbol binding. */ + unsigned int l_reldepsmax; + struct link_map_reldeps + { + unsigned int act; + struct link_map *list[]; + } *l_reldeps; + + /* Various flag words. */ + ElfW(Word) l_feature_1; + ElfW(Word) l_flags_1; + ElfW(Word) l_flags; + + /* Temporarily used in `dl_close'. */ + int l_idx; + + struct link_map_machine l_mach; + + struct + { + const ElfW(Sym) *sym; + int type_class; + struct link_map *value; + const ElfW(Sym) *ret; + } l_lookup_cache; + + /* Thread-local storage related info. */ + + /* Start of the initialization image. */ + void *l_tls_initimage; + /* Size of the initialization image. */ + size_t l_tls_initimage_size; + /* Size of the TLS block. */ + size_t l_tls_blocksize; + /* Alignment requirement of the TLS block. */ + size_t l_tls_align; + /* Offset of first byte module alignment. */ + size_t l_tls_firstbyte_offset; +#ifndef NO_TLS_OFFSET +# define NO_TLS_OFFSET 0 +#endif +#ifndef FORCED_DYNAMIC_TLS_OFFSET +# if NO_TLS_OFFSET == 0 +# define FORCED_DYNAMIC_TLS_OFFSET 1 +# elif NO_TLS_OFFSET == -1 +# define FORCED_DYNAMIC_TLS_OFFSET -2 +# else +# error "FORCED_DYNAMIC_TLS_OFFSET is not defined" +# endif +#endif + /* For objects present at startup time: offset in the static TLS block. */ + ptrdiff_t l_tls_offset; + /* Index of the module in the dtv array. */ + size_t l_tls_modid; + + /* Information used to change permission after the relocations are + done. */ + ElfW(Addr) l_relro_addr; + size_t l_relro_size; + + unsigned long long int l_serial; + + /* Audit information. This array apparent must be the last in the + structure. Never add something after it. */ + struct auditstate + { + uintptr_t cookie; + unsigned int bindflags; + } l_audit[0]; + }; + + +#if __ELF_NATIVE_CLASS == 32 +# define symbind symbind32 +#elif __ELF_NATIVE_CLASS == 64 +# define symbind symbind64 +#else +# error "__ELF_NATIVE_CLASS must be defined" +#endif + +extern int __dl_iterate_phdr (int (*callback) (struct dl_phdr_info *info, + size_t size, void *data), + void *data); + +#endif /* include/link.h */ diff --git a/include/dacollection.h b/include/dacollection.h new file mode 100755 index 0000000..94af344 --- /dev/null +++ b/include/dacollection.h @@ -0,0 +1,148 @@ +/* + * DA probe + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Jaewon Lim + * Woojin Jung + * Juyoung Kim + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#ifndef __COLLECTIONS_H__ +#define __COLLECTIONS_H__ + +#include // for pthread_mutex_t + +#include "khash.h" + +#ifdef __cplusplus +extern "C"{ +#endif + +#define SYMBOLHASH _hashinfo.symHash +#define SYMBOLHASH_LOCK pthread_mutex_lock(&(_hashinfo.symHashMutex)) +#define SYMBOLHASH_UNLOCK pthread_mutex_unlock(&(_hashinfo.symHashMutex)) + +#define MEMORYHASH _hashinfo.memHash +#define MEMORYHASH_LOCK pthread_mutex_lock(&(_hashinfo.memHashMutex)) +#define MEMORYHASH_UNLOCK pthread_mutex_unlock(&(_hashinfo.memHashMutex)) + +#define UIOBJECTHASH _hashinfo.uiobjHash +#define UIOBJECTHASH_LOCK pthread_mutex_lock(&(_hashinfo.uiobjHashMutex)) +#define UIOBJECTHASH_UNLOCK pthread_mutex_unlock(&(_hashinfo.uiobjHashMutex)) + +#define OBJECTHASH _hashinfo.objHash +#define OBJECTHASH_LOCK pthread_mutex_lock(&(_hashinfo.objHashMutex)) +#define OBJECTHASH_UNLOCK pthread_mutex_unlock(&(_hashinfo.objHashMutex)) + +#define DETECTORHASH _hashinfo.dttHash +#define DETECTORHASH_LOCK pthread_mutex_lock(&(_hashinfo.dttHashMutex)) +#define DETECTORHASH_UNLOCK pthread_mutex_unlock(&(_hashinfo.dttHashMutex)) + +#define MEMTYPE_ALLOC 0x01 +#define MEMTYPE_FREE 0x01 +#define MEMTYPE_NEW 0x03 +#define MEMTYPE_DELETE 0x03 + +#define MEM_INTERNAL 0x01 +#define MEM_EXTERNAL 0x02 + +#define MEMMASK_CALLER 0xFFFF000000000000L +#define MEMMASK_TYPE 0x0000FFFF00000000L +#define MEMMASK_SIZE 0x00000000FFFFFFFFL + +#define GET_MEMSIZE(_info) ((size_t)(_info & MEMMASK_SIZE)) +#define GET_MEMCALLER(_info) ((unsigned short)((_info & MEMMASK_CALLER) >> 48)) +#define GET_MEMTYPE(_info) ((unsigned short)((_info & MEMMASK_TYPE) >> 32)) + +#define MAKE_MEMINFO(caller, type, size) \ + (((uint64_t)caller << 48) | ((uint64_t)type << 32) | ((uint64_t)size)) + +#define OBJECT_INTERNAL 0x01 +#define OBJECT_EXTERNAL 0x02 + +typedef struct +{ + char* type; + char* name; +} _uiobjectinfo; + +// khash table function definition +KHASH_MAP_INIT_INT(symbol, char*) + +KHASH_MAP_INIT_INT(allocmap, uint64_t) + +KHASH_MAP_INIT_INT(uiobject, _uiobjectinfo*) + +KHASH_MAP_INIT_INT(object, unsigned short) + +KHASH_MAP_INIT_INT(detector, void*) + +typedef struct +{ + khash_t(symbol)* symHash; + pthread_mutex_t symHashMutex; + khash_t(allocmap)* memHash; + pthread_mutex_t memHashMutex; + khash_t(uiobject)* uiobjHash; + pthread_mutex_t uiobjHashMutex; + khash_t(object)* objHash; + pthread_mutex_t objHashMutex; + khash_t(detector)* dttHash; + pthread_mutex_t dttHashMutex; +} __hashInfo; + +extern __hashInfo _hashinfo; + +// APIs for symdata linked list +int add_to_glist(char* key, void* data); +int remove_from_glist(char* key); +int remove_all_glist(); +void* find_glist(char* key); + +// APIs for hash table +int initialize_hash_table(); +int finalize_hash_table(); + +int find_symbol_hash(void* ptr, char** psymbol); +int add_symbol_hash(void* ptr, const char* str, int strlen); +int add_memory_hash(void* ptr, size_t size, unsigned short type, unsigned short caller); +int del_memory_hash(void* ptr, unsigned short type, unsigned short* caller); + +int find_uiobject_hash(void* ptr, char** type, char** classname); +int add_uiobject_hash_class(void* ptr, const char* classname); +int add_uiobject_hash_type(void* ptr, const char* type); +int del_uiobject_hash(void* ptr); + +int find_object_hash(void* ptr, unsigned short *caller); +int add_object_hash(void* ptr, unsigned short caller); +int del_object_hash(void* ptr, unsigned short *caller); + +int add_detector_hash(void* ptr, void* listener); +int del_detector_hash(void* ptr); + +#ifdef __cplusplus +} +#endif + +#endif /* __COLLECTIONS_H_ */ diff --git a/include/daerror.h b/include/daerror.h new file mode 100755 index 0000000..9eade26 --- /dev/null +++ b/include/daerror.h @@ -0,0 +1,54 @@ +/* DA probe + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Jaewon Lim + * Woojin Jung + * Juyoung Kim + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#ifndef DAERROR_H_ +#define DAERROR_H_ + +#ifdef __cplusplus +extern "C"{ +#endif + +#define ERR_SUCCESS 0 +#define ERR_OUTOFMEMORY -11 +#define ERR_WRONGPARAMETER -12 +#define ERR_NOTINITIALIZED -13 +#define ERR_NOTEXIST -21 +#define ERR_ALREADYEXIST -22 +#define ERR_OTHER -30 +#define ERR_DLOPEN -101 +#define ERR_DLSYM -102 +#define ERR_USER -10000 + + +#ifdef __cplusplus +} +#endif + + +#endif /* DAERROR_H_ */ diff --git a/include/dahelper.h b/include/dahelper.h new file mode 100755 index 0000000..a730f06 --- /dev/null +++ b/include/dahelper.h @@ -0,0 +1,237 @@ +/* + * DA probe + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Jaewon Lim + * Woojin Jung + * Juyoung Kim + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#ifndef _DAHELPER_H_ +#define _DAHELPER_H_ + +#include +#include // for pthread_mutex_t + +#include + +#include "daprobe.h" + +#ifdef __cplusplus +extern "C"{ +#endif + +#define MAX_PATH_LENGTH 256 +#define MAX_STACK_DEPTH 128 +#define TRIM_STACK_DEPTH 2 + +/* +#define WIN_RENDER_POST 0 +#define CONTROLBAR_RENDER_POST 1 +#define NAVIFRAME_RENDER_POST 2 +#define PAGER_RENDER_POST 3 +#define RENDER_POST_COUNT 4 + +#define SNAPSHOT_WAIT_TIME_MAX 10000 +*/ + +#define ENABLE_INTERNAL_MALLOC 0x0001 +#define ENABLE_SNAPSHOT 0x0002 + +#define LOG(FORMAT, ...) \ + do { \ + char buf[128]; \ + sprintf(buf, FORMAT, __VA_ARGS__); \ + PRINTMSG(buf); \ + } while(0) \ + +#define SCREENSHOT_LOCK() \ + do { \ + int old; \ + pthread_mutex_lock(&(gTraceInfo.screenshot.ssMutex)); \ + old = gTraceInfo.screenshot.state; \ + gTraceInfo.screenshot.state = -1; \ + pthread_mutex_unlock(&(gTraceInfo.screenshot.ssMutex)); \ + if(old > 0) { \ + if(isOptionEnabled(OPT_SNAPSHOT)) \ + captureScreen(); \ + } \ + } while(0) + +#define SCREENSHOT_UNLOCK() \ + do { \ + pthread_mutex_lock(&(gTraceInfo.screenshot.ssMutex)); \ + if(gTraceInfo.screenshot.state < 0) \ + gTraceInfo.screenshot.state = 1; \ + pthread_mutex_unlock(&(gTraceInfo.screenshot.ssMutex)); \ + } while(0) + +#define SCREENSHOT_SET() \ + do { \ + int old; \ + pthread_mutex_lock(&(gTraceInfo.screenshot.ssMutex)); \ + old = gTraceInfo.screenshot.state; \ + if(gTraceInfo.screenshot.state >= 0) \ + gTraceInfo.screenshot.state = 1; \ + pthread_mutex_unlock(&(gTraceInfo.screenshot.ssMutex)); \ + if(old == 2) { \ + if(isOptionEnabled(OPT_SNAPSHOT)) \ + captureScreen(); \ + } \ + } while(0) + +#define SCREENSHOT_UNSET() \ + do { \ + pthread_mutex_lock(&(gTraceInfo.screenshot.ssMutex)); \ + if(gTraceInfo.screenshot.state >= 0) \ + gTraceInfo.screenshot.state = 0; \ + pthread_mutex_unlock(&(gTraceInfo.screenshot.ssMutex)); \ + } while(0) + +#define SCREENSHOT_DONE() \ + do { \ + int old; \ + pthread_mutex_lock(&(gTraceInfo.screenshot.ssMutex)); \ + old = gTraceInfo.screenshot.state; \ + if(gTraceInfo.screenshot.state == 1) \ + gTraceInfo.screenshot.state = 2; \ + pthread_mutex_unlock(&(gTraceInfo.screenshot.ssMutex)); \ + if(old == 1) { \ + activateCaptureTimer(); \ + } \ + } while(0) + +#define SCREENSHOT_TIMEOUT() \ + do { \ + int old; \ + pthread_mutex_lock(&(gTraceInfo.screenshot.ssMutex)); \ + old = gTraceInfo.screenshot.state; \ + if(gTraceInfo.screenshot.state == 2) \ + gTraceInfo.screenshot.state = 0; \ + pthread_mutex_unlock(&(gTraceInfo.screenshot.ssMutex)); \ + if(old == 2) { \ + if(isOptionEnabled(OPT_SNAPSHOT)) \ + captureScreen(); \ + } \ + } while(0) + +#define NUM_ORIGINAL_LIBRARY 9 + +typedef enum +{ + LIBC = 0, + LIBPTHREAD = 1, + LIBELEMENTARY = 2, + LIBOSP_UIFW = 3, + LIBOSP_APPFW = 4, + LIBOSP_WEB = 5, + LIBECORE_INPUT_EVAS = 6, + LIBDAEMON = 7, + LIBCAPI_APPFW_APPLICATION = 8 +} ORIGINAL_LIBRARY; + +extern char *lib_string[NUM_ORIGINAL_LIBRARY]; +extern void *lib_handle[NUM_ORIGINAL_LIBRARY]; + +// type definition for global variable +typedef struct +{ + int eventIndex; + pthread_mutex_t eventMutex; +} __indexInfo; + +typedef struct +{ + int daemonSock; + pthread_mutex_t sockMutex; +} __socketInfo; + +typedef struct +{ + char appName[128]; + unsigned int startTime; +} __appInfo; + +typedef struct +{ + int state; + pthread_mutex_t ssMutex; +} __screenshotInfo; + +typedef struct +{ + void* map_start; + void* map_end; +} __mapInfo; + +typedef struct +{ + __indexInfo index; + __socketInfo socket; + __appInfo app; + __screenshotInfo screenshot; + __mapInfo exec_map; + int stateTouch; + int init_complete; + int custom_chart_callback_count; + unsigned long optionflag; +} __traceInfo; + +extern __traceInfo gTraceInfo; + +int get_map_address(void* symbol, void** map_start, void** map_end); +char** da_backtrace_symbols (void* const* array, int size); +char** cached_backtrace_symbols (void* const* array, int size); + +// profil turned on +int __profil(int mode); + +//wchar_t* -> char* +void WcharToChar(char* pstrDest, const wchar_t* pwstrSrc); + +void application_exit(); + +// screen capture functions +int initialize_screencapture(); +int finalize_screencapture(); +int captureScreen(); +int activateCaptureTimer(); +void _cb_render_post(void* data, Evas* e, void* eventinfo); + +// event related functions +int initialize_event(); +int finalize_event(); +int getOrientation(); +void on_orientation_changed(int angle, bool capi); + +int remove_indir(const char* dirname); + +// query functions +#define isOptionEnabled(OPT) ((gTraceInfo.optionflag & OPT) != 0) + +#ifdef __cplusplus +} +#endif + +#endif // _DAHELPER_H_ diff --git a/include/daprobe.h b/include/daprobe.h new file mode 100644 index 0000000..a07de38 --- /dev/null +++ b/include/daprobe.h @@ -0,0 +1,363 @@ +/* + * DA probe + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Jaewon Lim + * Woojin Jung + * Juyoung Kim + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#ifndef __DAPROBE_H__ +#define __DAPROBE_H__ + +#include +#include +#include +#include +#include "probeinfo.h" + +#ifdef __cplusplus +extern "C"{ +#endif + +#ifndef likely +#define likely(x) __builtin_expect((x),1) +#define unlikely(x) __builtin_expect((x),0) +#endif + +#define NUM_OF_MONITOR 3 +#define DA_LOG_MAX 4096 +#define PERROR_MSG_MAX 128 + +#define DEFAULT_TOKEN "`," + +#define CALLER_ADDRESS \ + ((void*) __builtin_extract_return_addr(__builtin_return_address(0))) + +#define BACKTRACE_SYMBOLS cached_backtrace_symbols + +typedef enum +{ + MT_MEMORY, + MT_FILE, + MT_SOCKET, +} MonitorType; + +enum BlockLocation +{ + BL_PRE, + BL_POST, +}; + +typedef struct +{ + int type; + int length; + char data[DA_LOG_MAX]; +} log_t; + +typedef struct +{ + int eventIndex; + int pID; + int tID; + unsigned long currentTime; + unsigned int callDepth; +} probeInfo_t; + +extern __thread int gProbeBlockCount; +extern __thread int gProbeDepth; + +#define probeBlockStart() (gProbeBlockCount++) +#define probeBlockEnd() (gProbeBlockCount--) +#define probingStart() (gProbeDepth++) +#define probingEnd() (gProbeDepth--) + +/*************************************************************************** + * helper apis + ***************************************************************************/ + +int preBlockBegin(void* caller, bool bFiltering, enum DaOptions); +void preBlockEnd(); + +int postBlockBegin(int preresult); +void postBlockEnd(); + +unsigned int getCurrentEventIndex(); +unsigned long getCurrentTime(); +bool setProbePoint(probeInfo_t * iProbe); +int update_heap_memory_size(bool isAdd, size_t size); + +bool printLogStr(const char* str, int msgType); +bool printLog(log_t* log, int msgType); +int __appendTypeLog(log_t* log, int nInput, char* token, ...); +int getBacktraceString(log_t* log, int bufsize); + +//char* captureScreenShotX(int* width, int* height); +//void releaseScreenShotX(); + +//int printSamplingLog(void); + +//bool captureScreen(unsigned int logNum); +//void captureProbe(); +//int registeScreenChange(int renderID); +//void detectTouchEvent(int touchID); +//int getTouchState(); +//int isPossibleCapture(); + + +/*************************************************************************** + * helper macros + ***************************************************************************/ + +// ========================= print log ===================================== +#define PRINTMSG(msg) printLogStr(msg, MSG_MSG) + +// =========================== declare variables =========================== +// local variable is faster than heap allocated variable +// array variable initialization with declare is expensive than memset +#define DECLARE_COMMON_VARIABLE \ + probeInfo_t probeInfo; \ + log_t log + +// declare variable for standard api (not tizen related api) +#define DECLARE_VARIABLE_STANDARD \ + DECLARE_COMMON_VARIABLE; \ + int blockresult; \ + bool bfiltering = true; \ + int olderrno, newerrno; \ + int __attribute__((unused)) ret + +// ========================== initialize variable ========================== + +#define INIT_LOG \ + log.type = 0; \ + log.length = 0; \ + log.data[0] = '\0' + +// ========================== get function pointer ========================= + +#define GET_REAL_FUNCP(FUNCNAME, SONAME, FUNCTIONPOINTER) \ + do { \ + if(!FUNCTIONPOINTER) { \ + probeBlockStart(); \ + if(lib_handle[SONAME] == NULL) { \ + lib_handle[SONAME] = dlopen(lib_string[SONAME], RTLD_LAZY); \ + if(lib_handle[SONAME] == NULL) { \ + char perror_msg[PERROR_MSG_MAX]; \ + sprintf(perror_msg, "dlopen failed : %s", lib_string[SONAME]); \ + perror(perror_msg); \ + exit(0); \ + } \ + } \ + FUNCTIONPOINTER = dlsym(lib_handle[SONAME], #FUNCNAME); \ + if(FUNCTIONPOINTER == NULL || dlerror() != NULL) { \ + perror("dlsym failed : " #FUNCNAME); \ + exit(0); \ + } \ + probeBlockEnd(); \ + } \ + } while(0) + +#define GET_REAL_FUNC(FUNCNAME, SONAME) \ + GET_REAL_FUNCP(FUNCNAME, SONAME, FUNCNAME##p) + +#define GET_REAL_FUNCP_RTLD_NEXT(FUNCNAME, FUNCTIONPOINTER) \ + do { \ + if(!FUNCTIONPOINTER) { \ + probeBlockStart(); \ + FUNCTIONPOINTER = dlsym(RTLD_NEXT, #FUNCNAME); \ + if(FUNCTIONPOINTER == NULL || dlerror() != NULL) { \ + perror("dlsym failed"); \ + exit(0); \ + } \ + probeBlockEnd(); \ + } \ + } while(0) + +#define GET_REAL_FUNC_RTLD_NEXT(FUNCNAME) \ + GET_REAL_FUNCP_RTLD_NEXT(FUNCNAME, FUNCNAME##p) + +#define GET_REAL_FUNCP_RTLD_NEXT_CPP(FUNCNAME, FUNCTIONPOINTER) \ + do { \ + if(!FUNCTIONPOINTER) { \ + probeBlockStart(); \ + void* funcp = dlsym(RTLD_NEXT, #FUNCNAME); \ + if(funcp == NULL || dlerror() != NULL) { \ + perror("dlsym failed : " #FUNCNAME); \ + exit(0); \ + } \ + memcpy(&FUNCTIONPOINTER, &funcp, sizeof(void*)); \ + probeBlockEnd(); \ + } \ + } while(0) + +#define GET_REAL_FUNC_RTLD_NEXT_CPP(FUNCNAME) \ + GET_REAL_FUNCP_RTLD_NEXT_CPP(FUNCNAME, FUNCNAME##p) + +// ======================= pre block macro ================================ + +#define PRE_PROBEBLOCK_BEGIN() \ + if((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { \ + setProbePoint(&probeInfo) + +#define PRE_PROBEBLOCK_END() \ + preBlockEnd(); \ + } \ + olderrno = errno; \ + errno = 0 + +#define PRE_PROBEBLOCK() \ + PRE_PROBEBLOCK_BEGIN(); \ + PRE_PROBEBLOCK_END() + +// ========================== make log macro ================================ +#define APPEND_LOG_BASIC(LCTYPE) \ + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", \ + LCTYPE, probeInfo.eventIndex, __func__, \ + probeInfo.currentTime, probeInfo.pID, probeInfo.tID) + +#define APPEND_LOG_BASIC_NAME(LCTYPE, APINAME) \ + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", \ + LCTYPE, probeInfo.eventIndex, APINAME, \ + probeInfo.currentTime, probeInfo.pID, probeInfo.tID) + +#define APPEND_LOG_COMMON_NONE(CALLER) \ + log.length += sprintf(log.data + log.length, "`,`,`,`,`,`,%u", \ + (unsigned int)CALLER) + +#define APPEND_LOG_INPUT(INPUTFORMAT, ...) \ + log.length += sprintf(log.data + log.length, \ + DEFAULT_TOKEN INPUTFORMAT, __VA_ARGS__) + +#define APPEND_LOG_RESULT(RETTYPE, RETVALUE) \ + __appendTypeLog(&log, 4, NULL, RETTYPE, RETVALUE, VT_INT, 0, \ + VT_INT, newerrno, VT_INT, blockresult) + +#define APPEND_LOG_CALLER() \ + log.length += sprintf(log.data + log.length, \ + "`,%u",(unsigned int) CALLER_ADDRESS) + +#if defined(USING_BACKTRACE) || defined(PRINT_BACKTRACE_CALLSTACK) +#define APPEND_LOG_CALLSTACK() \ + log.length += sprintf(log.data + log.length, \ + "`,\ncallstack_start`,"); \ + getBacktraceString(&log, DA_LOG_MAX - log.length - 17); \ + log.length += sprintf(log.data + log.length, "`,callstack_end") +#else +#define APPEND_LOG_CALLSTACK() APPEND_LOG_NULL_CALLSTACK() +#endif + +#define APPEND_LOG_NULL_CALLSTACK() \ + log.length += sprintf(log.data + log.length, \ + "`,\ncallstack_start`,`,callstack_end") + + +// =========================== post block macro =========================== + +#define POST_PROBEBLOCK_BEGIN(LCTYPE, RETTYPE, RETVALUE, INPUTFORMAT, ...) \ + newerrno = errno; \ + if(postBlockBegin(blockresult)) { \ + INIT_LOG; \ + APPEND_LOG_BASIC(LCTYPE); \ + APPEND_LOG_INPUT(INPUTFORMAT, __VA_ARGS__); \ + APPEND_LOG_RESULT(RETTYPE, RETVALUE); \ + APPEND_LOG_CALLER() + +#define POST_PROBEBLOCK_CALLSTACK() \ + do { \ + if(newerrno != 0) { \ + APPEND_LOG_CALLSTACK(); \ + } else { \ + APPEND_LOG_NULL_CALLSTACK(); \ + } \ + } while(0) + + +#define POST_PROBEBLOCK_END() \ + printLog(&log, MSG_LOG); \ + postBlockEnd(); \ + } \ + errno = (newerrno != 0) ? newerrno : olderrno + +// ====================== start/end pre/post block macro ================== + +#define PRE_START_END_PROBEBLOCK_BEGIN(LCTYPE, INPUTFORMAT, ...) \ + PRE_PROBEBLOCK_BEGIN(); \ + INIT_LOG; \ + APPEND_LOG_BASIC(LCTYPE); \ + APPEND_LOG_INPUT(INPUTFORMAT, __VA_ARGS__); \ + log.length += sprintf(log.data + log.length, "`,`,0`,0`,%d", blockresult); \ + APPEND_LOG_CALLER() + +#define POST_START_END_PROBEBLOCK_BEGIN(LCTYPE, RETTYPE, RETVALUE, INPUTFORMAT, ...) \ + newerrno = errno; \ + if(postBlockBegin(blockresult)) { \ + setProbePoint(&probeInfo); \ + INIT_LOG; \ + APPEND_LOG_BASIC(LCTYPE); \ + APPEND_LOG_INPUT(INPUTFORMAT, __VA_ARGS__); \ + APPEND_LOG_RESULT(RETTYPE, RETVALUE); \ + APPEND_LOG_CALLER() + +// ===================== unconditional probe block ======================== + +#define PRE_UNCONDITIONAL_BLOCK_BEGIN() \ + do { \ + probeBlockStart(); \ + setProbePoint(&probeInfo) + +#define PRE_UNCONDITIONAL_BLOCK_END() \ + probeBlockEnd(); \ + } while(0) + +#define POST_UNCONDITIONAL_BLOCK_BEGIN(LCTYPE) \ + do { \ + probeBlockStart(); \ + INIT_LOG; \ + APPEND_LOG_BASIC(LCTYPE) + +#define POST_UNCONDITIONAL_BLOCK_END() \ + printLog(&log, MSG_LOG); \ + probeBlockEnd(); \ + } while(0) + +// ========================= simplify macro ================================ + +#define BEFORE_ORIGINAL(FUNCNAME, LIBNAME) \ + DECLARE_VARIABLE_STANDARD; \ + GET_REAL_FUNC(FUNCNAME, LIBNAME); \ + PRE_PROBEBLOCK() + +#define BEFORE_ORIGINAL_NOFILTER(FUNCNAME, LIBNAME) \ + DECLARE_VARIABLE_STANDARD; \ + GET_REAL_FUNC(FUNCNAME, LIBNAME); \ + bfiltering = false; \ + PRE_PROBEBLOCK() + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/dautil.h b/include/dautil.h new file mode 100644 index 0000000..6751a83 --- /dev/null +++ b/include/dautil.h @@ -0,0 +1,39 @@ +/* + * DA probe + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Jaewon Lim + * Woojin Jung + * Juyoung Kim + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#ifndef __DAUTIL_H__ +#define __DAUTIL_H__ +//#define DA_DEBUG_LOG +#ifdef DA_DEBUG_LOG +#define HEAR() printf("DA: %s:%s:%d: we are here\n", __FILE__, __func__, __LINE__) +#else +#define HEAR() ; +#endif +#endif diff --git a/include/khash.h b/include/khash.h new file mode 100755 index 0000000..3495bdb --- /dev/null +++ b/include/khash.h @@ -0,0 +1,325 @@ +/* The MIT License + + Copyright (c) 2008, by Attractive Chaos + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +/* + An example: + +#include "khash.h" +KHASH_MAP_INIT_INT(32, char) +int main() { + int ret, is_missing; + khiter_t k; + khash_t(32) *h = kh_init(32); + k = kh_put(32, h, 5, &ret); + if (!ret) kh_del(32, h, k); + kh_value(h, k) = 10; + k = kh_get(32, h, 10); + is_missing = (k == kh_end(h)); + k = kh_get(32, h, 5); + kh_del(32, h, k); + for (k = kh_begin(h); k != kh_end(h); ++k) + if (kh_exist(h, k)) kh_value(h, k) = 1; + kh_destroy(32, h); + return 0; +} +*/ + +/* + 2008-09-19 (0.2.3): + + * Corrected the example + * Improved interfaces + + 2008-09-11 (0.2.2): + + * Improved speed a little in kh_put() + + 2008-09-10 (0.2.1): + + * Added kh_clear() + * Fixed a compiling error + + 2008-09-02 (0.2.0): + + * Changed to token concatenation which increases flexibility. + + 2008-08-31 (0.1.2): + + * Fixed a bug in kh_get(), which has not been tested previously. + + 2008-08-31 (0.1.1): + + * Added destructor +*/ + + +#ifndef __AC_KHASH_H +#define __AC_KHASH_H + +#define AC_VERSION_KHASH_H "0.2.2" + +#include +#include +#include +#include + +typedef uint32_t khint_t; +typedef khint_t khiter_t; + +#define __ac_HASH_PRIME_SIZE 32 +static const uint32_t __ac_prime_list[__ac_HASH_PRIME_SIZE] = +{ + 0ul, 3ul, 11ul, 23ul, 53ul, + 97ul, 193ul, 389ul, 769ul, 1543ul, + 3079ul, 6151ul, 12289ul, 24593ul, 49157ul, + 98317ul, 196613ul, 393241ul, 786433ul, 1572869ul, + 3145739ul, 6291469ul, 12582917ul, 25165843ul, 50331653ul, + 100663319ul, 201326611ul, 402653189ul, 805306457ul, 1610612741ul, + 3221225473ul, 4294967291ul +}; + +#define __ac_isempty(flag, i) ((flag[i>>4]>>((i&0xfU)<<1))&2) +#define __ac_isdel(flag, i) ((flag[i>>4]>>((i&0xfU)<<1))&1) +#define __ac_iseither(flag, i) ((flag[i>>4]>>((i&0xfU)<<1))&3) +#define __ac_set_isdel_false(flag, i) (flag[i>>4]&=~(1ul<<((i&0xfU)<<1))) +#define __ac_set_isempty_false(flag, i) (flag[i>>4]&=~(2ul<<((i&0xfU)<<1))) +#define __ac_set_isboth_false(flag, i) (flag[i>>4]&=~(3ul<<((i&0xfU)<<1))) +#define __ac_set_isdel_true(flag, i) (flag[i>>4]|=1ul<<((i&0xfU)<<1)) + +static const double __ac_HASH_UPPER = 0.77; + +#define KHASH_INIT(name, khkey_t, khval_t, kh_is_map, __hash_func, __hash_equal) \ + typedef struct { \ + khint_t n_buckets, size, n_occupied, upper_bound; \ + uint32_t *flags; \ + khkey_t *keys; \ + khval_t *vals; \ + } kh_##name##_t; \ + static inline kh_##name##_t *kh_init_##name() { \ + return (kh_##name##_t*)calloc(1, sizeof(kh_##name##_t)); \ + } \ + static inline void kh_destroy_##name(kh_##name##_t *h) \ + { \ + if (h) { \ + free(h->keys); free(h->flags); \ + free(h->vals); \ + free(h); \ + } \ + } \ + static inline void kh_clear_##name(kh_##name##_t *h) \ + { \ + if (h && h->flags) { \ + memset(h->flags, 0xaa, ((h->n_buckets>>4) + 1) * sizeof(uint32_t)); \ + h->size = h->n_occupied = 0; \ + } \ + } \ + static inline khint_t kh_get_##name(kh_##name##_t *h, khkey_t key) \ + { \ + if (h->n_buckets) { \ + khint_t inc, k, i, last; \ + k = __hash_func(key); i = k % h->n_buckets; \ + inc = 1 + k % (h->n_buckets - 1); last = i; \ + while (!__ac_isempty(h->flags, i) && (__ac_isdel(h->flags, i) || !__hash_equal(h->keys[i], key))) { \ + if (i + inc >= h->n_buckets) i = i + inc - h->n_buckets; \ + else i += inc; \ + if (i == last) return h->n_buckets; \ + } \ + return __ac_iseither(h->flags, i)? h->n_buckets : i; \ + } else return 0; \ + } \ + static inline void kh_resize_##name(kh_##name##_t *h, khint_t new_n_buckets) \ + { \ + uint32_t *new_flags = 0; \ + khint_t j = 1; \ + { \ + khint_t t = __ac_HASH_PRIME_SIZE - 1; \ + while (__ac_prime_list[t] > new_n_buckets) { \ + --t; \ + } \ + new_n_buckets = __ac_prime_list[t+1]; \ + if (h->size >= (khint_t)(new_n_buckets * __ac_HASH_UPPER + 0.5)) j = 0; \ + else { \ + new_flags = (uint32_t*)malloc(((new_n_buckets>>4) + 1) * sizeof(uint32_t)); \ + memset(new_flags, 0xaa, ((new_n_buckets>>4) + 1) * sizeof(uint32_t)); \ + if (h->n_buckets < new_n_buckets) { \ + h->keys = (khkey_t*)realloc(h->keys, new_n_buckets * sizeof(khkey_t)); \ + if (kh_is_map) \ + h->vals = (khval_t*)realloc(h->vals, new_n_buckets * sizeof(khval_t)); \ + } \ + } \ + } \ + if (j) { \ + for (j = 0; j != h->n_buckets; ++j) { \ + if (__ac_iseither(h->flags, j) == 0) { \ + khkey_t key = h->keys[j]; \ + khval_t val; \ + if (kh_is_map) val = h->vals[j]; \ + __ac_set_isdel_true(h->flags, j); \ + while (1) { \ + khint_t inc, k, i; \ + k = __hash_func(key); \ + i = k % new_n_buckets; \ + inc = 1 + k % (new_n_buckets - 1); \ + while (!__ac_isempty(new_flags, i)) { \ + if (i + inc >= new_n_buckets) i = i + inc - new_n_buckets; \ + else i += inc; \ + } \ + __ac_set_isempty_false(new_flags, i); \ + if (i < h->n_buckets && __ac_iseither(h->flags, i) == 0) { \ + { khkey_t tmp = h->keys[i]; h->keys[i] = key; key = tmp; } \ + if (kh_is_map) { khval_t tmp = h->vals[i]; h->vals[i] = val; val = tmp; } \ + __ac_set_isdel_true(h->flags, i); \ + } else { \ + h->keys[i] = key; \ + if (kh_is_map) h->vals[i] = val; \ + break; \ + } \ + } \ + } \ + } \ + if (h->n_buckets > new_n_buckets) { \ + h->keys = (khkey_t*)realloc(h->keys, new_n_buckets * sizeof(khkey_t)); \ + if (kh_is_map) \ + h->vals = (khval_t*)realloc(h->vals, new_n_buckets * sizeof(khval_t)); \ + } \ + free(h->flags); \ + h->flags = new_flags; \ + h->n_buckets = new_n_buckets; \ + h->n_occupied = h->size; \ + h->upper_bound = (khint_t)(h->n_buckets * __ac_HASH_UPPER + 0.5); \ + } \ + } \ + static inline khint_t kh_put_##name(kh_##name##_t *h, khkey_t key, int *ret) \ + { \ + khint_t x; \ + if (h->n_occupied >= h->upper_bound) { \ + if (h->n_buckets > (h->size<<1)) kh_resize_##name(h, h->n_buckets - 1); \ + else kh_resize_##name(h, h->n_buckets + 1); \ + } \ + { \ + khint_t inc, k, i, site, last; \ + x = site = h->n_buckets; k = __hash_func(key); i = k % h->n_buckets; \ + if (__ac_isempty(h->flags, i)) x = i; \ + else { \ + inc = 1 + k % (h->n_buckets - 1); last = i; \ + while (!__ac_isempty(h->flags, i) && (__ac_isdel(h->flags, i) || !__hash_equal(h->keys[i], key))) { \ + if (__ac_isdel(h->flags, i)) site = i; \ + if (i + inc >= h->n_buckets) i = i + inc - h->n_buckets; \ + else i += inc; \ + if (i == last) { x = site; break; } \ + } \ + if (x == h->n_buckets) { \ + if (__ac_isempty(h->flags, i) && site != h->n_buckets) x = site; \ + else x = i; \ + } \ + } \ + } \ + if (__ac_isempty(h->flags, x)) { \ + h->keys[x] = key; \ + __ac_set_isboth_false(h->flags, x); \ + ++h->size; ++h->n_occupied; \ + *ret = 1; \ + } else if (__ac_isdel(h->flags, x)) { \ + h->keys[x] = key; \ + __ac_set_isboth_false(h->flags, x); \ + ++h->size; \ + *ret = 2; \ + } else *ret = 0; \ + return x; \ + } \ + static inline void kh_del_##name(kh_##name##_t *h, khint_t x) \ + { \ + if (x != h->n_buckets && !__ac_iseither(h->flags, x)) { \ + __ac_set_isdel_true(h->flags, x); \ + --h->size; \ + } \ + } + +/* --- BEGIN OF HASH FUNCTIONS --- */ + +#define kh_int_hash_func(key) (uint32_t)(key) +#define kh_int_hash_equal(a, b) (a == b) +#define kh_int64_hash_func(key) (uint32_t)((key)>>33^(key)^(key)<<11) +#define kh_int64_hash_equal(a, b) (a == b) +static inline khint_t __ac_X31_hash_string(const char *s) +{ + khint_t h = *s; + if (h) + { + for (++s ; *s; ++s) + { + h = (h << 5) - h + *s; + } + } + return h; +} +#define kh_str_hash_func(key) __ac_X31_hash_string(key) +#define kh_str_hash_equal(a, b) (strcmp(a, b) == 0) + +/* --- END OF HASH FUNCTIONS --- */ + +/* Other necessary macros... */ + +#define khash_t(name) kh_##name##_t + +#define kh_init(name) kh_init_##name() +#define kh_destroy(name, h) kh_destroy_##name(h) +#define kh_clear(name, h) kh_clear_##name(h) +#define kh_resize(name, h, s) kh_resize_##name(h, s) +#define kh_put(name, h, k, r) kh_put_##name(h, k, r) +#define kh_get(name, h, k) kh_get_##name(h, k) +#define kh_del(name, h, k) kh_del_##name(h, k) + +#define kh_exist(h, x) (!__ac_iseither((h)->flags, (x))) +#define kh_key(h, x) ((h)->keys[x]) +#define kh_val(h, x) ((h)->vals[x]) +#define kh_value(h, x) ((h)->vals[x]) +#define kh_begin(h) (khint_t)(0) +#define kh_end(h) ((h)->n_buckets) +#define kh_size(h) ((h)->size) +#define kh_n_buckets(h) ((h)->n_buckets) + +/* More conenient interfaces */ + +#define KHASH_SET_INIT_INT(name) \ + KHASH_INIT(name, uint32_t, char, 0, kh_int_hash_func, kh_int_hash_equal) + +#define KHASH_MAP_INIT_INT(name, khval_t) \ + KHASH_INIT(name, uint32_t, khval_t, 1, kh_int_hash_func, kh_int_hash_equal) + +#define KHASH_SET_INIT_INT64(name) \ + KHASH_INIT(name, uint64_t, char, 0, kh_int64_hash_func, kh_int64_hash_equal) + +#define KHASH_MAP_INIT_INT64(name, khval_t) \ + KHASH_INIT(name, uint64_t, khval_t, 1, kh_int64_hash_func, kh_int64_hash_equal) + +typedef const char *kh_cstr_t; +#define KHASH_SET_INIT_STR(name) \ + KHASH_INIT(name, kh_cstr_t, char, 0, kh_str_hash_func, kh_str_hash_equal) + +#define KHASH_MAP_INIT_STR(name, khval_t) \ + KHASH_INIT(name, kh_cstr_t, khval_t, 1, kh_str_hash_func, kh_str_hash_equal) + +#endif /* __AC_KHASH_H */ diff --git a/include/probeinfo.h b/include/probeinfo.h new file mode 100755 index 0000000..9693a28 --- /dev/null +++ b/include/probeinfo.h @@ -0,0 +1,174 @@ +/* + * DA probe + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Jaewon Lim + * Woojin Jung + * Juyoung Kim + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#ifndef __PROBEINFO_H__ +#define __PROBEINFO_H__ + +#ifdef __cplusplus +extern "C"{ +#endif + +#define VT_INT 1 +#define VT_UINT 2 +#define VT_LONG 3 +#define VT_ULONG 4 +#define VT_STR 5 +#define VT_CHAR 6 +#define VT_PTR 7 +#define VT_NULL 8 +#define VT_OFF_T 9 +#define VT_SIZE_T 10 +#define VT_SSIZE_T 11 +#define VT_SOCKLEN_T 12 +#define VT_UINT16_T 13 +#define VT_UINT32_T 14 +#define VT_UINT64_T 15 +#define VT_MODE_T 16 +#define VT_DEV_T 17 + +#define LC_MEMORY 1 +#define LC_UICREATE 2 +#define LC_UIEVENT 3 +#define LC_USERFUNC 4 +#define LC_RESOURCE 5 +#define LC_LIFECYCLE 6 +#define LC_SNAPSHOT 7 +#define LC_SCENE 8 +#define LC_DEVICE 9 +#define LC_ALLOCMEM 10 +#define LC_SAMPLE 11 +#define LC_THREAD 12 +#define LC_CUSTOM 13 +#define LC_SYNC 14 + +#define FD_FILE 0 +#define FD_SOCKET 1 + +#define FD_API_OPEN 0 +#define FD_API_CLOSE 1 +#define FD_API_READ_START 2 +#define FD_API_READ_END 3 +#define FD_API_WRITE_START 4 +#define FD_API_WRITE_END 5 +#define FD_API_DIRECTORY 6 +#define FD_API_PERMISSION 7 +#define FD_API_OTHER 8 +#define FD_API_SEND 9 +#define FD_API_RECEIVE 10 +#define FD_API_OPTION 11 +#define FD_API_MANAGE 12 + +#define MEMORY_API_ALLOC 0 +#define MEMORY_API_FREE 1 +#define MEMORY_API_MANAGE 2 + +//#define SNAPSHOT_API_WIN 0 +//#define SNAPSHOT_API_CONTROLBAR 1 +//#define SNAPSHOT_API_NAVIFRAME 2 +//#define SNAPSHOT_API_PAGER 3 + +#define EVENT_TYPE_DOWN 0 +#define EVENT_TYPE_UP 1 +#define EVENT_TYPE_MOVE 2 + +#define USERFUNC_ENTER 0 +#define USERFUNC_EXIT 1 + +#define THREAD_PTHREAD 0 +#define THREAD_TIZENTHREAD_WORKER 1 +#define THREAD_TIZENTHREAD_EVENTDRIVEN 2 + +#define THREAD_API_NEW 0 +#define THREAD_API_START 1 +#define THREAD_API_STOP 2 +#define THREAD_API_EXIT 3 +#define THREAD_API_WAIT_START 4 +#define THREAD_API_WAIT_END 5 +#define THREAD_API_INTERNAL_START 6 +#define THREAD_API_INTERNAL_STOP 7 +#define THREAD_API_OTHER 8 + +#define SYNC_TIZEN_MUTEX 0 +#define SYNC_TIZEN_MONITOR 1 +#define SYNC_TIZEN_SEMAPHORE 2 +#define SYNC_PTHREAD_MUTEX 3 +#define SYNC_PTHREAD_COND_VARIABLE 4 +#define SYNC_PTHREAD_RWLOCK 5 +#define SYNC_PTHREAD_SPINLOCK 6 +#define SYNC_PTHREAD_BARRIER 7 + +#define SYNC_API_NEW 0 +#define SYNC_API_ACQUIRE_WAIT_START 1 +#define SYNC_API_ACQUIRE_WAIT_END 2 +#define SYNC_API_RELEASE 3 +#define SYNC_API_TRY_ACQUIRE 4 +#define SYNC_API_COND_WAIT_START 5 +#define SYNC_API_COND_WAIT_END 6 +#define SYNC_API_NOTIFY 7 +#define SYNC_API_NOTIFY_ALL 8 +#define SYNC_API_OTHER 9 + +enum MessageType +{ + MSG_DEVICE = 1, + MSG_TIME, + MSG_SAMPLE, + MSG_LOG = 5, + MSG_IMAGE = 6, + MSG_TERMINATE = 7, + MSG_PID = 8, + MSG_MSG = 9, + MSG_ALLOC = 10, + MSG_ERROR = 11, + MSG_STOP = 101, + MSG_CONFIG = 103 +}; + +enum DaOptions +{ + OPT_ALWAYSOFF = 0x00000000, + OPT_CPUMEM = 0x00000001, + OPT_FUNC = 0x00000002, + OPT_ALLOC = 0x00000004, + OPT_FILE = 0x00000008, + OPT_THREAD = 0x00000010, + OPT_UI = 0x00000020, + OPT_SNAPSHOT = 0x00000040, + OPT_EVENT = 0x00000080, + OPT_RECORD = 0x00000100, + OPT_ALWAYSON = 0xffffffff +}; + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/tizen_probe.h b/include/tizen_probe.h new file mode 100755 index 0000000..7dd32bc --- /dev/null +++ b/include/tizen_probe.h @@ -0,0 +1,78 @@ +/* + * DA probe + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Jaewon Lim + * Woojin Jung + * Juyoung Kim + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#ifndef __BADA_PROBE_H__ +#define __BADA_PROBE_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define GET_REAL_FUNC_TIZEN(FUNCNAME, LIBNAME, FUNCTIONPOINTER) \ + do { \ + if(!FUNCTIONPOINTER) { \ + probeBlockStart(); \ + if(lib_handle[LIBNAME] == NULL) { \ + lib_handle[LIBNAME] = dlopen(lib_string[LIBNAME], RTLD_LAZY); \ + if(lib_handle[LIBNAME] == NULL) { \ + char perror_msg[PERROR_MSG_MAX]; \ + sprintf(perror_msg, "dlopen failed : %s", lib_string[LIBNAME]); \ + perror(perror_msg); \ + exit(0); \ + } \ + } \ + void* funcp = dlsym(lib_handle[LIBNAME], #FUNCNAME); \ + if(funcp == NULL || dlerror() != NULL) { \ + perror("dlsym failed : " #FUNCNAME); \ + exit(0); \ + } \ + memcpy(&FUNCTIONPOINTER, &funcp, sizeof(void*)); \ + probeBlockEnd(); \ + } \ + } while(0) + +#define PRE_PROBEBLOCK_TIZEN(FILTER) \ + do { \ + if((blockresult = preBlockBegin(CALLER_ADDRESS, FILTER, _sopt)) != 0) { \ + setProbePoint(&probeInfo); \ + preBlockEnd(); \ + } \ + } while(0) + +extern int SceneManagerUsed; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/packaging/dynamic-analysis-probe.changes b/packaging/dynamic-analysis-probe.changes new file mode 100644 index 0000000..3cd68c4 --- /dev/null +++ b/packaging/dynamic-analysis-probe.changes @@ -0,0 +1,9 @@ +* Fri Jul 12 2013 Woojin Jung +- bug fix for ThreadProc, File::Seek probe +- add filesize value for probe log of Tizen::Io::File APIs +- function call inside app loader is excluded from user call +- use original header files for Tizen APIs + +* Wed Jul 3 2013 Jaewon Lim +- change screenshot file name for multiprocess application + diff --git a/packaging/dynamic-analysis-probe.manifest b/packaging/dynamic-analysis-probe.manifest new file mode 100644 index 0000000..86dbb26 --- /dev/null +++ b/packaging/dynamic-analysis-probe.manifest @@ -0,0 +1,5 @@ + + + + + diff --git a/packaging/dynamic-analysis-probe.spec b/packaging/dynamic-analysis-probe.spec new file mode 100644 index 0000000..b0f8bb3 --- /dev/null +++ b/packaging/dynamic-analysis-probe.spec @@ -0,0 +1,45 @@ +Name: dynamic-analysis-probe +Summary: dynamic analyzer probe library +Version: 2.2.1 +Release: 1 +Group: System/Libraries +License: GNU Lesser General Public License, Version 2.1 +Source: %{name}_%{version}.tar.gz +BuildRequires: osp-appfw-devel +BuildRequires: osp-uifw-devel +BuildRequires: ecore-input-evas +BuildRequires: elementary-devel +BuildRequires: capi-appfw-application-devel +BuildRequires: capi-system-runtime-info-devel +BuildRequires: libXext-devel +#BuildRequires: libX11-devel +#BuildRequires: evas-devel + + +%description +Dynamic analysis probe is for dynamic analyzer. +This library will be installed in target. + +%prep +%setup -q -n %{name}_%{version} + +%build +make + +%install +rm -rf ${RPM_BUILD_ROOT} +mkdir -p %{buildroot}/usr/share/license +cp LICENSE %{buildroot}/usr/share/license/%{name} +%make_install + +%files +/usr/share/license/%{name} + +%manifest dynamic-analysis-probe.manifest +%defattr(-,root,root,-) +%{_prefix}/lib/da_probe_tizen.so +%{_prefix}/lib/libdaprobe.so + + +%changelog + diff --git a/probe_capi/capi_appfw.c b/probe_capi/capi_appfw.c new file mode 100644 index 0000000..bc599ad --- /dev/null +++ b/probe_capi/capi_appfw.c @@ -0,0 +1,179 @@ +/* + * DA probe + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Jaewon Lim + * Woojin Jung + * Juyoung Kim + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#include +#include +#include "daprobe.h" +#include "dahelper.h" +#include "probeinfo.h" + +Ecore_Event_Handler* register_orientation_event_listener(); +void unregister_orientation_event_listener(Ecore_Event_Handler* handler); + +app_event_callback_s gAppCallback; + +#define AFTER_ORIGINAL_APPFWCYCLE(RTYPE, RVAL, FUNCNAME, INPUTFORMAT, ...) \ + newerrno = errno; \ + do { \ + if(postBlockBegin(blockresult)) { \ + INIT_LOG; \ + APPEND_LOG_BASIC_NAME(LC_LIFECYCLE, #FUNCNAME); \ + APPEND_LOG_INPUT(INPUTFORMAT, __VA_ARGS__); \ + APPEND_LOG_RESULT(RTYPE, RVAL); \ + __appendTypeLog(&log, 1, NULL, VT_INT, 0); \ + printLog(&log, MSG_LOG); \ + postBlockEnd(); \ + } \ + } while(0); \ + errno = (newerrno != 0) ? newerrno : olderrno + +static enum DaOptions _sopt = OPT_ALWAYSON; + +static bool _dalc_app_create(void* user_data) +{ + bool bret; + DECLARE_VARIABLE_STANDARD; + + bfiltering = false; + PRE_PROBEBLOCK(); + + bret = gAppCallback.create(user_data); + + AFTER_ORIGINAL_APPFWCYCLE(VT_INT, bret, usercallback_app_create, + "%p", user_data); + + return bret; +} + +static void _dalc_app_terminate(void* user_data) +{ + DECLARE_VARIABLE_STANDARD; + + bfiltering = false; + PRE_PROBEBLOCK(); + + gAppCallback.terminate(user_data); + + AFTER_ORIGINAL_APPFWCYCLE(VT_NULL, NULL, usercallback_app_terminate, + "%p", user_data); +} + +static void _dalc_app_pause(void* user_data) +{ + DECLARE_VARIABLE_STANDARD; + + bfiltering = false; + PRE_PROBEBLOCK(); + + gAppCallback.pause(user_data); + + AFTER_ORIGINAL_APPFWCYCLE(VT_NULL, NULL, usercallback_app_pause, + "%p", user_data); +} + +static void _dalc_app_resume(void* user_data) +{ + DECLARE_VARIABLE_STANDARD; + + bfiltering = false; + PRE_PROBEBLOCK(); + + gAppCallback.resume(user_data); + + AFTER_ORIGINAL_APPFWCYCLE(VT_NULL, NULL, usercallback_app_resume, + "%p", user_data); +} + +static void _dalc_app_service(service_h service, void* user_data) +{ + DECLARE_VARIABLE_STANDARD; + + bfiltering = false; + PRE_PROBEBLOCK(); + + gAppCallback.service(service, user_data); + + AFTER_ORIGINAL_APPFWCYCLE(VT_NULL, NULL, usercallback_app_service, + "%u, %p", (unsigned int)service, user_data); +} + +static void _dalc_app_deviceorientationchanged(app_device_orientation_e orientation, void* user_data) +{ + on_orientation_changed((int)orientation, true); + + if(gAppCallback.device_orientation) + gAppCallback.device_orientation(orientation, user_data); +} + +int app_efl_main(int *argc, char ***argv, app_event_callback_s *callback, void *user_data) +{ + static int (*app_efl_mainp)(int* argc, char*** argv, app_event_callback_s* callback, void* user_data); + Ecore_Event_Handler* handler; + int ret; + + GET_REAL_FUNC(app_efl_main, LIBCAPI_APPFW_APPLICATION); + + probeBlockStart(); + handler = register_orientation_event_listener(); + gAppCallback.create = callback->create; + gAppCallback.terminate = callback->terminate; + gAppCallback.pause = callback->pause; + gAppCallback.resume = callback->resume; + gAppCallback.service = callback->service; + gAppCallback.device_orientation = callback->device_orientation; + + if(callback->create) + callback->create = _dalc_app_create; + if(callback->terminate) + callback->terminate = _dalc_app_terminate; + if(callback->pause) + callback->pause = _dalc_app_pause; + if(callback->resume) + callback->resume = _dalc_app_resume; + if(callback->service) + callback->service = _dalc_app_service; + callback->device_orientation = _dalc_app_deviceorientationchanged; + probeBlockEnd(); + + ret = app_efl_mainp(argc, argv, callback, user_data); + + probeBlockStart(); + unregister_orientation_event_listener(handler); + callback->create = gAppCallback.create; + callback->terminate = gAppCallback.terminate; + callback->pause = gAppCallback.pause; + callback->resume = gAppCallback.resume; + callback->service = gAppCallback.service; + callback->device_orientation = gAppCallback.device_orientation; + probeBlockEnd(); + + return ret; +} + diff --git a/probe_event/da_event.c b/probe_event/da_event.c new file mode 100755 index 0000000..b3bfba1 --- /dev/null +++ b/probe_event/da_event.c @@ -0,0 +1,134 @@ +/* + * DA probe + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Jaewon Lim + * Woojin Jung + * Juyoung Kim + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#include +#include + +#include +#include +#include + +#include "daprobe.h" +#include "dahelper.h" +#include "da_event.h" + +static int external_angle = 0; +static int internal_angle = 0; + +// =================================================================== +// orientation related functions +// =================================================================== + +static int convert_angle(int angle) +{ + int os = _OS_NONE; + + switch(angle) + { + case 0: + os = _OS_PORTRAIT; + break; + case 90: + os = _OS_LANDSCAPE_REVERSE; + break; + case 180: + os = _OS_PORTRAIT_REVERSE; + break; + case 270: + os = _OS_LANDSCAPE; + break; + default: + break; + } + + return os; +} + +void on_orientation_changed(int angle, bool capi) +{ + DECLARE_COMMON_VARIABLE; + bool autoRotation = true; + + probeBlockStart(); + + internal_angle = angle; + if(runtime_info_get_value_bool( + RUNTIME_INFO_KEY_AUTO_ROTATION_ENABLED, &autoRotation) < 0) + { + PRINTMSG("ERROR: could not get auto rotation value!\n"); + } + + if(autoRotation) // rotation is not locked + { + external_angle = internal_angle; + + if(isOptionEnabled(OPT_EVENT)) + { + setProbePoint(&probeInfo); + INIT_LOG; + APPEND_LOG_BASIC_NAME(LC_UIEVENT, "OrientationChanged"); + APPEND_LOG_COMMON_NONE(0); + log.length += sprintf(log.data + log.length, "`,%d`,`,`,`,%d`,", + _EVENT_ORIENTATION, convert_angle(external_angle)); + printLog(&log, MSG_LOG); + } + + SCREENSHOT_SET(); +// if(!capi) +// { +// SCREENSHOT_DONE(); +// } + } + else { } // do nothing + + probeBlockEnd(); +} + +int getOrientation() +{ + return external_angle; +} + +// ==================================================================== +// initialize and finalize event +// ==================================================================== + +int initialize_event() +{ + external_angle = internal_angle = app_get_device_orientation(); + return 0; +} + +int finalize_event() +{ + return 0; +} + + diff --git a/probe_event/da_event.h b/probe_event/da_event.h new file mode 100755 index 0000000..d59625d --- /dev/null +++ b/probe_event/da_event.h @@ -0,0 +1,137 @@ +/* + * DA probe + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Jaewon Lim + * Woojin Jung + * Juyoung Kim + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#ifndef __DA_EVENT_H__ +#define __DA_EVENT_H__ + +#include "daprobe.h" + +/******************************************************************* + * Type definition + *******************************************************************/ + +enum __event_type +{ + _EVENT_KEY = 1, + _EVENT_TOUCH = 2, + _EVENT_GESTURE = 3, + _EVENT_ORIENTATION = 4, + _EVENT_LISTENER = 5 +} EVENT_TYPE; + +enum __key_status +{ + _KEY_PRESSED = 0, + _KEY_RELEASED = 1 +} KEY_STATUS; + +enum __touch_status +{ + _TOUCH_PRESSED = 0, + _TOUCH_LONG_PRESSED = 1, + _TOUCH_RELEASED = 2, + _TOUCH_MOVED = 3, + _TOUCH_DOUBLE_PRESSED = 4, + _TOUCH_FOCUS_IN = 5, + _TOUCH_FOCUS_OUT = 6, + _TOUCH_CANCELED = 7 +} _TOUCH_STATUS; + +enum __gesture_type +{ + _GESTURE_FLICK = 0, + _GESTURE_LONGPRESS = 1, + _GESTURE_PANNING = 2, + _GESTURE_PINCH = 3, + _GESTURE_ROTATION = 4, + _GESTURE_TAP = 5, + _GESTURE_CUSTOM = 6 +} GESTURE_TYPE; + +enum _orientation_status +{ + _OS_NONE = 0, + _OS_PORTRAIT = 1, + _OS_LANDSCAPE = 2, + _OS_PORTRAIT_REVERSE = 3, + _OS_LANDSCAPE_REVERSE = 4 +} ORIENTATION_STATUS; + + +/******************************************************************* + * macros for event probe + * + * log format: + * SeqNumber`,ApiName`,Time`,Pid`,Tid`,InputParm`,Return`,PCAddr`,Error`,x`,y`,\n + * callstack_start`,callstack`,callstack_end + * + *******************************************************************/ + +#define DECLARE_VARIABLE_EVENT \ + DECLARE_COMMON_VARIABLE; \ + static unsigned int oldtime = 0; \ + int blockresult = 0 + +#define PRE_PROBEBLOCK_BEGIN_EVENT(FUNCNAME, LIBNAME, EVENTTYPE) \ + GET_REAL_FUNC(FUNCNAME, LIBNAME); \ + do { \ + if(oldtime != timestamp && (EVENTTYPE != EVENT_TYPE_MOVE || \ + getTouchState() == EVENT_TYPE_DOWN || \ + getTouchState() == EVENT_TYPE_MOVE)) \ + { \ + blockresult = 1; \ + detectTouchEvent(EVENTTYPE); \ + PRE_UNCONDITIONAL_BLOCK_BEGIN() + +#define PRE_PROBEBLOCK_END_EVENT() \ + PRE_UNCONDITIONAL_BLOCK_END(); \ + } \ + } while(0) + +#define BEFORE_ORIGINAL_EVENT(FUNCNAME, LIBNAME, EVENTTYPE) \ + DECLARE_VARIABLE_EVENT; \ + PRE_PROBEBLOCK_BEGIN_EVENT(FUNCNAME, LIBNAME, EVENTTYPE); \ + PRE_PROBEBLOCK_END_EVENT() + +#define AFTER_ORIGINAL_EVENT(EVENTTYPE, INPUTFORMAT, ...) \ + do { \ + if(blockresult == 1) { \ + POST_UNCONDITIONAL_BLOCK_BEGIN(LC_UIEVENT); \ + APPEND_LOG_INPUT(INPUTFORMAT, __VA_ARGS__); \ + log.length += sprintf(log.data + log.length, \ + "`,`,`,`,1`,`,%d`,%d`,%d", x, y, EVENTTYPE);\ + APPEND_LOG_NULL_CALLSTACK(); \ + POST_UNCONDITIONAL_BLOCK_END(); \ + oldtime = timestamp; \ + } \ + } while(0) + + +#endif // __DA_EVENT_H__ diff --git a/probe_event/gesture.cpp b/probe_event/gesture.cpp new file mode 100755 index 0000000..371a8d6 --- /dev/null +++ b/probe_event/gesture.cpp @@ -0,0 +1,654 @@ +/* + * DA probe + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Jaewon Lim + * Woojin Jung + * Juyoung Kim + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#include "daprobe.h" +#include "dahelper.h" +#include "probeinfo.h" +#include "tizen_probe.h" +#include "dacollection.h" +#include "da_event.h" +#include "gesture.h" + +#define GESTURE_EVENT_LOG(_FUNCNAME, _GESTURETYPE, _X, _Y, _INFO1, _INFO2) \ + setProbePoint(&probeInfo); \ + INIT_LOG; \ + APPEND_LOG_BASIC_NAME(LC_UIEVENT, _FUNCNAME); \ + APPEND_LOG_COMMON_NONE(0); \ + log.length += sprintf(log.data + log.length, "`,%d`,%d`,%d`,%d`,%d`,%d", \ + _EVENT_GESTURE, _GESTURETYPE, _X, _Y, _INFO1, _INFO2); \ + printLog(&log, MSG_LOG) + +GestureEventListener GestureEventListener::rInstance; + +GestureEventListener::GestureEventListener() +{ + +} + +GestureEventListener::~GestureEventListener() +{ + +} + +void GestureEventListener::OnCustomGestureCanceled (TouchGestureDetector &gestureDetector) +{ + DECLARE_COMMON_VARIABLE; + + if(isOptionEnabled(OPT_EVENT)) + { + probeBlockStart(); + GESTURE_EVENT_LOG("canceled", _GESTURE_CUSTOM, 0, 0, 0, 0); + probeBlockEnd(); + } +} + +void GestureEventListener::OnCustomGestureChanged (TouchGestureDetector &gestureDetector) +{ + DECLARE_COMMON_VARIABLE; + + if(isOptionEnabled(OPT_EVENT)) + { + probeBlockStart(); + GESTURE_EVENT_LOG("changed", _GESTURE_CUSTOM, 0, 0, 0, 0); + probeBlockEnd(); + } +} + +void GestureEventListener::OnCustomGestureFinished (TouchGestureDetector &gestureDetector) +{ + DECLARE_COMMON_VARIABLE; + + if(isOptionEnabled(OPT_EVENT)) + { + probeBlockStart(); + GESTURE_EVENT_LOG("finished", _GESTURE_CUSTOM, 0, 0, 0, 0); + probeBlockEnd(); + } +} + +void GestureEventListener::OnCustomGestureStarted (TouchGestureDetector &gestureDetector) +{ + DECLARE_COMMON_VARIABLE; + + if(isOptionEnabled(OPT_EVENT)) + { + probeBlockStart(); + GESTURE_EVENT_LOG("started", _GESTURE_CUSTOM, 0, 0, 0, 0); + probeBlockEnd(); + } +} + +void GestureEventListener::OnFlickGestureCanceled (TouchFlickGestureDetector &gestureDetector) +{ + DECLARE_COMMON_VARIABLE; + + if(isOptionEnabled(OPT_EVENT)) + { + probeBlockStart(); + { + int x = 0, y = 0, dur = 0; + FlickDirection direction = FLICK_DIRECTION_NONE; + + gestureDetector.GetDistance(x, y); + dur = gestureDetector.GetDuration(); + direction = gestureDetector.GetDirection(); + GESTURE_EVENT_LOG("canceled", _GESTURE_FLICK, x, y, dur, (int)direction); + } + probeBlockEnd(); + } +} + +void GestureEventListener::OnFlickGestureDetected (TouchFlickGestureDetector &gestureDetector) +{ + DECLARE_COMMON_VARIABLE; + + if(isOptionEnabled(OPT_EVENT)) + { + probeBlockStart(); + { + int x = 0, y = 0, dur = 0; + FlickDirection direction = FLICK_DIRECTION_NONE; + + gestureDetector.GetDistance(x, y); + dur = gestureDetector.GetDuration(); + direction = gestureDetector.GetDirection(); + GESTURE_EVENT_LOG("detected", _GESTURE_FLICK, x, y, dur, (int)direction); + } + probeBlockEnd(); + } +} + +void GestureEventListener::OnLongPressGestureCanceled (TouchLongPressGestureDetector &gestureDetector) +{ + DECLARE_COMMON_VARIABLE; + + if(isOptionEnabled(OPT_EVENT)) + { + probeBlockStart(); + { + int moveallow = 0, tcount = 0, dur = 0; + + moveallow = gestureDetector.GetMoveAllowance(); + dur = gestureDetector.GetDuration(); + tcount = gestureDetector.GetTouchCount(); + GESTURE_EVENT_LOG("canceled", _GESTURE_LONGPRESS, moveallow, 0, dur, tcount); + } + probeBlockEnd(); + } +} + +void GestureEventListener::OnLongPressGestureDetected (TouchLongPressGestureDetector &gestureDetector) +{ + DECLARE_COMMON_VARIABLE; + + if(isOptionEnabled(OPT_EVENT)) + { + probeBlockStart(); + { + int moveallow = 0, tcount = 0, dur = 0; + + moveallow = gestureDetector.GetMoveAllowance(); + dur = gestureDetector.GetDuration(); + tcount = gestureDetector.GetTouchCount(); + GESTURE_EVENT_LOG("detected", _GESTURE_LONGPRESS, moveallow, 0, dur, tcount); + } + probeBlockEnd(); + } +} + +void GestureEventListener::OnPanningGestureCanceled (TouchPanningGestureDetector &gestureDetector) +{ + DECLARE_COMMON_VARIABLE; + + if(isOptionEnabled(OPT_EVENT)) + { + probeBlockStart(); + { + int tcount = 0; + + tcount = gestureDetector.GetTouchCount(); + GESTURE_EVENT_LOG("canceled", _GESTURE_PANNING, 0, 0, 0, tcount); + } + probeBlockEnd(); + } +} + +void GestureEventListener::OnPanningGestureChanged (TouchPanningGestureDetector &gestureDetector) +{ + DECLARE_COMMON_VARIABLE; + + if(isOptionEnabled(OPT_EVENT)) + { + probeBlockStart(); + { + int tcount = 0; + + tcount = gestureDetector.GetTouchCount(); + GESTURE_EVENT_LOG("changed", _GESTURE_PANNING, 0, 0, 0, tcount); + } + probeBlockEnd(); + } +} + +void GestureEventListener::OnPanningGestureFinished (TouchPanningGestureDetector &gestureDetector) +{ + DECLARE_COMMON_VARIABLE; + + if(isOptionEnabled(OPT_EVENT)) + { + probeBlockStart(); + { + int tcount = 0; + + tcount = gestureDetector.GetTouchCount(); + GESTURE_EVENT_LOG("finished", _GESTURE_PANNING, 0, 0, 0, tcount); + } + probeBlockEnd(); + } +} + +void GestureEventListener::OnPanningGestureStarted (TouchPanningGestureDetector &gestureDetector) +{ + DECLARE_COMMON_VARIABLE; + + if(isOptionEnabled(OPT_EVENT)) + { + probeBlockStart(); + { + int tcount = 0; + + tcount = gestureDetector.GetTouchCount(); + GESTURE_EVENT_LOG("started", _GESTURE_PANNING, 0, 0, 0, tcount); + } + probeBlockEnd(); + } +} + +void GestureEventListener::OnPinchGestureCanceled (TouchPinchGestureDetector &gestureDetector) +{ + DECLARE_COMMON_VARIABLE; + + if(isOptionEnabled(OPT_EVENT)) + { + probeBlockStart(); + { + Tizen::Graphics::Point point; + int scale = 0; + + point = gestureDetector.GetCenterPoint(); + scale = gestureDetector.GetScale(); + GESTURE_EVENT_LOG("canceled", _GESTURE_PINCH, point.x, point.y, scale, 0); + } + probeBlockEnd(); + } +} + +void GestureEventListener::OnPinchGestureChanged (TouchPinchGestureDetector &gestureDetector) +{ + DECLARE_COMMON_VARIABLE; + + if(isOptionEnabled(OPT_EVENT)) + { + probeBlockStart(); + { + Tizen::Graphics::Point point; + int scale = 0; + + point = gestureDetector.GetCenterPoint(); + scale = gestureDetector.GetScale(); + GESTURE_EVENT_LOG("changed", _GESTURE_PINCH, point.x, point.y, scale, 0); + } + probeBlockEnd(); + } +} + +void GestureEventListener::OnPinchGestureFinished (TouchPinchGestureDetector &gestureDetector) +{ + DECLARE_COMMON_VARIABLE; + + if(isOptionEnabled(OPT_EVENT)) + { + probeBlockStart(); + { + Tizen::Graphics::Point point; + int scale = 0; + + point = gestureDetector.GetCenterPoint(); + scale = gestureDetector.GetScale(); + GESTURE_EVENT_LOG("finished", _GESTURE_PINCH, point.x, point.y, scale, 0); + } + probeBlockEnd(); + } +} + +void GestureEventListener::OnPinchGestureStarted (TouchPinchGestureDetector &gestureDetector) +{ + DECLARE_COMMON_VARIABLE; + + if(isOptionEnabled(OPT_EVENT)) + { + probeBlockStart(); + { + Tizen::Graphics::Point point; + int scale = 0; + + point = gestureDetector.GetCenterPoint(); + scale = gestureDetector.GetScale(); + GESTURE_EVENT_LOG("started", _GESTURE_PINCH, point.x, point.y, scale, 0); + } + probeBlockEnd(); + } +} + +void GestureEventListener::OnRotationGestureCanceled (TouchRotationGestureDetector &gestureDetector) +{ + DECLARE_COMMON_VARIABLE; + + if(isOptionEnabled(OPT_EVENT)) + { + probeBlockStart(); + { + int distance = 0; + float angle = 0.0f; + + distance = gestureDetector.GetDistance(); + angle = gestureDetector.GetAngle(); + GESTURE_EVENT_LOG("canceled", _GESTURE_ROTATION, 0, 0, distance, static_cast(angle)); + } + probeBlockEnd(); + } +} + +void GestureEventListener::OnRotationGestureChanged (TouchRotationGestureDetector &gestureDetector) +{ + DECLARE_COMMON_VARIABLE; + + if(isOptionEnabled(OPT_EVENT)) + { + probeBlockStart(); + { + int distance = 0; + float angle = 0.0f; + + distance = gestureDetector.GetDistance(); + angle = gestureDetector.GetAngle(); + GESTURE_EVENT_LOG("changed", _GESTURE_ROTATION, 0, 0, distance, static_cast(angle)); + } + probeBlockEnd(); + } +} + +void GestureEventListener::OnRotationGestureFinished (TouchRotationGestureDetector &gestureDetector) +{ + DECLARE_COMMON_VARIABLE; + + if(isOptionEnabled(OPT_EVENT)) + { + probeBlockStart(); + { + int distance = 0; + float angle = 0.0f; + + distance = gestureDetector.GetDistance(); + angle = gestureDetector.GetAngle(); + GESTURE_EVENT_LOG("finished", _GESTURE_ROTATION, 0, 0, distance, static_cast(angle)); + } + probeBlockEnd(); + } +} + +void GestureEventListener::OnRotationGestureStarted (TouchRotationGestureDetector &gestureDetector) +{ + DECLARE_COMMON_VARIABLE; + + if(isOptionEnabled(OPT_EVENT)) + { + probeBlockStart(); + { + int distance = 0; + float angle = 0.0f; + + distance = gestureDetector.GetDistance(); + angle = gestureDetector.GetAngle(); + GESTURE_EVENT_LOG("started", _GESTURE_ROTATION, 0, 0, distance, static_cast(angle)); + } + probeBlockEnd(); + } +} + +void GestureEventListener::OnTapGestureCanceled (TouchTapGestureDetector &gestureDetector) +{ + DECLARE_COMMON_VARIABLE; + + if(isOptionEnabled(OPT_EVENT)) + { + probeBlockStart(); + { + int move = 0, tapcount = 0, touchcount = 0, interval = 0; + + move = gestureDetector.GetMoveAllowance(); + tapcount = gestureDetector.GetTapCount(); + interval = gestureDetector.GetTapInterval(); + touchcount = gestureDetector.GetTouchCount(); + GESTURE_EVENT_LOG("canceled", _GESTURE_TAP, move, tapcount, interval, touchcount); + } + probeBlockEnd(); + } +} + +void GestureEventListener::OnTapGestureDetected (TouchTapGestureDetector &gestureDetector) +{ + DECLARE_COMMON_VARIABLE; + + if(isOptionEnabled(OPT_EVENT)) + { + probeBlockStart(); + { + int move = 0, tapcount = 0, touchcount = 0, interval = 0; + + move = gestureDetector.GetMoveAllowance(); + tapcount = gestureDetector.GetTapCount(); + interval = gestureDetector.GetTapInterval(); + touchcount = gestureDetector.GetTouchCount(); + GESTURE_EVENT_LOG("detected", _GESTURE_TAP, move, tapcount, interval, touchcount); + } + probeBlockEnd(); + } +} + +GestureEventListener& GestureEventListener::GetInstance() +{ + return rInstance; +} + + +namespace Tizen { namespace Ui { + +result TouchFlickGestureDetector::AddFlickGestureEventListener(ITouchFlickGestureEventListener& listener) +{ + typedef result (TouchFlickGestureDetector::*methodType)(ITouchFlickGestureEventListener& listener); + static methodType addflickgestureeventlistenerp; + result iret; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui25TouchFlickGestureDetector28AddFlickGestureEventListenerERNS0_31ITouchFlickGestureEventListenerE, + LIBOSP_UIFW, addflickgestureeventlistenerp); + + probeBlockStart(); + GestureEventListener& mylistener = GestureEventListener::GetInstance(); + if(add_detector_hash(static_cast(this), static_cast(&mylistener)) <= 0) + { + iret = (this->*addflickgestureeventlistenerp)(static_cast(mylistener)); + if(likely(iret == E_SUCCESS)) + { + // do nothing + } + else + { + del_detector_hash(static_cast(this)); + } + } + probeBlockEnd(); + + return (this->*addflickgestureeventlistenerp)(listener); +} + +result TouchLongPressGestureDetector::AddLongPressGestureEventListener(ITouchLongPressGestureEventListener& listener) +{ + typedef result (TouchLongPressGestureDetector::*methodType)(ITouchLongPressGestureEventListener& listener); + static methodType addlongpressgestureeventlistenerp; + result iret; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui29TouchLongPressGestureDetector32AddLongPressGestureEventListenerERNS0_35ITouchLongPressGestureEventListenerE, + LIBOSP_UIFW, addlongpressgestureeventlistenerp); + + probeBlockStart(); + GestureEventListener& mylistener = GestureEventListener::GetInstance(); + if(add_detector_hash(static_cast(this), static_cast(&mylistener)) <= 0) + { + iret = (this->*addlongpressgestureeventlistenerp)(static_cast(mylistener)); + if(likely(iret == E_SUCCESS)) + { + // do nothing + } + else + { + del_detector_hash(static_cast(this)); + } + } + probeBlockEnd(); + + return (this->*addlongpressgestureeventlistenerp)(listener); +} + +result TouchPanningGestureDetector::AddPanningGestureEventListener(ITouchPanningGestureEventListener& listener) +{ + typedef result (TouchPanningGestureDetector::*methodType)(ITouchPanningGestureEventListener& listener); + static methodType addpanninggestureeventlistenerp; + result iret; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui27TouchPanningGestureDetector30AddPanningGestureEventListenerERNS0_33ITouchPanningGestureEventListenerE, + LIBOSP_UIFW, addpanninggestureeventlistenerp); + + probeBlockStart(); + GestureEventListener& mylistener = GestureEventListener::GetInstance(); + if(add_detector_hash(static_cast(this), static_cast(&mylistener)) <= 0) + { + iret = (this->*addpanninggestureeventlistenerp)(static_cast(mylistener)); + if(likely(iret == E_SUCCESS)) + { + // do nothing + } + else + { + del_detector_hash(static_cast(this)); + } + } + probeBlockEnd(); + + return (this->*addpanninggestureeventlistenerp)(listener); +} + +result TouchPinchGestureDetector::AddPinchGestureEventListener(ITouchPinchGestureEventListener& listener) +{ + typedef result (TouchPinchGestureDetector::*methodType)(ITouchPinchGestureEventListener& listener); + static methodType addpinchgestureeventlistenerp; + result iret; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui25TouchPinchGestureDetector28AddPinchGestureEventListenerERNS0_31ITouchPinchGestureEventListenerE, + LIBOSP_UIFW, addpinchgestureeventlistenerp); + + probeBlockStart(); + GestureEventListener& mylistener = GestureEventListener::GetInstance(); + if(add_detector_hash(static_cast(this), static_cast(&mylistener)) <= 0) + { + iret = (this->*addpinchgestureeventlistenerp)(static_cast(mylistener)); + if(likely(iret == E_SUCCESS)) + { + // do nothing + } + else + { + del_detector_hash(static_cast(this)); + } + } + probeBlockEnd(); + + return (this->*addpinchgestureeventlistenerp)(listener); +} + +result TouchRotationGestureDetector::AddRotationGestureEventListener(ITouchRotationGestureEventListener& listener) +{ + typedef result (TouchRotationGestureDetector::*methodType)(ITouchRotationGestureEventListener& listener); + static methodType addrotationgestureeventlistenerp; + result iret; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui28TouchRotationGestureDetector31AddRotationGestureEventListenerERNS0_34ITouchRotationGestureEventListenerE, + LIBOSP_UIFW, addrotationgestureeventlistenerp); + + probeBlockStart(); + GestureEventListener& mylistener = GestureEventListener::GetInstance(); + if(add_detector_hash(static_cast(this), static_cast(&mylistener)) <= 0) + { + iret = (this->*addrotationgestureeventlistenerp)(static_cast(mylistener)); + if(likely(iret == E_SUCCESS)) + { + // do nothing + } + else + { + del_detector_hash(static_cast(this)); + } + } + probeBlockEnd(); + + return (this->*addrotationgestureeventlistenerp)(listener); +} + +result TouchTapGestureDetector::AddTapGestureEventListener(ITouchTapGestureEventListener& listener) +{ + typedef result (TouchTapGestureDetector::*methodType)(ITouchTapGestureEventListener& listener); + static methodType addtapgestureeventlistenerp; + result iret; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui23TouchTapGestureDetector26AddTapGestureEventListenerERNS0_29ITouchTapGestureEventListenerE, + LIBOSP_UIFW, addtapgestureeventlistenerp); + + probeBlockStart(); + GestureEventListener& mylistener = GestureEventListener::GetInstance(); + if(add_detector_hash(static_cast(this), static_cast(&mylistener)) <= 0) + { + iret = (this->*addtapgestureeventlistenerp)(static_cast(mylistener)); + if(likely(iret == E_SUCCESS)) + { + // do nothing + } + else + { + del_detector_hash(static_cast(this)); + } + } + probeBlockEnd(); + + return (this->*addtapgestureeventlistenerp)(listener); +} + +result TouchGestureDetector::AddGestureEventListener(ITouchGestureEventListener& listener) +{ + typedef result (TouchGestureDetector::*methodType)(ITouchGestureEventListener& listener); + static methodType addgestureeventlistenerp; + result iret; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui20TouchGestureDetector23AddGestureEventListenerERNS0_26ITouchGestureEventListenerE, + LIBOSP_UIFW, addgestureeventlistenerp); + + probeBlockStart(); + GestureEventListener& mylistener = GestureEventListener::GetInstance(); + if(add_detector_hash(static_cast(this), static_cast(&mylistener)) <= 0) + { + iret = (this->*addgestureeventlistenerp)(static_cast(mylistener)); + if(likely(iret == E_SUCCESS)) + { + // do nothing + } + else + { + del_detector_hash(static_cast(this)); + } + } + probeBlockEnd(); + + return (this->*addgestureeventlistenerp)(listener); +} + + +} } // end of namespace + + + diff --git a/probe_event/gesture.h b/probe_event/gesture.h new file mode 100644 index 0000000..20fdea1 --- /dev/null +++ b/probe_event/gesture.h @@ -0,0 +1,86 @@ +/* + * DA probe + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Jaewon Lim + * Woojin Jung + * Juyoung Kim + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#ifndef __GESTURE_H__ +#define __GESTURE_H__ + +#include + +using namespace Tizen::Ui; + +class GestureEventListener : + public ITouchCustomGestureEventListener, + public ITouchFlickGestureEventListener, + public ITouchLongPressGestureEventListener, + public ITouchPanningGestureEventListener, + public ITouchPinchGestureEventListener, + public ITouchRotationGestureEventListener, + public ITouchTapGestureEventListener +{ +public: + GestureEventListener(); + virtual ~GestureEventListener(); + + virtual void OnCustomGestureStarted (TouchGestureDetector &gestureDetector); + virtual void OnCustomGestureChanged (TouchGestureDetector &gestureDetector); + virtual void OnCustomGestureFinished (TouchGestureDetector &gestureDetector); + virtual void OnCustomGestureCanceled (TouchGestureDetector &gestureDetector); + + virtual void OnFlickGestureDetected (TouchFlickGestureDetector &gestureDetector); + virtual void OnFlickGestureCanceled (TouchFlickGestureDetector &gestureDetector); + + virtual void OnLongPressGestureDetected (TouchLongPressGestureDetector &gestureDetector); + virtual void OnLongPressGestureCanceled (TouchLongPressGestureDetector &gestureDetector); + + virtual void OnPanningGestureStarted (TouchPanningGestureDetector &gestureDetector); + virtual void OnPanningGestureChanged (TouchPanningGestureDetector &gestureDetector); + virtual void OnPanningGestureFinished (TouchPanningGestureDetector &gestureDetector); + virtual void OnPanningGestureCanceled (TouchPanningGestureDetector &gestureDetector); + + virtual void OnPinchGestureStarted (TouchPinchGestureDetector &gestureDetector); + virtual void OnPinchGestureChanged (TouchPinchGestureDetector &gestureDetector); + virtual void OnPinchGestureFinished (TouchPinchGestureDetector &gestureDetector); + virtual void OnPinchGestureCanceled (TouchPinchGestureDetector &gestureDetector); + + virtual void OnRotationGestureStarted (TouchRotationGestureDetector &gestureDetector); + virtual void OnRotationGestureChanged (TouchRotationGestureDetector &gestureDetector); + virtual void OnRotationGestureFinished (TouchRotationGestureDetector &gestureDetector); + virtual void OnRotationGestureCanceled (TouchRotationGestureDetector &gestureDetector); + + virtual void OnTapGestureDetected (TouchTapGestureDetector &gestureDetector); + virtual void OnTapGestureCanceled (TouchTapGestureDetector &gestureDetector); + + static GestureEventListener& GetInstance(void); + +private: + static GestureEventListener rInstance; +}; + +#endif diff --git a/probe_event/keytouch.c b/probe_event/keytouch.c new file mode 100755 index 0000000..a2c080c --- /dev/null +++ b/probe_event/keytouch.c @@ -0,0 +1,277 @@ +/* + * DA probe + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Jaewon Lim + * Woojin Jung + * Juyoung Kim + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +//#include +//#include +#include +#include + +//#include +//#include +//#include +//#include +#include +#include +#include +//#include + +#include "daprobe.h" +#include "dahelper.h" +#include "probeinfo.h" +//#include "dautil.h" +#include "da_event.h" + +bool touch_pressed = false; + +#define HW_EVENT_LOG(_EVENTTYPE, _DETAILTYPE, _X, _Y, _KEYCODE, _EXTRA) \ + setProbePoint(&probeInfo); \ + INIT_LOG; \ + APPEND_LOG_BASIC(LC_UIEVENT); \ + APPEND_LOG_COMMON_NONE(0); \ + log.length += sprintf(log.data + log.length, "`,%d`,%d`,%d`,%d`,%s`,%d", \ + _EVENTTYPE, _DETAILTYPE, _X, _Y, _KEYCODE, _EXTRA); \ + printLog(&log, MSG_LOG) + +Eina_Bool ecore_event_evas_key_down(void *data, int type, void *event) +{ + static Eina_Bool (*ecore_event_evas_key_downp)(void *data, int type, void *event); + DECLARE_COMMON_VARIABLE; + + GET_REAL_FUNC(ecore_event_evas_key_down, LIBECORE_INPUT_EVAS); + + if(isOptionEnabled(OPT_EVENT)) + { + probeBlockStart(); + if(event != NULL) + { + Ecore_Event_Key* pEv = (Ecore_Event_Key*)event; + if(strcasestr(pEv->keyname, "volume") == NULL) + { + HW_EVENT_LOG(_EVENT_KEY, _KEY_PRESSED, 0, 0, pEv->keyname, 0); + } + } + probeBlockEnd(); + } + + return ecore_event_evas_key_downp(data, type, event); +} + +Eina_Bool ecore_event_evas_key_up(void *data, int type, void *event) +{ + static Eina_Bool (*ecore_event_evas_key_upp)(void *data, int type, void *event); + DECLARE_COMMON_VARIABLE; + + GET_REAL_FUNC(ecore_event_evas_key_up, LIBECORE_INPUT_EVAS); + + if(isOptionEnabled(OPT_EVENT)) + { + probeBlockStart(); + if(event != NULL) + { + Ecore_Event_Key* pEv = (Ecore_Event_Key*)event; + if(strcasestr(pEv->keyname, "volume") == NULL) + { + HW_EVENT_LOG(_EVENT_KEY, _KEY_RELEASED, 0, 0, pEv->keyname, 0); + } + } + probeBlockEnd(); + } + + return ecore_event_evas_key_upp(data, type, event); +} + +Eina_Bool ecore_event_evas_mouse_button_down(void *data, int type, void *event) +{ + static Eina_Bool (*ecore_event_evas_mouse_button_downp)(void *data, int type, void *event); + DECLARE_COMMON_VARIABLE; + + GET_REAL_FUNC(ecore_event_evas_mouse_button_down, LIBECORE_INPUT_EVAS); + + if(isOptionEnabled(OPT_EVENT)) + { + probeBlockStart(); + if(event != NULL) + { + Ecore_Event_Mouse_Button* pEv = (Ecore_Event_Mouse_Button*)event; + touch_pressed = true; + HW_EVENT_LOG(_EVENT_TOUCH, _TOUCH_PRESSED, pEv->root.x, pEv->root.y, "", pEv->multi.device); + } + probeBlockEnd(); + } + + return ecore_event_evas_mouse_button_downp(data, type, event); +} + +Eina_Bool ecore_event_evas_mouse_button_up(void *data, int type, void *event) +{ + static Eina_Bool (*ecore_event_evas_mouse_button_upp)(void *data, int type, void *event); + DECLARE_COMMON_VARIABLE; + + GET_REAL_FUNC(ecore_event_evas_mouse_button_up, LIBECORE_INPUT_EVAS); + + if(isOptionEnabled(OPT_EVENT)) + { + probeBlockStart(); + if(event != NULL) + { + Ecore_Event_Mouse_Button* pEv = (Ecore_Event_Mouse_Button*)event; + touch_pressed = false; + HW_EVENT_LOG(_EVENT_TOUCH, _TOUCH_RELEASED, pEv->root.x, pEv->root.y, "", pEv->multi.device); + } + probeBlockEnd(); + } + + return ecore_event_evas_mouse_button_upp(data, type, event); +} + +Eina_Bool ecore_event_evas_mouse_move(void *data, int type, void *event) +{ + static Eina_Bool (*ecore_event_evas_mouse_movep)(void *data, int type, void *event); + DECLARE_COMMON_VARIABLE; + + GET_REAL_FUNC(ecore_event_evas_mouse_move, LIBECORE_INPUT_EVAS); + + if(isOptionEnabled(OPT_EVENT)) + { + probeBlockStart(); + if(touch_pressed) + { + if(event != NULL) + { + Ecore_Event_Mouse_Move* pEv = (Ecore_Event_Mouse_Move*)event; + HW_EVENT_LOG(_EVENT_TOUCH, _TOUCH_MOVED, pEv->root.x, pEv->root.y, "", pEv->multi.device); + } + } + probeBlockEnd(); + } + + return ecore_event_evas_mouse_movep(data, type, event); +} + + +/* +void evas_event_feed_mouse_down(Evas *e, int b, Evas_Button_Flags flags, + unsigned int timestamp, const void *data) +{ + static void (*evas_event_feed_mouse_downp)(Evas *e, int b, Evas_Button_Flags flags, unsigned int timestamp, const void *data); + + DECLARE_COMMON_VARIABLE; + + GET_REAL_FUNC(evas_event_feed_mouse_down, LIBEVAS); + + PRE_UNCONDITIONAL_BLOCK_BEGIN(); + HW_EVENT_LOG(_EVENT_TOUCH, _TOUCH_PRESSED, ) + PRE_UNCONDITIONAL_BLOCK_END(); + + + DECLARE_VARIABLE_EVENT; + int x, y; + + PRE_PROBEBLOCK_BEGIN_EVENT(evas_event_feed_mouse_down, LIBEVAS, EVENT_TYPE_DOWN); + evas_pointer_output_xy_get(e, &x, &y); + PRE_PROBEBLOCK_END_EVENT(); + + evas_event_feed_mouse_downp(e, b, flags, timestamp, data); + + AFTER_ORIGINAL_EVENT(EVENT_TYPE_DOWN, "%d", b); +} + +void evas_event_feed_mouse_up(Evas *e, int b, Evas_Button_Flags flags, + unsigned int timestamp, const void *data) +{ + static void (*evas_event_feed_mouse_upp)(Evas *e, int b, Evas_Button_Flags flags, unsigned int timestamp, const void *data); + + DECLARE_VARIABLE_EVENT; + int x, y; + + PRE_PROBEBLOCK_BEGIN_EVENT(evas_event_feed_mouse_up, LIBEVAS, EVENT_TYPE_UP); + evas_pointer_output_xy_get(e, &x, &y); + PRE_PROBEBLOCK_END_EVENT(); + + evas_event_feed_mouse_upp(e, b, flags, timestamp, data); + + AFTER_ORIGINAL_EVENT(EVENT_TYPE_UP, "%d", b); +} + +void evas_event_feed_mouse_move(Evas *e, int x, int y, + unsigned int timestamp, const void *data) +{ + static void (*evas_event_feed_mouse_movep)(Evas *e, int x, int y, unsigned int timestamp, const void *data); + + BEFORE_ORIGINAL_EVENT(evas_event_feed_mouse_move, LIBEVAS, EVENT_TYPE_MOVE); + + evas_event_feed_mouse_movep(e, x, y, timestamp, data); + + AFTER_ORIGINAL_EVENT(EVENT_TYPE_MOVE, "%u", timestamp); +} + +void evas_event_feed_multi_down(Evas *e, int d, int x, int y, + double rad, double radx, double rady, + double pres, double ang, double fx, double fy, + Evas_Button_Flags flags, unsigned int timestamp, const void *data) +{ + static void (*evas_event_feed_multi_downp)(Evas *e, int d, int x, int y, double rad, double radx, double rady, double pres, double ang, double fx, double fy, Evas_Button_Flags flags, unsigned int timestamp, const void *data); + + BEFORE_ORIGINAL_EVENT(evas_event_feed_multi_down, LIBEVAS, EVENT_TYPE_DOWN); + + evas_event_feed_multi_downp(e, d, x, y, rad, radx, + rady, pres, ang, fx, fy, flags, timestamp, data); + + AFTER_ORIGINAL_EVENT(EVENT_TYPE_DOWN, "%d", d); +} + +void evas_event_feed_multi_up(Evas *e, int d, int x, int y, double rad, double radx, + double rady, double pres, double ang, double fx, double fy, + Evas_Button_Flags flags, unsigned int timestamp, const void *data) +{ + static void (*evas_event_feed_multi_upp)(Evas *e, int d, int x, int y, double rad, double radx, double rady, double pres, double ang, double fx, double fy, Evas_Button_Flags flags, unsigned int timestamp, const void *data); + + BEFORE_ORIGINAL_EVENT(evas_event_feed_multi_up, LIBEVAS, EVENT_TYPE_UP); + + evas_event_feed_multi_upp(e, d, x, y, rad, radx, rady, + pres, ang, fx, fy, flags, timestamp, data); + + AFTER_ORIGINAL_EVENT(EVENT_TYPE_UP, "%d", d); +} + +void evas_event_feed_multi_move (Evas *e, int d, int x, int y, double rad, double radx, + double rady, double pres, double ang, double fx, double fy, + unsigned int timestamp, const void *data) +{ + static void (*evas_event_feed_multi_movep)(Evas *e, int d, int x, int y, double rad, double radx, double rady, double pres, double ang, double fx, double fy, unsigned int timestamp, const void *data); + + BEFORE_ORIGINAL_EVENT(evas_event_feed_multi_move, LIBEVAS, EVENT_TYPE_MOVE); + + evas_event_feed_multi_movep(e, d, x, y, rad, radx, rady, + pres, ang, fx, fy, timestamp, data); + + AFTER_ORIGINAL_EVENT(EVENT_TYPE_MOVE, "%d", d); +} +*/ diff --git a/probe_event/orientation.c b/probe_event/orientation.c new file mode 100644 index 0000000..2e96c31 --- /dev/null +++ b/probe_event/orientation.c @@ -0,0 +1,79 @@ +/* + * DA probe + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Jaewon Lim + * Woojin Jung + * Juyoung Kim + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#include +#include + +#include "daprobe.h" +#include "dahelper.h" + +Eina_Bool _da_onclientmessagereceived(void* pData, int type, void* pEvent) +{ + Ecore_X_Event_Client_Message* pClientEvent; + + probeBlockStart(); + pClientEvent = (Ecore_X_Event_Client_Message*)pEvent; + + if(pClientEvent != NULL) + { + if(pClientEvent->message_type == ECORE_X_ATOM_E_WINDOW_ROTATION_CHANGE_REQUEST) + { + int orientation = pClientEvent->data.l[1]; + on_orientation_changed(orientation, false); + } + } + probeBlockEnd(); + + return ECORE_CALLBACK_RENEW; +} + +Ecore_Event_Handler* register_orientation_event_listener() +{ + Ecore_Event_Handler* handler; + + probeBlockStart(); + ecore_init(); + ecore_x_init(NULL); + handler = ecore_event_handler_add(ECORE_X_EVENT_CLIENT_MESSAGE, _da_onclientmessagereceived, NULL); + probeBlockEnd(); + + return handler; +} + +void unregister_orientation_event_listener(Ecore_Event_Handler* handler) +{ + probeBlockStart(); + if(handler) + { + ecore_event_handler_del(handler); + } + probeBlockEnd(); +} + diff --git a/probe_file/da_io.h b/probe_file/da_io.h new file mode 100755 index 0000000..c30fbc2 --- /dev/null +++ b/probe_file/da_io.h @@ -0,0 +1,315 @@ +/* + * DA probe + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Jaewon Lim + * Woojin Jung + * Juyoung Kim + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#ifndef __DA_IO_H__ +#define __DA_IO_H__ + +#include +#include +#include +#include + +#include "daprobe.h" + +/******************************************************************** + * RESOURCE PROBE MACRO + * + * log format + * SeqNumber`,ApiName`,Time`,Pid`,Tid`,InputParm`,Return`,PCAddr`,Error`, + * Size`,FDValue`,FDType`,FDApiType`,\n + * callstack_start`,callstack`,callstack_end + * + * fd type + * FD_TYPE_FILE, FD_TYPE_SOCKET + * + * fd api type + * FD_API_TYPE_OPEN, FD_API_TYPE_CLOSE, FD_API_TYPE_READ, FD_API_TYPE_WRITE, + * FD_API_TYPE_DIRECTORY, FD_API_TYPE_PERMISSION, FD_API_TYPE_OTHER, + * FD_API_TYPE_SEND, FD_API_TYPE_RECEIVE, FD_API_TYPE_OPTION, FD_API_TYPE_MANAGE + * + ************************************************************************/ + +// =================================================================== +// macro for file probe +// =================================================================== + +#define GET_FD_FROM_FILEP(FILEP) \ + _fd = (FILEP != NULL) ? fileno(FILEP) : -1 + +#define GET_FILEPATH_FROM_FD(FD) \ + do { \ + sprintf(_procfdlink, "/proc/self/fd/%d", FD); \ + _readlinkret = readlink(_procfdlink, _pathbuf, PATH_MAX - 1); \ + if(_readlinkret != -1) { \ + _pathbuf[_readlinkret] = '\0'; \ + _filepath = _pathbuf; \ + } \ + } while(0) + +#define GET_FILEPATH_FROM_FILEP(FILEP) \ + GET_FD_FROM_FILEP(FILEP); \ + GET_FILEPATH_FROM_FD(_fd) + +#define GET_FILEPATH_FROM_FD_AND_PATH \ + do { \ + if(fd != AT_FDCWD && path[0] != '/') \ + { \ + static const char procfd[] = "/proc/self/fd/%d/%s"; \ + size_t pathlen = strlen(path); \ + size_t buflen = sizeof(procfd) + sizeof(int) * 3 + pathlen; \ + buf = alloca(buflen); \ + snprintf(buf, buflen, procfd, fd, path); \ + path = buf; \ + } \ + } while(0) + +#define DECLARE_VARIABLE_FD \ + DECLARE_VARIABLE_STANDARD; \ + char __attribute((unused)) _pathbuf[PATH_MAX]; \ + char* _filepath = ""; \ + char __attribute((unused)) _procfdlink[PATH_MAX]; \ + int __attribute((unused)) _readlinkret; \ + int __attribute((unused)) _fd; \ + int __attribute((unused)) _fstatret = -1; \ + struct stat __attribute((unused)) _statbuf + +// ================================================================= +// PRE/POST_PROBEBLOCK for file +// ================================================================= + +#define PRE_PROBEBLOCK_BEGIN_FILE(FD) \ + if((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { \ + _fstatret = fstat(FD, &_statbuf); \ + if(_fstatret != 0) perror("fstat error"); \ + if(S_ISREG(_statbuf.st_mode) || S_ISSOCK(_statbuf.st_mode)) { \ + setProbePoint(&probeInfo) + +#define PRE_PROBEBLOCK_END_FILE() \ + preBlockEnd(); \ + } \ + } \ + olderrno = errno; \ + errno = 0 + +#define POST_PROBEBLOCK_BEGIN_FILE(LCTYPE, RETTYPE, RETVALUE, FD, INPUTFORMAT, ...) \ + newerrno = errno; \ + if(postBlockBegin(blockresult)) { \ + _fstatret = fstat(FD, &_statbuf); \ + if(_fstatret != 0) perror("fstat error"); \ + if(S_ISREG(_statbuf.st_mode) || S_ISSOCK(_statbuf.st_mode)) { \ + INIT_LOG; \ + APPEND_LOG_BASIC(LCTYPE); \ + APPEND_LOG_INPUT(INPUTFORMAT, __VA_ARGS__); \ + APPEND_LOG_RESULT(RETTYPE, RETVALUE); \ + APPEND_LOG_CALLER() + +#define POST_PROBEBLOCK_END_FILE() \ + printLog(&log, MSG_LOG); \ + } \ + postBlockEnd(); \ + } \ + errno = (newerrno != 0) ? newerrno : olderrno + +#define PRE_START_END_PROBEBLOCK_BEGIN_FILE(LCTYPE, FD, INPUTFORMAT, ...) \ + PRE_PROBEBLOCK_BEGIN_FILE(FD); \ + INIT_LOG; \ + APPEND_LOG_BASIC(LCTYPE); \ + APPEND_LOG_INPUT(INPUTFORMAT, __VA_ARGS__); \ + log.length += sprintf(log.data + log.length, "`,`,0`,0`,%d", blockresult); \ + APPEND_LOG_CALLER() + +#define POST_START_END_PROBEBLOCK_BEGIN_FILE(LCTYPE, RETTYPE, RETVALUE, FD, INPUTFORMAT, ...) \ + newerrno = errno; \ + if(postBlockBegin(blockresult)) { \ + _fstatret = fstat(FD, &_statbuf); \ + if(_fstatret != 0) perror("fstat error"); \ + if(S_ISREG(_statbuf.st_mode) || S_ISSOCK(_statbuf.st_mode)) { \ + setProbePoint(&probeInfo); \ + INIT_LOG; \ + APPEND_LOG_BASIC(LCTYPE); \ + APPEND_LOG_INPUT(INPUTFORMAT, __VA_ARGS__); \ + APPEND_LOG_RESULT(RETTYPE, RETVALUE); \ + APPEND_LOG_CALLER() + +#define POST_PROBEBLOCK_MIDDLE_FD(SIZE, FD, APITYPE) \ + log.length += sprintf(log.data + log.length, "`,%u`,%d`,%d`,%d`,%ld`,%s", \ + SIZE, FD, FD_FILE, APITYPE, (_fstatret == 0 ? _statbuf.st_size : 0), _filepath) + +#define POST_PROBEBLOCK_MIDDLE_NOFD(SIZE, APITYPE) \ + log.length += sprintf(log.data + log.length, "`,%u`,`,%d`,%d`,0`,%s", \ + SIZE, FD_FILE, APITYPE, _filepath) + +#define POST_PROBEBLOCK_CALLSTACK_RESOURCE(APITYPE) \ + do { \ + if(APITYPE == FD_API_OPEN) { \ + APPEND_LOG_CALLSTACK(); \ + } else if(unlikely(newerrno != 0 || blockresult == 2)) { \ + APPEND_LOG_CALLSTACK(); \ + } else { \ + APPEND_LOG_NULL_CALLSTACK(); \ + } \ + } while(0) + +// ================================================================== +// BEFORE_ORIGINAL macro for file +// ================================================================== + +#define BEFORE_ORIGINAL_FILE(FUNCNAME, LIBNAME) \ + DECLARE_VARIABLE_FD; \ + GET_REAL_FUNC(FUNCNAME, LIBNAME); \ + PRE_PROBEBLOCK() + +#define BEFORE_ORIGINAL_FILE_NOFILTER(FUNCNAME, LIBNAME) \ + DECLARE_VARIABLE_FD; \ + GET_REAL_FUNC(FUNCNAME, LIBNAME); \ + bfiltering = false; \ + PRE_PROBEBLOCK() + +// ================================================================== +// AFTER_ORIGINAL macro for file +// ================================================================== + +#define AFTER_ORIGINAL_FD_RET(RTYPE, RVAL, SIZE, FD, APITYPE, INPUTFORMAT, ...) \ + POST_PROBEBLOCK_BEGIN_FILE(LC_RESOURCE, RTYPE, RVAL, FD, INPUTFORMAT, __VA_ARGS__); \ + if(S_ISREG(_statbuf.st_mode)) { \ + POST_PROBEBLOCK_MIDDLE_FD(SIZE, FD, APITYPE); \ + POST_PROBEBLOCK_CALLSTACK_RESOURCE(APITYPE); \ + } else { /*socket*/ \ + POST_PROBEBLOCK_MIDDLE_FD(SIZE, FD, APITYPE); \ + POST_PROBEBLOCK_CALLSTACK_RESOURCE(APITYPE); \ + } \ + POST_PROBEBLOCK_END_FILE() + +#define AFTER_ORIGINAL_NOFD_RET(RTYPE, RVAL, SIZE, APITYPE, INPUTFORMAT, ...) \ + POST_PROBEBLOCK_BEGIN(LC_RESOURCE, RTYPE, RVAL, INPUTFORMAT, __VA_ARGS__); \ + POST_PROBEBLOCK_MIDDLE_NOFD(SIZE, APITYPE); \ + POST_PROBEBLOCK_CALLSTACK_RESOURCE(APITYPE); \ + POST_PROBEBLOCK_END() + +#define AFTER_ORIGINAL_FILEP_RET(RTYPE, RVAL, SIZE, FILEP, APITYPE, INPUTFORMAT, ...) \ + POST_PROBEBLOCK_BEGIN(LC_RESOURCE, RTYPE, RVAL, INPUTFORMAT, __VA_ARGS__); \ + GET_FD_FROM_FILEP(FILEP); \ + if(_fd != -1) { \ + _fstatret = fstat(_fd, &_statbuf); \ + } \ + if(_fstatret != 0) perror("fstat error"); \ + POST_PROBEBLOCK_MIDDLE_FD(SIZE, _fd, APITYPE); \ + POST_PROBEBLOCK_CALLSTACK_RESOURCE(APITYPE); \ + POST_PROBEBLOCK_END() + + +#define AFTER_ORIGINAL_FD(SIZE, FD, APITYPE, INPUTFORMAT, ...) \ + AFTER_ORIGINAL_FD_RET(VT_INT, ret, SIZE, FD, APITYPE, INPUTFORMAT, __VA_ARGS__) + +#define AFTER_ORIGINAL_NOFD(SIZE, APITYPE, INPUTFORMAT, ...) \ + AFTER_ORIGINAL_NOFD_RET(VT_INT, ret, SIZE, APITYPE, INPUTFORMAT, __VA_ARGS__) + +#define AFTER_ORIGINAL_FILEP(SIZE, FILEP, APITYPE, INPUTFORMAT, ...) \ + AFTER_ORIGINAL_FILEP_RET(VT_INT, ret, SIZE, FILEP, APITYPE, INPUTFORMAT, __VA_ARGS__) + +// ================================================================== +// START_END macro for file +// ================================================================== + +#define BEFORE_ORIGINAL_START_END_FD(FUNCNAME, LIBNAME, FD, APITYPE, INPUTFORMAT, ...) \ + DECLARE_VARIABLE_FD; \ + GET_REAL_FUNC(FUNCNAME, LIBNAME); \ + PRE_START_END_PROBEBLOCK_BEGIN_FILE(LC_RESOURCE, FD, INPUTFORMAT, __VA_ARGS__); \ + if(S_ISREG(_statbuf.st_mode)) { \ + POST_PROBEBLOCK_MIDDLE_FD(0, FD, APITYPE); \ + APPEND_LOG_NULL_CALLSTACK(); \ + } else { /*socket*/ \ + POST_PROBEBLOCK_MIDDLE_FD(0, FD, APITYPE); \ + APPEND_LOG_NULL_CALLSTACK(); \ + } \ + printLog(&log, MSG_LOG); \ + PRE_PROBEBLOCK_END_FILE() + +#define BEFORE_ORIGINAL_START_END_NOFD(FUNCNAME, LIBNAME, APITYPE, INPUTFORMAT, ...) \ + DECLARE_VARIABLE_FD; \ + GET_REAL_FUNC(FUNCNAME, LIBNAME); \ + PRE_START_END_PROBEBLOCK_BEGIN(LC_RESOURCE, INPUTFORMAT, __VA_ARGS__); \ + POST_PROBEBLOCK_MIDDLE_NOFD(0, APITYPE); \ + APPEND_LOG_NULL_CALLSTACK(); \ + printLog(&log, MSG_LOG); \ + PRE_PROBEBLOCK_END() + +#define BEFORE_ORIGINAL_START_END_FILEP(FUNCNAME, LIBNAME, FILEP, APITYPE, INPUTFORMAT, ...) \ + DECLARE_VARIABLE_FD; \ + GET_REAL_FUNC(FUNCNAME, LIBNAME); \ + PRE_START_END_PROBEBLOCK_BEGIN(LC_RESOURCE, INPUTFORMAT, __VA_ARGS__); \ + GET_FD_FROM_FILEP(FILEP); \ + if(_fd != -1) { \ + _fstatret = fstat(_fd, &_statbuf); \ + } \ + if(_fstatret != 0) perror("fstat error"); \ + POST_PROBEBLOCK_MIDDLE_FD(0, _fd, APITYPE); \ + APPEND_LOG_NULL_CALLSTACK(); \ + printLog(&log, MSG_LOG); \ + PRE_PROBEBLOCK_END() + +#define AFTER_ORIGINAL_START_END_FD_RET(RTYPE, RVAL, SIZE, FD, APITYPE, INPUTFORMAT, ...) \ + POST_START_END_PROBEBLOCK_BEGIN_FILE(LC_RESOURCE, RTYPE, RVAL, FD, INPUTFORMAT, __VA_ARGS__); \ + if(S_ISREG(_statbuf.st_mode)) { \ + POST_PROBEBLOCK_MIDDLE_FD(SIZE, FD, APITYPE); \ + POST_PROBEBLOCK_CALLSTACK_RESOURCE(APITYPE); \ + } else { /*socket*/ \ + POST_PROBEBLOCK_MIDDLE_FD(SIZE, FD, APITYPE); \ + POST_PROBEBLOCK_CALLSTACK_RESOURCE(APITYPE); \ + } \ + POST_PROBEBLOCK_END_FILE() + +#define AFTER_ORIGINAL_START_END_NOFD_RET(RTYPE, RVAL, SIZE, APITYPE, INPUTFORMAT, ...) \ + POST_START_END_PROBEBLOCK_BEGIN(LC_RESOURCE, RTYPE, RVAL, INPUTFORMAT, __VA_ARGS__); \ + POST_PROBEBLOCK_MIDDLE_NOFD(SIZE, APITYPE); \ + POST_PROBEBLOCK_CALLSTACK_RESOURCE(APITYPE); \ + POST_PROBEBLOCK_END() + +#define AFTER_ORIGINAL_START_END_FILEP_RET(RTYPE, RVAL, SIZE, FILEP, APITYPE, INPUTFORMAT, ...) \ + POST_START_END_PROBEBLOCK_BEGIN(LC_RESOURCE, RTYPE, RVAL, INPUTFORMAT, __VA_ARGS__); \ + GET_FD_FROM_FILEP(FILEP); \ + if(_fd != -1) { \ + _fstatret = fstat(_fd, &_statbuf); \ + } \ + if(_fstatret != 0) perror("fstat error"); \ + POST_PROBEBLOCK_MIDDLE_FD(SIZE, _fd, APITYPE); \ + POST_PROBEBLOCK_CALLSTACK_RESOURCE(APITYPE); \ + POST_PROBEBLOCK_END() + +#define AFTER_ORIGINAL_START_END_FD(SIZE, FD, APITYPE, INPUTFORMAT, ...) \ + AFTER_ORIGINAL_START_END_FD_RET(VT_INT, ret, SIZE, FD, APITYPE, INPUTFORMAT, __VA_ARGS__) + +#define AFTER_ORIGINAL_START_END_NOFD(SIZE, APITYPE, INPUTFORMAT, ...) \ + AFTER_ORIGINAL_START_END_NOFD_RET(VT_INT, ret, SIZE, APITYPE, INPUTFORMAT, __VA_ARGS__) + +#define AFTER_ORIGINAL_START_END_FILEP(SIZE, FILEP, APITYPE, INPUTFORMAT, ...) \ + AFTER_ORIGINAL_START_END_FILEP_RET(VT_INT, ret, SIZE, FILEP, APITYPE, INPUTFORMAT, __VA_ARGS__) + +#endif // __DA_IO_H__ diff --git a/probe_file/da_io_posix.c b/probe_file/da_io_posix.c new file mode 100755 index 0000000..5b376b6 --- /dev/null +++ b/probe_file/da_io_posix.c @@ -0,0 +1,1189 @@ +/* + * DA probe + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Jaewon Lim + * Woojin Jung + * Juyoung Kim + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#include +#include +#include +#include "daprobe.h" +#include "probeinfo.h" +#include "dautil.h" +#include "dahelper.h" +#include "da_io.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static enum DaOptions _sopt = OPT_FILE; + +int open(const char* path, int oflag, ...) +{ + static int (*openp)(const char* path, int oflag, ...); + int mode = 0; + + BEFORE_ORIGINAL_FILE_NOFILTER(open, LIBC); + if(realpath(path, _pathbuf) != NULL) + { + _filepath = _pathbuf; + } + else + { + perror("realpath error"); + _filepath = (char*)path; + } + + if(oflag & O_CREAT) + { + va_list arg; + va_start(arg, oflag); + mode = va_arg(arg, int); + va_end(arg); + } + + ret = openp(path, oflag, mode); + + AFTER_ORIGINAL_FD(0, ret, FD_API_OPEN, "%s, %d, %d", path, oflag, mode); + + return ret; +} + +int openat(int fd, const char* path, int oflag, ...) +{ + static int (*openatp)(int fd, const char* path, int oflag, ...); + int mode = 0; + char *buf = NULL; + + BEFORE_ORIGINAL_FILE_NOFILTER(openat, LIBC); + GET_FILEPATH_FROM_FD_AND_PATH; + if(realpath(path, _pathbuf) != NULL) + { + _filepath = _pathbuf; + } + else + { + perror("realpath error"); + _filepath = (char*)path; + } + + if(oflag & O_CREAT) + { + va_list arg; + va_start(arg, oflag); + mode = va_arg(arg, int); + va_end(arg); + } + + ret = openatp(fd, path, oflag, mode); + + AFTER_ORIGINAL_FD(0, ret, FD_API_OPEN, "%d, %s, %d, %d", fd, path, oflag, mode); + + return ret; +} + +int creat(const char* path, mode_t mode) +{ + static int (*creatp)(const char* path, mode_t mode); + + BEFORE_ORIGINAL_FILE_NOFILTER(creat, LIBC); + if(realpath(path, _pathbuf) != NULL) + { + _filepath = _pathbuf; + } + else + { + perror("realpath error"); + _filepath = (char*)path; + } + + ret = creatp(path, mode); + + AFTER_ORIGINAL_FD(0, ret, FD_API_OPEN, "%s, %d", path, mode); + + return ret; +} + +int close(int fd) +{ + static int (*closep)(int fd); + DECLARE_VARIABLE_FD; + + GET_REAL_FUNC(close, LIBC); + + bfiltering = false; + PRE_PROBEBLOCK_BEGIN(); + _fstatret = fstat(fd, &_statbuf); + if(_fstatret != 0) + PRINTMSG("ERROR : fstat error\n"); + GET_FILEPATH_FROM_FD(fd); + PRE_PROBEBLOCK_END(); + + ret = closep(fd); + + POST_PROBEBLOCK_BEGIN_FILE(LC_RESOURCE, VT_INT, ret, fd, "%d", fd); + if(S_ISREG(_statbuf.st_mode)) { + POST_PROBEBLOCK_MIDDLE_FD(0, fd, FD_API_CLOSE); + POST_PROBEBLOCK_CALLSTACK_RESOURCE(FD_API_CLOSE); + } else { /*socket*/ + POST_PROBEBLOCK_MIDDLE_FD(0, fd, FD_API_CLOSE); + POST_PROBEBLOCK_CALLSTACK_RESOURCE(FD_API_CLOSE); + } + POST_PROBEBLOCK_END_FILE(); + + return ret; +} + +off_t lseek(int fd, off_t offset, int whence) +{ + static int (*lseekp)(int fd, off_t offset, int whence); + off_t offret; + + BEFORE_ORIGINAL_FILE(lseek, LIBC); + GET_FILEPATH_FROM_FD(fd); + + offret = lseekp(fd, offset, whence); + + AFTER_ORIGINAL_FD_RET(VT_OFF_T, offret, (unsigned int)offset, fd, FD_API_OTHER, + "%d, %ld, %d", fd, offset, whence); + + return offret; +} + +int fsync(int fd) +{ + static int (*fsyncp)(int fd); + + BEFORE_ORIGINAL_FILE(fsync, LIBC); + GET_FILEPATH_FROM_FD(fd); + + ret = fsyncp(fd); + + AFTER_ORIGINAL_FD(0, fd, FD_API_OTHER, "%d", fd); + + return ret; +} + +int fdatasync(int fd) +{ + static int (*fdatasyncp)(int fd); + + BEFORE_ORIGINAL_FILE(fdatasync, LIBC); + GET_FILEPATH_FROM_FD(fd); + + ret = fdatasyncp(fd); + + AFTER_ORIGINAL_FD(0, fd, FD_API_OTHER, "%d", fd); + + return ret; +} + +int ftruncate(int fd, off_t length) +{ + static int (*ftruncatep)(int fd, off_t length); + + BEFORE_ORIGINAL_FILE(ftruncate, LIBC); + GET_FILEPATH_FROM_FD(fd); + + ret = ftruncatep(fd, length); + + AFTER_ORIGINAL_FD((unsigned int)length, fd, FD_API_DIRECTORY, + "%d, %ld", fd, length); + + return ret; +} + +// **************************************************************** +// File Permission APIs +// **************************************************************** +int fchown(int fd, uid_t owner, gid_t group) +{ + static int (*fchownp)(int fd, uid_t owner, gid_t group); + + BEFORE_ORIGINAL_FILE(fchown, LIBC); + GET_FILEPATH_FROM_FD(fd); + ret = fchownp(fd, owner, group); + AFTER_ORIGINAL_FD(0, fd, FD_API_PERMISSION, "%d, %u, %u", fd, owner, group); + return ret; +} + +int lockf(int fd, int function, off_t size) +{ + static int (*lockfp)(int fd, int function, off_t size); + + BEFORE_ORIGINAL_FILE(lockf, LIBC); + GET_FILEPATH_FROM_FD(fd); + ret = lockfp(fd, function, size); + AFTER_ORIGINAL_FD((unsigned int)size, fd, FD_API_PERMISSION, + "%d, %d, %ld", fd, function, size); + return ret; +} + +int fchmod(int fd, mode_t mode) +{ + static int (*fchmodp)(int fd, mode_t mode); + + BEFORE_ORIGINAL_FILE(fchmod, LIBC); + GET_FILEPATH_FROM_FD(fd); + ret = fchmodp(fd, mode); + AFTER_ORIGINAL_FD(0, fd, FD_API_PERMISSION, "%d, %u", fd, mode); + return ret; +} + +// ***************************************************************** +// Read / Write APIs +// ***************************************************************** + +ssize_t pread(int fd, void *buf, size_t nbyte, off_t offset) +{ + static ssize_t (*preadp)(int fd, void *buf, size_t nbyte, off_t offset); + ssize_t sret; + + BEFORE_ORIGINAL_START_END_FD(pread, LIBC, fd, FD_API_READ_START, "%d, %p, %u, %ld", fd, buf, nbyte, offset); + GET_FILEPATH_FROM_FD(fd); + + sret = preadp(fd, buf, nbyte, offset); + + AFTER_ORIGINAL_START_END_FD_RET(VT_SSIZE_T, sret, (unsigned int)sret, fd, FD_API_READ_END, "%d, %p, %u, %ld", fd, buf, nbyte, offset); + + return sret; +} +ssize_t read(int fd, void *buf, size_t nbyte) +{ + static ssize_t (*readp)(int fildes, void *buf, size_t nbyte); + ssize_t sret; + + BEFORE_ORIGINAL_START_END_FD(read, LIBC, fd, FD_API_READ_START, "%d, %p, %u", fd, buf, nbyte); + GET_FILEPATH_FROM_FD(fd); + + sret = readp(fd, buf, nbyte); + + AFTER_ORIGINAL_START_END_FD_RET(VT_SSIZE_T, sret, (unsigned int)sret, fd, FD_API_READ_END, "%d, %p, %u", fd, buf, nbyte); + + return sret; +} + +ssize_t pwrite(int fd, const void *buf, size_t nbyte, off_t offset) +{ + static ssize_t (*pwritep)(int fd, const void *buf, size_t nbyte, off_t offset); + ssize_t sret; + + BEFORE_ORIGINAL_START_END_FD(pwrite, LIBC, fd, FD_API_WRITE_START, "%d, %p, %u, %ld", fd, buf, nbyte, offset); + GET_FILEPATH_FROM_FD(fd); + + sret = pwritep(fd, buf, nbyte, offset); + + AFTER_ORIGINAL_START_END_FD_RET(VT_SSIZE_T, sret, (unsigned int)sret, fd, FD_API_WRITE_END, "%d, %p, %u, %ld", fd, buf, nbyte, offset); + + return sret; +} + +ssize_t write(int fd, const void *buf, size_t nbyte) +{ + static ssize_t (*writep)(int fildes, const void *buf, size_t nbyte); + ssize_t sret; + + BEFORE_ORIGINAL_START_END_FD(write, LIBC, fd, FD_API_WRITE_START, "%d, %p, %u", fd, buf, nbyte); + GET_FILEPATH_FROM_FD(fd); + + sret = writep(fd, buf, nbyte); + + AFTER_ORIGINAL_START_END_FD_RET(VT_SSIZE_T, sret, (unsigned int)sret, fd, FD_API_WRITE_END, "%d, %p, %u", fd, buf, nbyte); + + return sret; +} + + +ssize_t readv(int fd, const struct iovec *iov, int iovcnt) +{ + static ssize_t (*readvp)(int fd, const struct iovec *iov, int iovcnt); + ssize_t sret; + + BEFORE_ORIGINAL_START_END_FD(readv, LIBC, fd, FD_API_READ_START, "%d, %p, %d", fd, iov, iovcnt); + GET_FILEPATH_FROM_FD(fd); + + sret = readvp(fd,iov,iovcnt); + + AFTER_ORIGINAL_START_END_FD_RET(VT_SSIZE_T, sret, (unsigned int)sret, fd, FD_API_READ_END, "%d, %p, %d", fd, iov, iovcnt); + + return sret; +} + +// why writev is commented ? +#if 0 +ssize_t writev(int fd, const struct iovec *iov, int iovcnt) +{ + static ssize_t (*writevp)(int fd, const struct iovec *iov, int iovcnt); + + MAKE_RESOURCE_PREBLOCK(writev, LIBC,3,VT_INT,fd,VT_PTR,iov,VT_INT,iovcnt); + ssize_t ret; + ret = writevp(fd,iov,iovcnt); + MAKE_RESOURCE_POSTBLOCK(VT_SSIZE_T,ret,VT_SSIZE_T,ret,VT_INT,fd, FD_API_WRITE); + return ret; +} +#endif + +// ***************************************************************** +// File Attributes APIs +// ***************************************************************** + +int fcntl(int fd, int cmd, ...) +{ + static int (*fcntlp)(int fd, int cmd, ...); + int arg = 0; + + BEFORE_ORIGINAL_FILE(fcntl, LIBC); + GET_FILEPATH_FROM_FD(fd); + + va_list argl; + va_start(argl, cmd); + arg = va_arg(argl, int); + va_end(argl); + + ret = fcntlp(fd, cmd, arg); + + AFTER_ORIGINAL_FD(0, fd, FD_API_OTHER, "%d, %d, %d", fd, cmd, arg); + + return ret; +} + +int dup(int fd) +{ + static int (*dupp)(int fd); + + BEFORE_ORIGINAL_FILE_NOFILTER(dup, LIBC); + GET_FILEPATH_FROM_FD(fd); + + ret = dupp(fd); + + AFTER_ORIGINAL_FD(0, ret, FD_API_OPEN, "%d", fd); + + return ret; +} + +int dup2(int fd, int fd2) +{ + static int (*dup2p)(int fd, int fd2); + + BEFORE_ORIGINAL_FILE_NOFILTER(dup2, LIBC); + GET_FILEPATH_FROM_FD(fd); + + ret = dup2p(fd, fd2); + + AFTER_ORIGINAL_FD(0, ret, FD_API_OPEN, "%d, %d", fd, fd2); + + return ret; +} + +//FIXME dlsym error +// fstat is not in LIBC +#if 0 +int fstat(int fd, struct stat *buf) +{ + static int (*fstatp)(int fd, struct stat *buf); + + BEFORE_ORIGINAL_FILE(fstat, LIBC); + GET_FILEPATH_FROM_FD(fd); + ret = fstatp(fd, buf); + AFTER_ORIGINAL_FD(0, fd, FD_API_OTHER, "%d, %p", fd, buf); + return ret; +} +#endif + +int futimens(int fd, const struct timespec times[2]) +{ + static int (*futimensp)(int fd, const struct timespec times[2]); + + BEFORE_ORIGINAL_FILE(futimens, LIBC); + GET_FILEPATH_FROM_FD(fd); + ret = futimensp(fd, times); + AFTER_ORIGINAL_FD(0, fd, FD_API_OTHER, "%d, %p", fd, times); + return ret; +} + +#ifdef UNUSED_PROBE +// unused +// 1. non regular file APIs +int mkfifo(const char *path, mode_t mode) +{ + static int (*mkfifop)(const char *path, mode_t mode); + + BEFORE_ORIGINAL_FILE(mkfifo, LIBC); + if(realpath(path, _pathbuf) != NULL) + { + _filepath = _pathbuf; + } + else + { + perror("realpath error"); + _filepath = (char*)path; + } + + ret = mkfifop(path, mode); + + AFTER_ORIGINAL_NOFD(0, FD_API_OTHER, "%s, %u", path, mode); + + return ret; +} + +int mkfifoat(int fd, const char *path, mode_t mode) +{ + static int (*mkfifoatp)(int fd, const char *path, mode_t mode); + + BEFORE_ORIGINAL_FILE(mkfifoat, LIBC); + GET_FILEPATH_FROM_FD_AND_PATH; + if(realpath(path, _pathbuf) != NULL) + { + _filepath = _pathbuf; + } + else + { + perror("realpath error"); + _filepath = (char*)path; + } + + ret = mkfifoatp(fd, path, mode); + + AFTER_ORIGINAL_NOFD(0, FD_API_OTHER, "%d, %s, %u", fd, path, mode); + + return ret; +} + +// ***************************************************************** +// Directory I/O +// ***************************************************************** + +int rmdir(const char *path) +{ + static int (*rmdirp)(const char *path); + + BEFORE_ORIGINAL_FILE(rmdir, LIBC); + if(realpath(path, _pathbuf) != NULL) + { + _filepath = _pathbuf; + } + else + { + perror("realpath error"); + _filepath = (char*)path; + } + ret = rmdirp(path); + AFTER_ORIGINAL_NOFD(0, FD_API_DIRECTORY, "%s", path); + return ret; +} + +int fchdir(int fd) +{ + static int (*fchdirp)(int fd); + + BEFORE_ORIGINAL_FILE(fchdir, LIBC); + GET_FILEPATH_FROM_FD(fd); + ret = fchdirp(fd); + AFTER_ORIGINAL_FD(0, fd, FD_API_DIRECTORY, "%d", fd); + return ret; +} + +int chdir(const char *path) +{ + static int (*chdirp)(const char *path); + + BEFORE_ORIGINAL_FILE(chdir, LIBC); + if(realpath(path, _pathbuf) != NULL) + { + _filepath = _pathbuf; + } + else + { + perror("realpath error"); + _filepath = (char*)path; + } + ret = chdirp(path); + AFTER_ORIGINAL_NOFD(0, FD_API_DIRECTORY, "%s", path); + return ret; +} + +int mkdir(const char *path, mode_t mode) +{ + static int (*mkdirp)(const char *path, mode_t mode); + + BEFORE_ORIGINAL_FILE(mkdir, LIBC); + if(realpath(path, _pathbuf) != NULL) + { + _filepath = _pathbuf; + } + else + { + perror("realpath error"); + _filepath = (char*)path; + } + ret = mkdirp(path, mode); + AFTER_ORIGINAL_NOFD(0, FD_API_DIRECTORY, "%s, %u", path, mode); + return ret; +} + +int mkdirat(int fd, const char *path, mode_t mode) +{ + static int (*mkdiratp)(int fd, const char *path, mode_t mode); + + BEFORE_ORIGINAL_FILE(mkdirat, LIBC); + GET_FILEPATH_FROM_FD_AND_PATH; + if(realpath(path, _pathbuf) != NULL) + { + _filepath = _pathbuf; + } + else + { + perror("realpath error"); + _filepath = (char*)path; + } + ret = mkdiratp(fd, path, mode); + AFTER_ORIGINAL_NOFD(0, FD_API_DIRECTORY, "%d, %s, %u", fd, path, mode); + return ret; +} + +int closedir(DIR *dirp) +{ + static int (*closedirp)(DIR *dirp); + + BEFORE_ORIGINAL_FILE(closedir, LIBC); + ret = closedirp(dirp); + AFTER_ORIGINAL_NOFD(0, FD_API_DIRECTORY, "%p", dirp); + return ret; +} + +DIR *fdopendir(int fd) +{ + static DIR* (*fdopendirp)(int fd); + DIR* dret; + + BEFORE_ORIGINAL_FILE(fdopendir, LIBC); + GET_FILEPATH_FROM_FD(fd); + + dret = fdopendirp(fd); + + AFTER_ORIGINAL_FD_RET(VT_PTR, dret, 0, fd, FD_API_DIRECTORY, "%d", fd); + + return dret; +} + +DIR *opendir(const char *dirname) +{ + static DIR* (*opendirp)(const char *dirname); + DIR* dret; + + BEFORE_ORIGINAL_FILE(opendir, LIBC); + if(realpath(dirname, _pathbuf) != NULL) + { + _filepath = _pathbuf; + } + else + { + perror("realpath error"); + _filepath = (char*)dirname; + } + + dret = opendirp(dirname); + + AFTER_ORIGINAL_NOFD_RET(VT_PTR, dret, 0, FD_API_DIRECTORY, "%s", dirname); + + return dret; +} + +struct dirent *readdir(DIR *dirp) +{ + static struct dirent* (*readdirp)(DIR *dirp); + struct dirent* dret; + + BEFORE_ORIGINAL_FILE(readdir, LIBC); + + dret = readdirp(dirp); + + AFTER_ORIGINAL_NOFD_RET(VT_PTR, dret, 0, FD_API_DIRECTORY, "%p", dirp); + + return dret; +} + +int readdir_r(DIR * dirp, struct dirent * entry, struct dirent ** result) +{ + static int (*readdir_rp)(DIR * dirp, struct dirent * entry, struct dirent ** result); + + BEFORE_ORIGINAL_FILE(readdir_r, LIBC); + ret = readdir_rp(dirp, entry, result); + AFTER_ORIGINAL_NOFD(0, FD_API_DIRECTORY, "%p, %p, %p", dirp, entry, result); + return ret; +} + +void rewinddir(DIR *dirp) +{ + static void (*rewinddirp)(DIR *dirp); + + BEFORE_ORIGINAL_FILE(rewinddir, LIBC); + + rewinddirp(dirp); + + AFTER_ORIGINAL_NOFD_RET(VT_NULL, NULL, 0, FD_API_DIRECTORY, "%p", dirp); +} + +void seekdir(DIR *dirp, long loc) +{ + static void (*seekdirp)(DIR *dirp, long loc); + + BEFORE_ORIGINAL_FILE(seekdir, LIBC); + + seekdirp(dirp, loc); + + AFTER_ORIGINAL_NOFD_RET(VT_NULL, NULL, 0, FD_API_DIRECTORY, + "%p, %ld", dirp, loc); +} + +long telldir(DIR *dirp) +{ + static int (*telldirp)(DIR *dirp); + long lret; + + BEFORE_ORIGINAL_FILE(telldir, LIBC); + + lret = telldirp(dirp); + + AFTER_ORIGINAL_NOFD_RET(VT_LONG, lret, 0, FD_API_DIRECTORY, "%p", dirp); + + return lret; +} + +ssize_t readlink(const char* path, char* buf, size_t bufsize) +{ + static int (*readlinkp)(const char* path, char* buf, size_t bufsize); + ssize_t sret; + + BEFORE_ORIGINAL_FILE(readlink, LIBC); + if(realpath(path, _pathbuf) != NULL) + { + _filepath = _pathbuf; + } + else + { + perror("realpath error"); + _filepath = (char*)path; + } + + sret = readlinkp(path, buf, bufsize); + + AFTER_ORIGINAL_NOFD_RET(VT_SSIZE_T, sret, bufsize, FD_API_DIRECTORY, + "%s, %s, %u", path, buf, bufsize); + + return sret; +} + +ssize_t readlinkat(int fd, const char * path, char * buf, size_t bufsize) +{ + static int (*readlinkatp)(int fd, const char * path, char * buf, size_t bufsize); + ssize_t sret; + + BEFORE_ORIGINAL_FILE(readlinkat, LIBC); + GET_FILEPATH_FROM_FD_AND_PATH; + if(realpath(path, _pathbuf) != NULL) + { + _filepath = _pathbuf; + } + else + { + perror("realpath error"); + _filepath = (char*)path; + } + + sret = readlinkatp(fd, path, buf, bufsize); + + AFTER_ORIGINAL_NOFD_RET(VT_SSIZE_T, sret, bufsize, FD_API_DIRECTORY, + "%d, %s, %s, %u", fd, path, buf, bufsize); + + return sret; +} + +// unused +// 2. not using fd APIs +int access(const char *path, int amode) +{ + static int (*accessp)(const char *path, int amode); + + BEFORE_ORIGINAL_FILE(access, LIBC); + if(realpath(path, _pathbuf) != NULL) + { + _filepath = _pathbuf; + } + else + { + perror("realpath error"); + _filepath = (char*)path; + } + + ret = accessp(path, amode); + + AFTER_ORIGINAL_NOFD(0, FD_API_PERMISSION, "%s, %d", path, amode); + + return ret; +} + +int faccessat(int fd, const char *path, int amode, int flag) +{ + static int (*faccessatp)(int fd, const char *path, int amode, int flag); + + BEFORE_ORIGINAL_FILE(faccessat, LIBC); + GET_FILEPATH_FROM_FD_AND_PATH; + if(realpath(path, _pathbuf) != NULL) + { + _filepath = _pathbuf; + } + else + { + perror("realpath error"); + _filepath = (char*)path; + } + + ret = faccessatp(fd, path, amode, flag); + + AFTER_ORIGINAL_NOFD(0, FD_API_PERMISSION, "%d, %s, %d, %d", fd, path, amode, flag); + + return ret; +} + +int truncate(const char *path, off_t length) +{ + static int (*truncatep)(const char *path, off_t length); + + BEFORE_ORIGINAL_FILE(truncate, LIBC); + if(realpath(path, _pathbuf) != NULL) + { + _filepath = _pathbuf; + } + else + { + perror("realpath error"); + _filepath = (char*)path; + } + + ret = truncatep(path, length); + + AFTER_ORIGINAL_NOFD((unsigned int)length, FD_API_DIRECTORY, + "%s, %ld", path, length); + + return ret; +} + +#if 1 +int mknod(const char *path, mode_t mode, dev_t dev) +{ + static int (*mknodp)(const char *path, mode_t mode, dev_t dev); + + BEFORE_ORIGINAL_FILE(mknod, LIBC); + if(realpath(path, _pathbuf) != NULL) + { + _filepath = _pathbuf; + } + else + { + perror("realpath error"); + _filepath = (char*)path; + } + + ret = mknodp(path, mode, dev); + + AFTER_ORIGINAL_NOFD(0, FD_API_OTHER, + "%s, %u, %lu", path, mode, (unsigned long int)dev); + + return ret; +} + +int mknodat(int fd, const char *path, mode_t mode, dev_t dev) +{ + static int (*mknodatp)(int fd, const char *path, mode_t mode, dev_t dev); + + BEFORE_ORIGINAL_FILE(mknodat, LIBC); + GET_FILEPATH_FROM_FD_AND_PATH; + if(realpath(path, _pathbuf) != NULL) + { + _filepath = _pathbuf; + } + else + { + perror("realpath error"); + _filepath = (char*)path; + } + + ret = mknodatp(fd,path, mode,dev); + + AFTER_ORIGINAL_NOFD(0, FD_API_OTHER, + "%d, %s, %u, %lu", fd, path, mode, (unsigned long int)dev); + + return ret; +} +#endif + +// **************************************************************** +// File Permission APIs +// **************************************************************** +int chown(const char *path, uid_t owner, gid_t group) +{ + static int (*chownp)(const char *path, uid_t owner, gid_t group); + + BEFORE_ORIGINAL_FILE(chown, LIBC); + if(realpath(path, _pathbuf) != NULL) + { + _filepath = _pathbuf; + } + else + { + perror("realpath error"); + _filepath = (char*)path; + } + ret = chownp(path, owner, group); + AFTER_ORIGINAL_NOFD(0, FD_API_PERMISSION, "%s, %u, %u", path, owner, group); + return ret; +} + +int fchownat(int fd, const char *path, uid_t owner, gid_t group, int flag) +{ + static int (*fchownatp)(int fd, const char *path, uid_t owner, gid_t group, int flag); + + BEFORE_ORIGINAL_FILE(fchownat, LIBC); + GET_FILEPATH_FROM_FD_AND_PATH; + if(realpath(path, _pathbuf) != NULL) + { + _filepath = _pathbuf; + } + else + { + perror("realpath error"); + _filepath = (char*)path; + } + ret = fchownatp(fd, path, owner, group, flag); + AFTER_ORIGINAL_NOFD(0, FD_API_PERMISSION, + "%d, %s, %u, %u, %d", fd, path, owner, group, flag); + return ret; +} + +int lchown(const char *path, uid_t owner, gid_t group) +{ + static int (*lchownp)(const char *path, uid_t owner, gid_t group); + + BEFORE_ORIGINAL_FILE(lchown, LIBC); + if(realpath(path, _pathbuf) != NULL) + { + _filepath = _pathbuf; + } + else + { + perror("realpath error"); + _filepath = (char*)path; + } + ret = lchownp(path, owner, group); + AFTER_ORIGINAL_NOFD(0, FD_API_PERMISSION, "%s, %u, %u", path, owner, group); + return ret; +} + +int chmod(const char *path, mode_t mode) +{ + static int (*chmodp)(const char *path, mode_t mode); + + BEFORE_ORIGINAL_FILE(chmod, LIBC); + if(realpath(path, _pathbuf) != NULL) + { + _filepath = _pathbuf; + } + else + { + perror("realpath error"); + _filepath = (char*)path; + } + ret = chmodp(path, mode); + AFTER_ORIGINAL_NOFD(0, FD_API_PERMISSION, "%s, %u", path, mode); + return ret; +} + +int fchmodat(int fd, const char *path, mode_t mode, int flag) +{ + static int (*fchmodatp)(int fd, const char *path, mode_t mode, int flag); + + BEFORE_ORIGINAL_FILE(fchmodat, LIBC); + GET_FILEPATH_FROM_FD_AND_PATH; + if(realpath(path, _pathbuf) != NULL) + { + _filepath = _pathbuf; + } + else + { + perror("realpath error"); + _filepath = (char*)path; + } + ret = fchmodatp(fd, path, mode, flag); + AFTER_ORIGINAL_NOFD(0, FD_API_PERMISSION, "%d, %s, %u, %d", fd, path, mode, flag); + return ret; +} + +int link(const char *path1, const char *path2) +{ + static int (*linkp)(const char *path1, const char *path2); + + BEFORE_ORIGINAL_FILE(link, LIBC); + if(realpath(path1, _pathbuf) != NULL) + { + _filepath = _pathbuf; + } + else + { + perror("realpath error"); + _filepath = (char*)path1; + } + ret = linkp(path1, path2); + AFTER_ORIGINAL_NOFD(0, FD_API_DIRECTORY, "%s, %s", path1, path2); + return ret; +} + +int linkat(int fd, const char *path, int fd2, const char *path2, int flag) +{ + static int (*linkatp)(int fd, const char *path, int fd2, const char *path2, int flag); + + BEFORE_ORIGINAL_FILE(linkat, LIBC); + GET_FILEPATH_FROM_FD_AND_PATH; + if(realpath(path, _pathbuf) != NULL) + { + _filepath = _pathbuf; + } + else + { + perror("realpath error"); + _filepath = (char*)path; + } + ret = linkatp(fd, path, fd2, path2, flag); + AFTER_ORIGINAL_NOFD(0, FD_API_DIRECTORY, + "%d, %s, %d, %s, %d", fd, path, fd2, path2, flag); + return ret; +} + +int unlink(const char *path) +{ + static int (*unlinkp)(const char *path); + + BEFORE_ORIGINAL_FILE(unlink, LIBC); + if(realpath(path, _pathbuf) != NULL) + { + _filepath = _pathbuf; + } + else + { + perror("realpath error"); + _filepath = (char*)path; + } + ret = unlinkp(path); + AFTER_ORIGINAL_NOFD(0, FD_API_DIRECTORY, "%s", path); + return ret; +} + +int unlinkat(int fd, const char *path, int flag) +{ + static int (*unlinkatp)(int fd, const char *path, int flag); + + BEFORE_ORIGINAL_FILE(unlinkat, LIBC); + GET_FILEPATH_FROM_FD_AND_PATH; + if(realpath(path, _pathbuf) != NULL) + { + _filepath = _pathbuf; + } + else + { + perror("realpath error"); + _filepath = (char*)path; + } + ret = unlinkatp(fd, path, flag); + AFTER_ORIGINAL_NOFD(0, FD_API_DIRECTORY, "%d, %s, %d", fd, path, flag); + return ret; +} + +int symlink(const char *path1, const char *path2) +{ + static int (*symlinkp)(const char *path1, const char *path2); + + BEFORE_ORIGINAL_FILE(symlink, LIBC); + if(realpath(path1, _pathbuf) != NULL) + { + _filepath = _pathbuf; + } + else + { + perror("realpath error"); + _filepath = (char*)path1; + } + ret = symlinkp(path1, path2); + AFTER_ORIGINAL_NOFD(0, FD_API_DIRECTORY, "%s, %s", path1, path2); + return ret; +} + +int symlinkat(const char *path1, int fd, const char *path2) +{ + static int (*symlinkatp)(const char *path1, int fd, const char *path2); + + BEFORE_ORIGINAL_FILE(symlinkat, LIBC); + if(realpath(path1, _pathbuf) != NULL) + { + _filepath = _pathbuf; + } + else + { + perror("realpath error"); + _filepath = (char*)path1; + } + ret = symlinkatp(path1, fd, path2); + AFTER_ORIGINAL_NOFD(0, FD_API_DIRECTORY, "%s, %d, %s", path1, fd, path2); + return ret; +} + +//FIXME dlsym error +#if 0 +int stat(const char * path, struct stat * buf) +{ + static int (*statp)(const char * path, struct stat * buf); + + BEFORE_ORIGINAL_FILE(stat, LIBC); + if(realpath(path, _pathbuf) != NULL) + { + _filepath = _pathbuf; + } + else + { + perror("realpath error"); + _filepath = (char*)path; + } + ret = statp(path, buf); + AFTER_ORIGINAL_NOFD(0, FD_API_OTHER, "%s, %p", path, buf); + return ret; +} +#endif + +int fstatat(int fd, const char * path, struct stat * buf, int flag) +{ + static int (*fstatatp)(int fd, const char * path, struct stat * buf, int flag); + + BEFORE_ORIGINAL_FILE(fstatat, LIBC); + GET_FILEPATH_FROM_FD_AND_PATH; + if(realpath(path, _pathbuf) != NULL) + { + _filepath = _pathbuf; + } + else + { + perror("realpath error"); + _filepath = (char*)path; + } + ret = fstatatp(fd, path, buf, flag); + AFTER_ORIGINAL_NOFD(0, FD_API_OTHER, "%d, %s, %p, %d", fd, path, buf, flag); + return ret; +} + +int lstat(const char * path, struct stat * buf) +{ + static int (*lstatp)(const char * path, struct stat * buf); + + BEFORE_ORIGINAL_FILE(lstat, LIBC); + if(realpath(path, _pathbuf) != NULL) + { + _filepath = _pathbuf; + } + else + { + perror("realpath error"); + _filepath = (char*)path; + } + ret = lstatp(path, buf); + AFTER_ORIGINAL_NOFD(0, FD_API_OTHER, "%s, %p", path, buf); + return ret; +} + +int utimensat(int fd, const char *path, const struct timespec times[2], int flag) +{ + static int (*utimensatp)(int fd, const char *path, const struct timespec times[2], int flag); + + BEFORE_ORIGINAL_FILE(utimensat, LIBC); + GET_FILEPATH_FROM_FD_AND_PATH; + if(realpath(path, _pathbuf) != NULL) + { + _filepath = _pathbuf; + } + else + { + perror("realpath error"); + _filepath = (char*)path; + } + ret = utimensatp(fd, path, times, flag); + AFTER_ORIGINAL_NOFD(0, FD_API_OTHER, "%d, %s, %p, %d", fd, path, times, flag); + return ret; +} + +int utimes(const char *path, const struct timeval times[2]) +{ + static int (*utimesp)(const char *path, const struct timeval times[2]); + + BEFORE_ORIGINAL_FILE(utimes, LIBC); + if(realpath(path, _pathbuf) != NULL) + { + _filepath = _pathbuf; + } + else + { + perror("realpath error"); + _filepath = (char*)path; + } + ret = utimesp(path, times); + AFTER_ORIGINAL_NOFD(0, FD_API_OTHER, "%s, %p", path, times); + return ret; +} + +int utime(const char *path, const struct utimbuf *times) +{ + static int (*utimep)(const char *path, const struct utimbuf *times); + + BEFORE_ORIGINAL_FILE(utime, LIBC); + if(realpath(path, _pathbuf) != NULL) + { + _filepath = _pathbuf; + } + else + { + perror("realpath error"); + _filepath = (char*)path; + } + ret = utimep(path, times); + AFTER_ORIGINAL_NOFD(0, FD_API_OTHER, "%s, %p", path, times); + return ret; +} +#endif diff --git a/probe_file/da_io_stdc.c b/probe_file/da_io_stdc.c new file mode 100644 index 0000000..3218b2e --- /dev/null +++ b/probe_file/da_io_stdc.c @@ -0,0 +1,634 @@ +/* + * DA probe + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Jaewon Lim + * Woojin Jung + * Juyoung Kim + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#include +#include +#include +#include +#include +#include +#include "daprobe.h" +#include "probeinfo.h" +#include "dautil.h" +#include "dahelper.h" +#include "da_io.h" + +static enum DaOptions _sopt = OPT_FILE; + +FILE* fopen(const char* filename, const char* mode) +{ + static FILE* (*fopenp)(const char* filename, const char* mode); + FILE* fret; + + BEFORE_ORIGINAL_FILE_NOFILTER(fopen, LIBC); + if(realpath(filename, _pathbuf) != NULL) + { + _filepath = _pathbuf; + } + else + { + perror("realpath error"); + _filepath = (char*)filename; + } + + fret = fopenp(filename, mode); + + AFTER_ORIGINAL_FILEP_RET(VT_PTR, fret, 0, fret, FD_API_OPEN, "%s, %s", filename, mode); + + return fret; +} + +FILE* freopen(const char * filename, const char * mode, FILE * stream) +{ + static FILE* (*freopenp)(const char * filename, const char * mode, FILE * stream); + FILE* fret; + + BEFORE_ORIGINAL_FILE_NOFILTER(freopen, LIBC); + if(realpath(filename, _pathbuf) != NULL) + { + _filepath = _pathbuf; + } + else + { + perror("realpath error"); + _filepath = (char*)filename; + } + + fret = freopenp(filename, mode, stream); + + AFTER_ORIGINAL_FILEP_RET(VT_PTR, fret, 0, fret, FD_API_OPEN, + "%s, %s, %p", filename, mode, stream); + + return fret; +} + +FILE* fdopen(int fd, const char *mode) +{ + static FILE* (*fdopenp)(int fd, const char *mode); + FILE* fret; + + BEFORE_ORIGINAL_FILE_NOFILTER(fdopen, LIBC); + GET_FILEPATH_FROM_FD(fd); + + fret = fdopenp(fd, mode); + + AFTER_ORIGINAL_FILEP_RET(VT_PTR, fret, 0, fret, FD_API_OPEN, "%d, %s", fd, mode); + + return fret; +} + +int fflush(FILE* stream) +{ + static int (*fflushp)(FILE* stream); + + BEFORE_ORIGINAL_FILE(fflush, LIBC); + GET_FILEPATH_FROM_FILEP(stream); + ret = fflushp(stream); + AFTER_ORIGINAL_FILEP(0, stream, FD_API_OTHER, "%p", stream); + return ret; +} + +int fclose(FILE* stream) +{ + static int (*fclosep)(FILE* stream); + DECLARE_VARIABLE_FD; + + GET_REAL_FUNC(fclose, LIBC); + + bfiltering = false; + PRE_PROBEBLOCK_BEGIN(); + GET_FD_FROM_FILEP(stream); + if(_fd != -1) { + _fstatret = fstat(_fd, &_statbuf); + } + GET_FILEPATH_FROM_FD(_fd); + PRE_PROBEBLOCK_END(); + + ret = fclosep(stream); + + POST_PROBEBLOCK_BEGIN(LC_RESOURCE, VT_INT, ret, "%p", stream); + POST_PROBEBLOCK_MIDDLE_FD(0, _fd, FD_API_CLOSE); + POST_PROBEBLOCK_CALLSTACK_RESOURCE(FD_API_CLOSE); + POST_PROBEBLOCK_END(); + + return ret; +} + +FILE * tmpfile ( void ) +{ + static FILE* (*tmpfilep) ( void ); + FILE* fret; + + BEFORE_ORIGINAL_FILE_NOFILTER(tmpfile, LIBC); + _filepath = ""; + fret = tmpfilep(); + + AFTER_ORIGINAL_FILEP_RET(VT_PTR, fret, 0, fret, FD_API_OPEN, "%s", ""); + + return fret; +} + +int fgetpos(FILE* stream, fpos_t* position) +{ + static int (*fgetposp)(FILE* stream, fpos_t* position); + + BEFORE_ORIGINAL_FILE(fgetpos, LIBC); + GET_FILEPATH_FROM_FILEP(stream); + ret = fgetposp(stream, position); + AFTER_ORIGINAL_FILEP(0, stream, FD_API_OTHER, "%p, %p", stream, position); + return ret; +} + +int fseek(FILE* stream, long int offset, int origin) +{ + static int (*fseekp)(FILE* stream, long int offset, int origin); + + BEFORE_ORIGINAL_FILE(fseek, LIBC); + GET_FILEPATH_FROM_FILEP(stream); + ret = fseekp(stream, offset, origin); + AFTER_ORIGINAL_FILEP((unsigned int)offset, stream, FD_API_OTHER, + "%p, %ld, %d", stream, offset, origin); + return ret; +} + +int fsetpos(FILE* stream, const fpos_t* pos) +{ + static int (*fsetposp)(FILE* stream, const fpos_t* pos); + + BEFORE_ORIGINAL_FILE(fsetpos, LIBC); + GET_FILEPATH_FROM_FILEP(stream); + ret = fsetposp(stream, pos); + AFTER_ORIGINAL_FILEP(0, stream, FD_API_OTHER, "%p, %p", stream, pos); + return ret; +} + +long int ftell(FILE* stream) +{ + static long int (*ftellp)(FILE* stream); + long int lret; + + BEFORE_ORIGINAL_FILE(ftell, LIBC); + GET_FILEPATH_FROM_FILEP(stream); + + lret = ftellp(stream); + + AFTER_ORIGINAL_FILEP_RET(VT_LONG, lret, 0, stream, FD_API_OTHER, "%p", stream); + + return lret; +} + +void rewind(FILE* stream) +{ + static void (*rewindp)(FILE* stream); + + BEFORE_ORIGINAL_FILE(rewind, LIBC); + GET_FILEPATH_FROM_FILEP(stream); + + rewindp(stream); + + AFTER_ORIGINAL_FILEP_RET(VT_NULL, NULL, 0, stream, FD_API_OTHER, "%p", stream); +} + +void clearerr(FILE* stream) +{ + static void (*clearerrp)(FILE* stream); + + BEFORE_ORIGINAL_FILE(clearerr, LIBC); + GET_FILEPATH_FROM_FILEP(stream); + + clearerrp(stream); + + AFTER_ORIGINAL_FILEP_RET(VT_NULL, NULL, 0, stream, FD_API_OTHER, "%p", stream); +} + +int feof(FILE* stream) +{ + static int (*feofp)(FILE* stream); + + BEFORE_ORIGINAL_FILE(feof, LIBC); + GET_FILEPATH_FROM_FILEP(stream); + ret = feofp(stream); + AFTER_ORIGINAL_FILEP(0, stream, FD_API_OTHER, "%p", stream); + return ret; +} + +int ferror(FILE* stream) +{ + static int (*ferrorp)(FILE* stream); + + BEFORE_ORIGINAL_FILE(ferror, LIBC); + GET_FILEPATH_FROM_FILEP(stream); + ret = ferrorp(stream); + AFTER_ORIGINAL_FILEP(0, stream, FD_API_OTHER, "%p", stream); + return ret; +} + +int fileno(FILE* stream) +{ + static int (*filenop)(FILE* stream); + + BEFORE_ORIGINAL_FILE(fileno, LIBC); + _fd = (stream != NULL) ? filenop(stream) : -1; + GET_FILEPATH_FROM_FD(_fd); + ret = filenop(stream); + AFTER_ORIGINAL_FILEP(0, stream, FD_API_OTHER, "%p", stream); + return ret; +} + +// ******************************************************************* +// File read / write APIs +// ******************************************************************* + +int vfprintf(FILE* stream, const char* format, va_list arg) +{ + static int (*vfprintfp)(FILE* stream, const char* format, va_list arg); + + BEFORE_ORIGINAL_START_END_FILEP(vfprintf, LIBC, stream, FD_API_WRITE_START, "%p, %s", stream, format); + GET_FILEPATH_FROM_FILEP(stream); + ret = vfprintfp(stream, format, arg); + AFTER_ORIGINAL_START_END_FILEP(ret, stream, FD_API_WRITE_END, "%p, %s", stream, format); + return ret; +} + +int vfscanf(FILE* stream, const char* format, va_list arg) +{ + static int (*vfscanfp)(FILE* stream, const char* format, va_list arg); + + BEFORE_ORIGINAL_START_END_FILEP(vfscanf, LIBC, stream, FD_API_READ_START, "%p, %s", stream, format); + GET_FILEPATH_FROM_FILEP(stream); + ret = vfscanfp(stream, format, arg); + AFTER_ORIGINAL_START_END_FILEP(ret, stream, FD_API_READ_END, "%p, %s", stream, format); + return ret; +} + +int fgetc(FILE* stream) +{ + static int (*fgetcp)(FILE* stream); + + BEFORE_ORIGINAL_START_END_FILEP(fgetc, LIBC, stream, FD_API_READ_START, "%p", stream); + GET_FILEPATH_FROM_FILEP(stream); + ret = fgetcp(stream); + AFTER_ORIGINAL_START_END_FILEP((ret == EOF ? 0 : 1), stream, FD_API_READ_END, "%p", stream); + return ret; +} + +#if 0 // why is this commented? +char* fgets(char* str, int size, FILE* stream) +{ + static char* (*fgetsp)(char* str, int num, FILE* stream); + char* cret; + + BEFORE_ORIGINAL_START_END_FILEP(fgets, LIBC, stream, FD_API_READ_START, "%s, %d, %p", str, size, stream); + GET_FILEPATH_FROM_FILEP(stream); + + cret = fgetsp(str, size, stream); + + AFTER_ORIGINAL_START_END_FILEP_RET(VT_STR, cret, (ret == NULL ? 0 : strlen(cret)), stream, FD_API_READ_END, "%s, %d, %p", str, size, stream); + + return cret; +} +#endif + +int fputc(int character, FILE* stream) +{ + static int (*fputcp)(int character, FILE* stream); + + BEFORE_ORIGINAL_START_END_FILEP(fputc, LIBC, stream, FD_API_WRITE_START, "%d, %p", character, stream); + GET_FILEPATH_FROM_FILEP(stream); + ret = fputcp(character, stream); + AFTER_ORIGINAL_START_END_FILEP((ret == EOF ? 0 : 1), stream, FD_API_WRITE_END, "%d, %p", character, stream); + return ret; +} + +int fputs(const char* str, FILE* stream) +{ + static int (*fputsp)(const char* str, FILE* stream); + + BEFORE_ORIGINAL_START_END_FILEP(fputs, LIBC, stream, FD_API_WRITE_START, "%s, %p", str, stream); + GET_FILEPATH_FROM_FILEP(stream); + ret = fputsp(str, stream); + AFTER_ORIGINAL_START_END_FILEP(ret, stream, FD_API_WRITE_END, "%s, %p", str, stream); + return ret; +} + +int getc(FILE* stream) +{ + static int (*getcp)(FILE* stream); + + BEFORE_ORIGINAL_START_END_FILEP(getc, LIBC, stream, FD_API_READ_START, "%p", stream); + GET_FILEPATH_FROM_FILEP(stream); + ret = getcp(stream); + AFTER_ORIGINAL_START_END_FILEP((ret == EOF ? 0 : 1), stream, FD_API_READ_END, "%p", stream); + return ret; +} + +int putc(int character, FILE* stream) +{ + static int (*putcp)(int character, FILE* stream); + + BEFORE_ORIGINAL_START_END_FILEP(putc, LIBC, stream, FD_API_WRITE_START, "%d, %p", character, stream); + GET_FILEPATH_FROM_FILEP(stream); + ret = putcp(character, stream); + AFTER_ORIGINAL_START_END_FILEP((ret == EOF ? 0 : 1), stream, FD_API_WRITE_END, "%d, %p", character, stream); + return ret; +} + +int ungetc(int character, FILE* stream) +{ + static int (*ungetcp)(int character, FILE* stream); + + BEFORE_ORIGINAL_FILE(ungetc, LIBC); + GET_FILEPATH_FROM_FILEP(stream); + ret = ungetcp(character, stream); + AFTER_ORIGINAL_FILEP(0, stream, FD_API_OTHER, "%d, %p", character, stream); + return ret; +} + +size_t fread(void* ptr, size_t size, size_t count, FILE* stream) +{ + static size_t (*freadp)(void* ptr, size_t size, size_t count, FILE* stream); + size_t tret; + + BEFORE_ORIGINAL_START_END_FILEP(fread, LIBC, stream, FD_API_READ_START, "%p, %u, %u, %p", ptr, size, count, stream); + GET_FILEPATH_FROM_FILEP(stream); + + tret = freadp(ptr, size, count, stream); + + AFTER_ORIGINAL_START_END_FILEP_RET(VT_SIZE_T, tret, 0, stream, FD_API_READ_END, "%p, %u, %u, %p", ptr, size, count, stream); + + return tret; +} + +size_t fwrite(const void* ptr, size_t size, size_t count, FILE* stream) +{ + static size_t (*fwritep)(const void* ptr, size_t size, size_t count, FILE* stream); + size_t tret; + + BEFORE_ORIGINAL_START_END_FILEP(fwrite, LIBC, stream, FD_API_WRITE_START, "%p, %u, %u, %p", ptr, size, count, stream); + GET_FILEPATH_FROM_FILEP(stream); + + tret = fwritep(ptr, size, count, stream); + + AFTER_ORIGINAL_START_END_FILEP_RET(VT_SIZE_T, tret, 0, stream, FD_API_WRITE_END, "%p, %u, %u, %p", ptr, size, count, stream); + + return tret; +} + +// ********************************************************* +// variable parameter function +// ********************************************************* +int fprintf(FILE* stream, const char* format, ...) +{ + static int (*vfprintfp)(FILE* stream, const char* format, ...); + + BEFORE_ORIGINAL_START_END_FILEP(vfprintf, LIBC, stream, FD_API_WRITE_START, "%p, %s, ...", stream, format); + GET_FILEPATH_FROM_FILEP(stream); + + va_list arg; + va_start(arg, format); + ret = vfprintfp(stream, format, arg); + + AFTER_ORIGINAL_START_END_FILEP(ret, stream, FD_API_WRITE_END, "%p, %s, ...", stream, format); + va_end(arg); + + return ret; +} + +int fscanf(FILE* stream, const char* format, ...) +{ + static int (*vfscanfp)(FILE* stream, const char* format, ...); + + BEFORE_ORIGINAL_START_END_FILEP(vfscanf, LIBC, stream, FD_API_READ_START, "%p, %s, ...", stream, format); + GET_FILEPATH_FROM_FILEP(stream); + + va_list arg; + va_start(arg, format); + ret = vfscanfp(stream, format, arg); + + AFTER_ORIGINAL_START_END_FILEP(ret, stream, FD_API_READ_END, "%p, %s, ...", stream, format); + va_end(arg); + + return ret; +} + +#if !defined(DA_DEBUG_LOG) && !defined(PRINT_STDOUT) +int printf(const char* format, ...) +{ + static int (*vprintfp)(const char* format, ...); + + BEFORE_ORIGINAL_START_END_NOFD(vprintf, LIBC, FD_API_WRITE_START, "%s,...", format); + + va_list arg; + va_start(arg, format); + ret = vprintfp(format, arg); + + AFTER_ORIGINAL_START_END_NOFD(ret, FD_API_WRITE_END, "%s,...", format); + va_end(arg); + + return ret; +} +#endif + +int scanf(const char* format, ...) +{ + static int (*vscanfp)(const char* format, ...); + + BEFORE_ORIGINAL_START_END_NOFD(vscanf, LIBC, FD_API_READ_START, "%s,...", format); + + va_list arg; + va_start(arg, format); + ret = vscanfp(format, arg); + + AFTER_ORIGINAL_START_END_NOFD(ret, FD_API_READ_END, "%s,...", format); + va_end(arg); + + return ret; +} + +int getchar() +{ + static int (*getcharp)(); + + BEFORE_ORIGINAL_START_END_NOFD(getchar, LIBC, FD_API_READ_START, "%s", ""); + ret = getcharp(); + AFTER_ORIGINAL_START_END_NOFD((ret == EOF ? 0 : 1), FD_API_READ_END, "%s", ""); + return ret; +} + +int putchar(int c) +{ + static int (*putcharp)(int c); + + BEFORE_ORIGINAL_START_END_NOFD(putchar, LIBC, FD_API_WRITE_START, "%d", c); + ret = putcharp(c); + AFTER_ORIGINAL_START_END_NOFD((ret == EOF ? 0 : 1), FD_API_WRITE_END, "%d", c); + return ret; +} + +char* gets(char* str) +{ + static char* (*getsp)(char* str); + char* cret; + + BEFORE_ORIGINAL_START_END_NOFD(gets, LIBC, FD_API_READ_START, "%s", str); + + cret = getsp(str); + + AFTER_ORIGINAL_START_END_NOFD_RET(VT_STR, cret, strlen(cret), FD_API_READ_END, "%s", str); + + return cret; +} + +#if !defined(DA_DEBUG_LOG) && !defined(PRINT_STDOUT) +int puts(const char* str) +{ + static int (*putsp)(const char* str); + + BEFORE_ORIGINAL_START_END_NOFD(puts, LIBC, FD_API_WRITE_START, "%s", str); + ret = putsp(str); + AFTER_ORIGINAL_START_END_NOFD(ret, FD_API_WRITE_END, "%s", str); + return ret; +} +#endif + +void setbuf(FILE* stream, char* buf) +{ + static void (*setbufp)(FILE* stream, char* buf); + + BEFORE_ORIGINAL_FILE(setbuf, LIBC); + GET_FILEPATH_FROM_FILEP(stream); + + setbufp(stream, buf); + + AFTER_ORIGINAL_FILEP_RET(VT_NULL, NULL, 0, stream, FD_API_OTHER, + "%p, %p", stream, buf); +} + +void setbuffer(FILE* stream, char* buf, size_t size) +{ + static void (*setbufferp)(FILE* stream, char* buf, size_t size); + + BEFORE_ORIGINAL_FILE(setbuffer, LIBC); + GET_FILEPATH_FROM_FILEP(stream); + + setbufferp(stream, buf, size); + + AFTER_ORIGINAL_FILEP_RET(VT_NULL, NULL, size, stream, FD_API_OTHER, + "%p, %p, %u", stream, buf, size); +} + +void setlinebuf(FILE* stream) +{ + static int (*setlinebufp)(FILE* stream); + + BEFORE_ORIGINAL_FILE(setlinebuf, LIBC); + GET_FILEPATH_FROM_FILEP(stream); + + setlinebufp(stream); + + AFTER_ORIGINAL_FILEP_RET(VT_NULL, NULL, 0, stream, FD_API_OTHER, "%p", stream); +} + +int setvbuf(FILE* stream, char* buf, int mode, size_t size) +{ + static int (*setvbufp)(FILE* stream, char* buf, int mode, size_t size); + + BEFORE_ORIGINAL_FILE(setvbuf, LIBC); + GET_FILEPATH_FROM_FILEP(stream); + ret = setvbufp(stream,buf,mode,size); + AFTER_ORIGINAL_FILEP(size, stream, FD_API_OTHER, + "%p, %p, %d, %u", stream, buf, mode, size); + return ret; +} + +#ifdef UNUSED_PROBE +int remove(const char* filename) +{ + static int (*removep)(const char* filename); + + BEFORE_ORIGINAL_FILE(remove, LIBC); + if(realpath(filename, _pathbuf) != NULL) + { + _filepath = _pathbuf; + } + else + { + perror("realpath error"); + _filepath = (char*)filename; + } + ret = removep(filename); + AFTER_ORIGINAL_NOFD(0, FD_API_DIRECTORY, "%s", filename); + return ret; +} + +int rename(const char* oldname, const char* newname) +{ + static int (*renamep)(const char* oldname, const char* newname); + + BEFORE_ORIGINAL_FILE(rename, LIBC); + if(realpath(oldname, _pathbuf) != NULL) + { + _filepath = _pathbuf; + } + else + { + perror("realpath error"); + _filepath = (char*)oldname; + } + ret = renamep(oldname, newname); + AFTER_ORIGINAL_NOFD(0, FD_API_DIRECTORY, "%s, %s", oldname, newname); + return ret; +} + +void perror(const char* string) +{ + static void (*perrorp)(const char* string); + + BEFORE_ORIGINAL_FILE(perror, LIBC); + + perrorp(string); + + AFTER_ORIGINAL_NOFD_RET(VT_NULL, NULL, 0, FD_API_OTHER, "%s", string); +} + +char* tmpnam(char* str) +{ + static char* (*tmpnamp)(char* str); + char* cret; + + BEFORE_ORIGINAL_FILE(tmpnam, LIBC); + + cret = tmpnamp(str); + + AFTER_ORIGINAL_NOFD_RET(VT_STR, cret, 0, FD_API_OTHER, "%s", str); + + return cret; +} +#endif diff --git a/probe_memory/da_memory.h b/probe_memory/da_memory.h new file mode 100644 index 0000000..d0e7bdb --- /dev/null +++ b/probe_memory/da_memory.h @@ -0,0 +1,65 @@ +/* + * DA probe + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Jaewon Lim + * Woojin Jung + * Juyoung Kim + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#ifndef __DA_MEMORY_H__ +#define __DA_MEMORY_H__ + +#include "daprobe.h" + +//#define INTERNALFILTERING (!isEnableInternalMalloc()) +#define INTERNAL_MALLOC_FILTERING true +#define INTERNAL_FREE_FILTERING true +#define INTERNAL_NEW_FILTERING true +#define INTERNAL_DELETE_FILTERING true + +/******************************************************************* + * MEMORY PROBE MACRO + * + * log format + * SeqNumber`,ApiName`,Time`,Pid`,Tid`,InputParm`,Return`,PCAddr`,Error`, + * Size`,MemoryAPIType`,Addr`,\n + * callstack_start`,callstack`,callstack_end + * + ********************************************************************/ + +#define POST_PROBEBLOCK_MIDDLE_MEM(SIZE, APITYPE, ADDR) \ + log.length += sprintf(log.data + log.length, \ + "`,%u`,%d`,%p", SIZE, APITYPE, ADDR) + +#define POST_PROBEBLOCK_BEGIN_MEM(LCTYPE, APINAME, RETTYPE, RETVALUE, INPUTFORMAT, ...) \ + newerrno = errno; \ + if(postBlockBegin(blockresult)) { \ + INIT_LOG; \ + APPEND_LOG_BASIC_NAME(LCTYPE, APINAME); \ + APPEND_LOG_INPUT(INPUTFORMAT, __VA_ARGS__); \ + APPEND_LOG_RESULT(RETTYPE, RETVALUE); \ + APPEND_LOG_CALLER() + +#endif // __DA_MEMORY_H__ diff --git a/probe_memory/libdamemalloc.c b/probe_memory/libdamemalloc.c new file mode 100755 index 0000000..1e51b83 --- /dev/null +++ b/probe_memory/libdamemalloc.c @@ -0,0 +1,183 @@ +/* + * DA probe + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Jaewon Lim + * Woojin Jung + * Juyoung Kim + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include "daprobe.h" +#include "probeinfo.h" +#include "dacollection.h" +#include "dautil.h" +#include "da_memory.h" + +#define EXTRA_MEM_SIZE 20 +static char extra_mem[EXTRA_MEM_SIZE]; +static enum DaOptions _sopt = OPT_ALLOC; + +void *malloc(size_t size) +{ + static void*(*mallocp)(size_t size); + DECLARE_VARIABLE_STANDARD; + void *pret; + + GET_REAL_FUNC_RTLD_NEXT(malloc); + + bfiltering = INTERNAL_MALLOC_FILTERING; + PRE_PROBEBLOCK(); + + pret = mallocp(size); + + if(pret != NULL && gProbeBlockCount == 0) + { + add_memory_hash(pret, size, MEMTYPE_ALLOC, blockresult ? MEM_EXTERNAL : MEM_INTERNAL); + } + + POST_PROBEBLOCK_BEGIN(LC_MEMORY, VT_PTR, pret, "%u", size); + POST_PROBEBLOCK_MIDDLE_MEM(size, MEMORY_API_ALLOC, pret); + APPEND_LOG_CALLSTACK(); + POST_PROBEBLOCK_END(); + + return pret; +} + +void free(void *ptr) +{ + static void (*freep)(void *); + DECLARE_VARIABLE_STANDARD; + + GET_REAL_FUNC_RTLD_NEXT(free); + + bfiltering = INTERNAL_FREE_FILTERING; + PRE_PROBEBLOCK(); + + if(ptr != NULL && gProbeBlockCount == 0) + { + del_memory_hash(ptr, MEMTYPE_FREE, NULL); + } + + freep(ptr); + + POST_PROBEBLOCK_BEGIN(LC_MEMORY, VT_NULL, NULL, "%p", ptr); + POST_PROBEBLOCK_MIDDLE_MEM(0, MEMORY_API_FREE, ptr); + POST_PROBEBLOCK_CALLSTACK(); + POST_PROBEBLOCK_END(); +} + +/* calloc's helper fucntion + * - dlsym calls calloc - recursion occurs + * - first dlsym calls temp_calloc + * */ +void *temp_calloc(size_t nelem, size_t elsize) +{ + int i; + if(nelem * elsize > EXTRA_MEM_SIZE) + { + PRINTMSG("temp_calloc size error\n"); + abort(); + } + for(i = 0; i < elsize * nelem; i++) + { + extra_mem[i] = 0; + } + //memset(extra_mem,0,elsize*nelem); + return extra_mem; +} + +void *calloc(size_t nelem, size_t elsize) +{ + static void *(*callocp)(size_t,size_t); + DECLARE_VARIABLE_STANDARD; + void *pret; + + if(!callocp) { + probeBlockStart(); + callocp = temp_calloc; // make callocp is not null for dlsym + // dlsym use calloc function + callocp = dlsym(RTLD_NEXT, "calloc"); + if(callocp == NULL || dlerror() != NULL) { + perror("calloc dlsym failed"); + exit(0); + } + probeBlockEnd(); + } + + bfiltering = INTERNAL_MALLOC_FILTERING; + PRE_PROBEBLOCK(); + + pret = callocp(nelem, elsize); + + if(pret != NULL && gProbeBlockCount == 0) + { + add_memory_hash(pret, nelem * elsize, MEMTYPE_ALLOC, blockresult ? MEM_EXTERNAL : MEM_INTERNAL); + } + + POST_PROBEBLOCK_BEGIN(LC_MEMORY, VT_PTR, pret, "%u, %u", nelem, elsize); + POST_PROBEBLOCK_MIDDLE_MEM(nelem * elsize, MEMORY_API_ALLOC, pret); + APPEND_LOG_CALLSTACK(); + POST_PROBEBLOCK_END(); + + return pret; +} + +void *realloc(void *memblock, size_t size) +{ + static void *(*reallocp)(void *,size_t); + DECLARE_VARIABLE_STANDARD; + void *pret; + + GET_REAL_FUNC_RTLD_NEXT(realloc); + + bfiltering = INTERNAL_MALLOC_FILTERING; + PRE_PROBEBLOCK(); + + if(memblock != NULL && gProbeBlockCount == 0) + { + del_memory_hash(memblock, MEMTYPE_FREE, NULL); + } + + pret = reallocp(memblock, size); + + if(pret != NULL && gProbeBlockCount == 0) + { + add_memory_hash(pret, size, MEMTYPE_ALLOC, blockresult ? MEM_EXTERNAL : MEM_INTERNAL); + } + + POST_PROBEBLOCK_BEGIN(LC_MEMORY, VT_PTR, pret, "%p, %u", memblock, size); + POST_PROBEBLOCK_MIDDLE_MEM(size, MEMORY_API_ALLOC, pret); + APPEND_LOG_CALLSTACK(); + POST_PROBEBLOCK_END(); + + return pret; +} + diff --git a/probe_memory/libdamemmanage.c b/probe_memory/libdamemmanage.c new file mode 100644 index 0000000..80d17c2 --- /dev/null +++ b/probe_memory/libdamemmanage.c @@ -0,0 +1,103 @@ +/* + * DA probe + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Jaewon Lim + * Woojin Jung + * Juyoung Kim + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include "daprobe.h" +#include "probeinfo.h" +#include "dautil.h" +#include "da_memory.h" + +static enum DaOptions _sopt = OPT_ALLOC; + +void *memset(void *memblock, int c, size_t n) +{ + static void *(*memsetp)(void *,int,size_t); + DECLARE_VARIABLE_STANDARD; + void *pret; + + GET_REAL_FUNC_RTLD_NEXT(memset); + + PRE_PROBEBLOCK(); + + pret = memsetp(memblock, c, n); + + POST_PROBEBLOCK_BEGIN(LC_MEMORY, VT_PTR, pret, "%p, %d, %u", memblock, c, n); + POST_PROBEBLOCK_MIDDLE_MEM(n, MEMORY_API_MANAGE, memblock); + POST_PROBEBLOCK_CALLSTACK(); + POST_PROBEBLOCK_END(); + + return pret; +} + +int memcmp(const void * ptr1, const void * ptr2, size_t num) +{ + static int(*memcmpp)(const void *,const void *,size_t); + DECLARE_VARIABLE_STANDARD; + + GET_REAL_FUNC_RTLD_NEXT(memcmp); + + PRE_PROBEBLOCK(); + + ret = memcmpp(ptr1, ptr2, num); + + POST_PROBEBLOCK_BEGIN(LC_MEMORY, VT_INT, ret, "%p, %p, %u", ptr1, ptr2, num); + POST_PROBEBLOCK_MIDDLE_MEM(num, MEMORY_API_MANAGE, ptr1); + POST_PROBEBLOCK_CALLSTACK(); + POST_PROBEBLOCK_END(); + + return ret; +} + +void *memcpy(void * destination, const void * source, size_t num ) +{ + static void *(*memcpyp)(void *,const void *,size_t); + DECLARE_VARIABLE_STANDARD; + void *pret; + + GET_REAL_FUNC_RTLD_NEXT(memcpy); + + PRE_PROBEBLOCK(); + + pret = memcpyp(destination, source, num); + + POST_PROBEBLOCK_BEGIN(LC_MEMORY, VT_PTR, pret, "%p, %p, %u", destination, source, num); + POST_PROBEBLOCK_MIDDLE_MEM(num, MEMORY_API_MANAGE, destination); + POST_PROBEBLOCK_CALLSTACK(); + POST_PROBEBLOCK_END(); + + return pret; +} + diff --git a/probe_memory/libdanew.cpp b/probe_memory/libdanew.cpp new file mode 100644 index 0000000..0df3776 --- /dev/null +++ b/probe_memory/libdanew.cpp @@ -0,0 +1,276 @@ +/* + * DA probe + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Woojin Jung + * Jaewon Lim + * Juyoung Kim + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include "daprobe.h" +#include "probeinfo.h" +#include "dacollection.h" +#include "da_memory.h" + +static enum DaOptions _sopt = OPT_ALLOC; + +void *operator new(std::size_t size) throw (std::bad_alloc) +{ + static void*(*newp)(std::size_t size); + DECLARE_VARIABLE_STANDARD; + void *pret; + + GET_REAL_FUNCP_RTLD_NEXT_CPP(_Znwj,newp); + + bfiltering = INTERNAL_NEW_FILTERING; + PRE_PROBEBLOCK(); + + pret = newp(size); + + if(pret != NULL && gProbeBlockCount == 0) + { + add_memory_hash(pret, size, MEMTYPE_NEW, blockresult ? MEM_EXTERNAL : MEM_INTERNAL); + } + + POST_PROBEBLOCK_BEGIN_MEM(LC_MEMORY, "new", VT_PTR, pret, "%u", size); + POST_PROBEBLOCK_MIDDLE_MEM(size, MEMORY_API_ALLOC, pret); + APPEND_LOG_CALLSTACK(); + POST_PROBEBLOCK_END(); + + return pret; +} + +void *operator new[](std::size_t size) throw (std::bad_alloc) +{ + static void*(*newp)(std::size_t size); + DECLARE_VARIABLE_STANDARD; + void *pret; + + GET_REAL_FUNCP_RTLD_NEXT_CPP(_Znaj, newp); + + bfiltering = INTERNAL_NEW_FILTERING; + PRE_PROBEBLOCK(); + + pret = newp(size); + + if(pret != NULL && gProbeBlockCount == 0) + { + add_memory_hash(pret, size, MEMTYPE_NEW, blockresult ? MEM_EXTERNAL : MEM_INTERNAL); + } + + POST_PROBEBLOCK_BEGIN_MEM(LC_MEMORY, "new", VT_PTR, pret, "%u", size); + POST_PROBEBLOCK_MIDDLE_MEM(size, MEMORY_API_ALLOC, pret); + APPEND_LOG_CALLSTACK(); + POST_PROBEBLOCK_END(); + + return pret; +} + +void operator delete(void *ptr) throw() +{ + static void (*deletep)(void *ptr); + DECLARE_VARIABLE_STANDARD; + unsigned short caller; + + GET_REAL_FUNCP_RTLD_NEXT_CPP(_ZdlPv, deletep); + + bfiltering = INTERNAL_DELETE_FILTERING; + PRE_PROBEBLOCK(); + + if(ptr != NULL && gProbeBlockCount == 0) + { + probeBlockStart(); + ret = del_memory_hash(ptr, MEMTYPE_DELETE, &caller); + if(blockresult == 0 && ret == 0 && caller == MEM_EXTERNAL) + { + setProbePoint(&probeInfo); + blockresult = 2; + probingStart(); + } + probeBlockEnd(); + } + + deletep(ptr); + + POST_PROBEBLOCK_BEGIN_MEM(LC_MEMORY, "delete", VT_NULL, NULL, "%p", ptr); + POST_PROBEBLOCK_MIDDLE_MEM(0, MEMORY_API_FREE, ptr); + POST_PROBEBLOCK_CALLSTACK(); + POST_PROBEBLOCK_END(); +} + +void operator delete[](void *ptr) throw() +{ + static void (*deletep)(void *ptr); + DECLARE_VARIABLE_STANDARD; + unsigned short caller; + + GET_REAL_FUNCP_RTLD_NEXT_CPP(_ZdaPv, deletep); + + bfiltering = INTERNAL_DELETE_FILTERING; + PRE_PROBEBLOCK(); + + if(ptr != NULL && gProbeBlockCount == 0) + { + probeBlockStart(); + ret = del_memory_hash(ptr, MEMTYPE_DELETE, &caller); + if(blockresult == 0 && ret == 0 && caller == MEM_EXTERNAL) + { + setProbePoint(&probeInfo); + blockresult = 2; + probingStart(); + } + probeBlockEnd(); + } + + deletep(ptr); + + POST_PROBEBLOCK_BEGIN_MEM(LC_MEMORY, "delete", VT_NULL, NULL, "%p", ptr); + POST_PROBEBLOCK_MIDDLE_MEM(0, MEMORY_API_FREE, ptr); + POST_PROBEBLOCK_CALLSTACK(); + POST_PROBEBLOCK_END(); +} + +void *operator new(std::size_t size, const std::nothrow_t& nothrow) throw() +{ + static void*(*newp)(std::size_t size, const std::nothrow_t& nothrow); + DECLARE_VARIABLE_STANDARD; + void *pret; + + GET_REAL_FUNCP_RTLD_NEXT_CPP(_ZnwjRKSt9nothrow_t, newp); + + bfiltering = INTERNAL_NEW_FILTERING; + PRE_PROBEBLOCK(); + + pret = newp(size, nothrow); + + if(pret != NULL && gProbeBlockCount == 0) + { + add_memory_hash(pret, size, MEMTYPE_NEW, blockresult ? MEM_EXTERNAL : MEM_INTERNAL); + } + + POST_PROBEBLOCK_BEGIN_MEM(LC_MEMORY, "new", VT_PTR, pret, "%u", size); + POST_PROBEBLOCK_MIDDLE_MEM(size, MEMORY_API_ALLOC, pret); + APPEND_LOG_CALLSTACK(); + POST_PROBEBLOCK_END(); + + return pret; +} + +void *operator new[](std::size_t size, const std::nothrow_t& nothrow) throw() +{ + static void*(*newp)(std::size_t size, const std::nothrow_t& nothrow); + DECLARE_VARIABLE_STANDARD; + void *pret; + + GET_REAL_FUNCP_RTLD_NEXT_CPP(_ZnajRKSt9nothrow_t, newp); + + bfiltering = INTERNAL_NEW_FILTERING; + PRE_PROBEBLOCK(); + + pret = newp(size, nothrow); + + if(pret != NULL && gProbeBlockCount == 0) + { + add_memory_hash(pret, size, MEMTYPE_NEW, blockresult ? MEM_EXTERNAL : MEM_INTERNAL); + } + + POST_PROBEBLOCK_BEGIN_MEM(LC_MEMORY, "new", VT_PTR, pret, "%u", size); + POST_PROBEBLOCK_MIDDLE_MEM(size, MEMORY_API_ALLOC, pret); + APPEND_LOG_CALLSTACK(); + POST_PROBEBLOCK_END(); + + return pret; +} + +void operator delete(void *ptr, const std::nothrow_t& nothrow) throw() +{ + static void (*deletep)(void *ptr, const std::nothrow_t& nothrow); + DECLARE_VARIABLE_STANDARD; + unsigned short caller; + + GET_REAL_FUNCP_RTLD_NEXT_CPP(_ZdlPvRKSt9nothrow_t, deletep); + + bfiltering = INTERNAL_DELETE_FILTERING; + PRE_PROBEBLOCK(); + + if(ptr != NULL && gProbeBlockCount == 0) + { + probeBlockStart(); + ret = del_memory_hash(ptr, MEMTYPE_DELETE, &caller); + if(blockresult == 0 && ret == 0 && caller == MEM_EXTERNAL) + { + setProbePoint(&probeInfo); + blockresult = 2; + probingStart(); + } + probeBlockEnd(); + } + + deletep(ptr, nothrow); + + POST_PROBEBLOCK_BEGIN_MEM(LC_MEMORY, "delete", VT_NULL, NULL, "%p", ptr); + POST_PROBEBLOCK_MIDDLE_MEM(0, MEMORY_API_FREE, ptr); + POST_PROBEBLOCK_CALLSTACK(); + POST_PROBEBLOCK_END(); +} + +void operator delete[](void *ptr, const std::nothrow_t& nothrow) throw() +{ + static void (*deletep)(void *ptr, const std::nothrow_t& nothrow); + DECLARE_VARIABLE_STANDARD; + unsigned short caller; + + GET_REAL_FUNCP_RTLD_NEXT_CPP(_ZdaPvRKSt9nothrow_t, deletep); + + bfiltering = INTERNAL_DELETE_FILTERING; + PRE_PROBEBLOCK(); + + if(ptr != NULL && gProbeBlockCount == 0) + { + probeBlockStart(); + ret = del_memory_hash(ptr, MEMTYPE_DELETE, &caller); + if(blockresult == 0 && ret == 0 && caller == MEM_EXTERNAL) + { + setProbePoint(&probeInfo); + blockresult = 2; + probingStart(); + } + probeBlockEnd(); + } + + deletep(ptr, nothrow); + + POST_PROBEBLOCK_BEGIN_MEM(LC_MEMORY, "delete", VT_NULL, NULL, "%p", ptr); + POST_PROBEBLOCK_MIDDLE_MEM(0, MEMORY_API_FREE, ptr); + POST_PROBEBLOCK_CALLSTACK(); + POST_PROBEBLOCK_END(); +} + diff --git a/probe_socket/da_socket.h b/probe_socket/da_socket.h new file mode 100644 index 0000000..eedf58a --- /dev/null +++ b/probe_socket/da_socket.h @@ -0,0 +1,65 @@ +/* + * DA probe + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Jaewon Lim + * Woojin Jung + * Juyoung Kim + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#ifndef __DA_SOCKET_H__ +#define __DA_SOCKET_H__ + +#include "daprobe.h" + +#define POST_PROBEBLOCK_MIDDLE_SOCK(SIZE, FD, APITYPE, PATH) \ + log.length += sprintf(log.data + log.length, "`,%u`,%d`,%d`,%d`,0`,%s", \ + SIZE, FD, FD_SOCKET, APITYPE, PATH) + +#define POST_PROBEBLOCK_MIDDLE_NOSOCK(SIZE, APITYPE, PATH) \ + log.length += sprintf(log.data + log.length, "`,%u`,`,%d`,%d`,0`,%s", \ + SIZE, FD_SOCKET, APITYPE, PATH) + +#define POST_PROBEBLOCK_CALLSTACK_SOCKET() \ + POST_PROBEBLOCK_CALLSTACK() + +#define AFTER_ORIGINAL_SOCK_RET(RTYPE, RVAL, SIZE, FD, APITYPE, INPUTFORMAT, ...) \ + POST_PROBEBLOCK_BEGIN(LC_RESOURCE, RTYPE, RVAL, INPUTFORMAT, __VA_ARGS__); \ + POST_PROBEBLOCK_MIDDLE_SOCK(SIZE, FD, APITYPE, ""); \ + POST_PROBEBLOCK_CALLSTACK_SOCKET(); \ + POST_PROBEBLOCK_END() + +#define AFTER_ORIGINAL_NOSOCK_RET(RTYPE, RVAL, SIZE, APITYPE, INPUTFORMAT, ...) \ + POST_PROBEBLOCK_BEGIN(LC_RESOURCE, RTYPE, RVAL, INPUTFORMAT, __VA_ARGS__); \ + POST_PROBEBLOCK_MIDDLE_NOSOCK(SIZE, APITYPE, ""); \ + POST_PROBEBLOCK_CALLSTACK_SOCKET(); \ + POST_PROBEBLOCK_END() + +#define AFTER_ORIGINAL_SOCK(SIZE, FD, APITYPE, INPUTFORMAT, ...) \ + AFTER_ORIGINAL_SOCK_RET(VT_INT, ret, SIZE, FD, APITYPE, INPUTFORMAT, __VA_ARGS__) + +#define AFTER_ORIGINAL_NOSOCK(SIZE, APITYPE, INPUTFORMAT, ...) \ + AFTER_ORIGINAL_NOSOCK_RET(VT_INT, ret, SIZE, APITYPE, INPUTFORMAT, __VA_ARGS__) + +#endif // __DA_SOCKET_H__ diff --git a/probe_socket/libdasocket.c b/probe_socket/libdasocket.c new file mode 100644 index 0000000..24b16c4 --- /dev/null +++ b/probe_socket/libdasocket.c @@ -0,0 +1,1457 @@ +/* + * DA probe + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Jaewon Lim + * Woojin Jung + * Juyoung Kim + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include "daprobe.h" +#include "probeinfo.h" +#include "dautil.h" +#include "dahelper.h" +#include "da_socket.h" + +#define GCC_VERSION (__GNUC__ * 10000 \ + + __GNUC__MINOR__ * 100 \ + + __GNUC_PATCHLEVEL__ ) + +static enum DaOptions _sopt = OPT_FILE; + +int socket(int domain, int type, int protocol) +{ + static int (*socketp)(int domain, int type, int protocol); + + BEFORE_ORIGINAL_NOFILTER(socket, LIBC); + + ret = socketp(domain, type, protocol); + + POST_PROBEBLOCK_BEGIN(LC_RESOURCE, VT_INT, ret, "%d, %d, %d", domain, type, protocol); + POST_PROBEBLOCK_MIDDLE_SOCK(0, ret, FD_API_OPEN, ""); + APPEND_LOG_CALLSTACK(); + POST_PROBEBLOCK_END(); + + return ret; +} + +int socketpair(int domain, int type, int protocol,int socket_vector[2]) +{ + static int (*socketpairp)(int domain, int type, int protocol,int socket_vector[2]); + + BEFORE_ORIGINAL_NOFILTER(socketpair, LIBC); + + ret = socketpairp(domain, type, protocol, socket_vector); + + POST_PROBEBLOCK_BEGIN(LC_RESOURCE, VT_INT, ret, + "%d, %d, %d, %p", domain, type, protocol, socket_vector); + log.length += sprintf(log.data + log.length, "`,%u`,%d/%d`,%d`,%d`,0`,%s", + 0, socket_vector[0], socket_vector[1], FD_SOCKET, FD_API_OPEN, ""); + APPEND_LOG_CALLSTACK(); + POST_PROBEBLOCK_END(); + + return ret; +} + +int shutdown(int socket, int how) +{ + static int (*shutdownp)(int socket, int how); + + BEFORE_ORIGINAL_NOFILTER(shutdown, LIBC); + + ret = shutdownp(socket, how); + + AFTER_ORIGINAL_SOCK(0, socket, FD_API_OTHER, "%d, %d", socket, how); + + return ret; +} + +int bind(int socket, const struct sockaddr *address, socklen_t address_len) +{ + static int (*bindp)(int socket, const struct sockaddr *address, socklen_t address_len); + + BEFORE_ORIGINAL(bind, LIBC); + + ret = bindp(socket, address, address_len); + + AFTER_ORIGINAL_SOCK(0, socket, FD_API_MANAGE, + "%d, %p, %d", socket, address, address_len); + + return ret; +} + +int listen(int socket, int backlog) +{ + static int (*listenp)(int socket, int backlog); + + BEFORE_ORIGINAL(listen, LIBC); + + ret = listenp(socket, backlog); + + AFTER_ORIGINAL_SOCK(0, socket, FD_API_MANAGE, "%d, %d", socket, backlog); + + return ret; +} + +int accept(int socket, struct sockaddr *address, socklen_t *address_len) +{ + static int (*acceptp)(int socket, struct sockaddr *address, socklen_t *address_len); + + BEFORE_ORIGINAL_NOFILTER(accept, LIBC); + + ret = acceptp(socket, address, address_len); + + AFTER_ORIGINAL_SOCK(0, socket, FD_API_MANAGE, + "%d, %p, %p", socket, address, address_len); + + return ret; +} + +int accept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags) +{ + static int (*accept4p)(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags); + + BEFORE_ORIGINAL_NOFILTER(accept4, LIBC); + + ret = accept4p(sockfd, addr, addrlen, flags); + + AFTER_ORIGINAL_SOCK(0, sockfd, FD_API_MANAGE, + "%d, %p, %p, %d", sockfd, addr, addrlen, flags); + + return ret; +} + +int connect(int socket, const struct sockaddr *address, socklen_t address_len) +{ + static int (*connectp)(int socket, const struct sockaddr *address, socklen_t address_len); + + BEFORE_ORIGINAL(connect, LIBC); + + ret = connectp(socket, address, address_len); + + AFTER_ORIGINAL_SOCK(address_len, socket, FD_API_MANAGE, + "%d, %p, %d", socket, address, address_len); + + return ret; +} + +int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) +{ + static int (*selectp)(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout); + + BEFORE_ORIGINAL(select, LIBC); + + ret = selectp(nfds, readfds, writefds,exceptfds, timeout); + + AFTER_ORIGINAL_SOCK(0, nfds, FD_API_MANAGE, + "%d, %p, %p, %p, %p", nfds, readfds, writefds, exceptfds, timeout); + + return ret; +} + +int pselect(int nfds, fd_set *readfds, fd_set *writefds,fd_set *exceptfds, const struct timespec *ntimeout, const sigset_t *sigmask) +{ + static int (*pselectp)(int nfds, fd_set *readfds, fd_set *writefds,fd_set *exceptfds, const struct timespec *ntimeout, const sigset_t *sigmask); + + BEFORE_ORIGINAL(pselect, LIBC); + + ret = pselectp(nfds, readfds, writefds,exceptfds, ntimeout, sigmask); + + AFTER_ORIGINAL_SOCK(0, nfds, FD_API_MANAGE, "%d, %p, %p, %p, %p, %p", + nfds, readfds, writefds, exceptfds, ntimeout, sigmask); + + return ret; +} + +ssize_t send(int socket, const void *message, size_t length, int flags) +{ + static ssize_t (*sendp)(int socket, const void *message, size_t length, int flags); + ssize_t sret; + + BEFORE_ORIGINAL(send, LIBC); + + sret = sendp(socket, message, length, flags); + + AFTER_ORIGINAL_SOCK_RET(VT_SSIZE_T, sret, sret, socket, FD_API_SEND, + "%d, %p, %u, %d", socket, message, length, flags); + + return sret; +} + +ssize_t sendmsg(int socket, const struct msghdr *message, int flags) +{ + static ssize_t (*sendmsgp)(int socket, const struct msghdr *message, int flags); + ssize_t sret; + + BEFORE_ORIGINAL(sendmsg, LIBC); + + sret = sendmsgp(socket, message, flags); + + AFTER_ORIGINAL_SOCK_RET(VT_SSIZE_T, sret, sret, socket, FD_API_SEND, + "%d, %p, %d", socket, message, flags); + + return sret; +} + +ssize_t sendto(int socket, const void *message, size_t length, int flags,const struct sockaddr *dest_addr, socklen_t dest_len) +{ + static ssize_t (*sendtop)(int socket, const void *message, size_t length, int flags,const struct sockaddr *dest_addr, socklen_t dest_len); + ssize_t sret; + + BEFORE_ORIGINAL(sendto, LIBC); + + sret = sendtop(socket, message, length, flags, dest_addr, dest_len); + + AFTER_ORIGINAL_SOCK_RET(VT_SSIZE_T, sret, sret, socket, FD_API_SEND, + "%d, %p, %u, %d, %p, %d", socket, message, length, flags, dest_addr, dest_len); + + return sret; +} + +ssize_t recv(int socket, void *buffer, size_t length, int flags) +{ + static ssize_t (*recvp)(int socket, void *buffer, size_t length, int flags); + ssize_t sret; + + BEFORE_ORIGINAL(recv, LIBC); + + sret = recvp(socket, buffer, length, flags); + + AFTER_ORIGINAL_SOCK_RET(VT_SSIZE_T, sret, sret, socket, FD_API_RECEIVE, + "%d, %p, %u, %d", socket, buffer, length, flags); + + return sret; +} + +ssize_t recvfrom(int socket, void *buffer, size_t length, int flags, struct sockaddr *address, socklen_t *address_len) +{ + static ssize_t (*recvfromp)(int socket, void *buffer, size_t length, int flags, struct sockaddr *address, socklen_t *address_len); + ssize_t sret; + + BEFORE_ORIGINAL(recvfrom, LIBC); + + sret = recvfromp(socket, buffer, length, flags, address, address_len); + + AFTER_ORIGINAL_SOCK_RET(VT_SSIZE_T, sret, sret, socket, FD_API_RECEIVE, + "%d, %p, %u, %d, %p, %p", socket, buffer, length, flags, address, address_len); + + return sret; +} + +ssize_t recvmsg(int socket, struct msghdr *message, int flags) +{ + static ssize_t (*recvmsgp)(int socket, struct msghdr *message, int flags); + ssize_t sret; + + BEFORE_ORIGINAL(recvmsg, LIBC); + + sret = recvmsgp(socket, message, flags); + + AFTER_ORIGINAL_SOCK_RET(VT_SSIZE_T, sret, sret, socket, FD_API_RECEIVE, + "%d, %p, %d", socket, message, flags); + + return sret; +} + +uint32_t htonl(uint32_t hostlong) +{ + static uint32_t (*htonlp)(uint32_t hostlong); + uint32_t uret; + + BEFORE_ORIGINAL(htonl, LIBC); + + uret = htonlp(hostlong); + + AFTER_ORIGINAL_NOSOCK_RET(VT_UINT32_T, uret, 0, FD_API_OTHER, "%u", hostlong); + + return uret; +} + +uint16_t htons(uint16_t hostshort) +{ + static uint16_t (*htonsp)(uint16_t hostshort); + uint16_t uret; + + BEFORE_ORIGINAL(htons, LIBC); + + uret = htonsp(hostshort); + + AFTER_ORIGINAL_NOSOCK_RET(VT_UINT16_T, uret, 0, FD_API_OTHER, "%u", hostshort); + + return uret; +} + +uint32_t ntohl(uint32_t netlong) +{ + static uint32_t (*ntohlp)(uint32_t netlong); + uint32_t uret; + + BEFORE_ORIGINAL(ntohl, LIBC); + + uret = ntohlp(netlong); + + AFTER_ORIGINAL_NOSOCK_RET(VT_UINT32_T, uret, 0, FD_API_OTHER, "%u", netlong); + + return uret; +} + +uint16_t ntohs(uint16_t netshort) +{ + static uint16_t (*ntohsp)(uint16_t netshort); + uint16_t uret; + + BEFORE_ORIGINAL(ntohs, LIBC); + + uret = ntohsp(netshort); + + AFTER_ORIGINAL_NOSOCK_RET(VT_UINT16_T, uret, 0, FD_API_OTHER, "%u", netshort); + + return uret; +} + +#if 0 +uint16_t htobe16(uint16_t host_16bits) +{ + static uint16_t (*htobe16p)(uint16_t host_16bits); + uint16_t uret; + + BEFORE_ORIGINAL(htobe16, LIBC); + + uret = htobe16p(host_16bits); + + AFTER_ORIGINAL_NOSOCK_RET(VT_UINT16_T, uret, 0, FD_API_OTHER, "%u", host_16bits); + + return uret; +} + +uint16_t htole16(uint16_t host_16bits) +{ + static uint16_t (*htole16p)(uint16_t host_16bits); + uint16_t uret; + + BEFORE_ORIGINAL(htole16, LIBC); + + uret = htole16p(host_16bits); + + AFTER_ORIGINAL_NOSOCK_RET(VT_UINT16_T, uret, 0, FD_API_OTHER, "%u", host_16bits); + + return uret; +} + +uint16_t be16toh(uint16_t big_endian_16bits) +{ + static uint16_t (*be16tohp)(uint16_t big_endian_16bits); + uint16_t uret; + + BEFORE_ORIGINAL(be16toh, LIBC); + + uret = be16tohp(big_endian_16bits); + + AFTER_ORIGINAL_NOSOCK_RET(VT_UINT16_T, uret, 0, FD_API_OTHER, + "%u", big_endian_16bits); + + return uret; +} + +uint16_t le16toh(uint16_t little_endian_16bits) +{ + static uint16_t (*le16tohp)(uint16_t little_endian_16bits); + uint16_t uret; + + BEFORE_ORIGINAL(le16toh, LIBC); + + uret = le16tohp(little_endian_16bits); + + AFTER_ORIGINAL_NOSOCK_RET(VT_UINT16_T, uret, 0, FD_API_OTHER, + "%u", little_endian_16bits); + + return uret; +} + +uint32_t htobe32(uint32_t host_32bits) +{ + static uint32_t (*htobe32p)(uint32_t host_32bits); + uint32_t uret; + + BEFORE_ORIGINAL(htobe32, LIBC); + + uret = htobe32p(host_32bits); + + AFTER_ORIGINAL_NOSOCK_RET(VT_UINT32_T, uret, 0, FD_API_OTHER, + "%u", host_32bits); + + return uret; +} + +uint32_t htole32(uint32_t host_32bits) +{ + static uint32_t (*htole32p)(uint32_t host_32bits); + uint32_t uret; + + BEFORE_ORIGINAL(htole32, LIBC); + + uret = htole32p(host_32bits); + + AFTER_ORIGINAL_NOSOCK_RET(VT_UINT32_T, uret, 0, FD_API_OTHER, + "%u", host_32bits); + + return uret; +} + +uint32_t be32toh(uint32_t big_endian_32bits) +{ + static uint32_t (*be32tohp)(uint32_t big_endian_32bits); + uint32_t uret; + + BEFORE_ORIGINAL(be32toh, LIBC); + + uret = be32tohp(big_endian_32bits); + + AFTER_ORIGINAL_NOSOCK_RET(VT_UINT32_T, uret, 0, FD_API_OTHER, + "%u", big_endian_32bits); + + return uret; +} + +uint32_t le32toh(uint32_t little_endian_32bits) +{ + static uint32_t (*le32tohp)(uint32_t little_endian_32bits); + uint32_t uret; + + BEFORE_ORIGINAL(le32toh, LIBC); + + uret = le32tohp(little_endian_32bits); + + AFTER_ORIGINAL_NOSOCK_RET(VT_UINT32_T, uret, 0, FD_API_OTHER, + "%u", little_endian_32bits); + + return uret; +} + +uint64_t htobe64(uint64_t host_64bits) +{ + static uint64_t (*htobe64p)(uint64_t host_64bits); + uint64_t uret; + + BEFORE_ORIGINAL(htobe64, LIBC); + + uret = htobe64p(host_64bits); + + AFTER_ORIGINAL_NOSOCK_RET(VT_UINT64_T, uret, 0, FD_API_OTHER, + "%u", host_64bits); + + return uret; +} + +uint64_t htole64(uint64_t host_64bits) +{ + static uint64_t (*htole64p)(uint64_t host_64bits); + uint64_t uret; + + BEFORE_ORIGINAL(htole64, LIBC); + + uret = htole64p(host_64bits); + + AFTER_ORIGINAL_NOSOCK_RET(VT_UINT64_T, uret, 0, FD_API_OTHER, + "%u", host_64bits); + + return uret; +} + +uint64_t be64toh(uint64_t big_endian_64bits) +{ + static uint64_t (*be64tohp)(uint64_t big_endian_64bits); + uint64_t uret; + + BEFORE_ORIGINAL(be64toh, LIBC); + + uret = be64tohp(big_endian_64bits); + + AFTER_ORIGINAL_NOSOCK_RET(VT_UINT64_T, uret, 0, FD_API_OTHER, + "%u", big_endian_64bits); + + return uret; +} + +uint64_t le64toh(uint64_t little_endian_64bits) +{ + static uint64_t (*le64tohp)(uint64_t little_endian_64bits); + uint64_t uret; + + BEFORE_ORIGINAL(le64toh, LIBC); + + uret = le64tohp(little_endian_64bits); + + AFTER_ORIGINAL_NOSOCK_RET(VT_UINT64_T, uret, 0, FD_API_OTHER, + "%u", little_endian_64bits); + + return uret; +} +#endif + +#if 1 +int inet_aton(const char *cp, struct in_addr *inp) +{ + static int (*inet_atonp)(const char *cp, struct in_addr *inp); + + BEFORE_ORIGINAL(inet_aton, LIBC); + + ret = inet_atonp(cp,inp); + + AFTER_ORIGINAL_NOSOCK(0, FD_API_OTHER, "%p, %p", cp, inp); + + return ret; +} + +in_addr_t inet_addr(const char *cp) +{ + static in_addr_t (*inet_addrp)(const char *cp); + in_addr_t iret; + + BEFORE_ORIGINAL(inet_addr, LIBC); + + iret = inet_addrp(cp); + + AFTER_ORIGINAL_NOSOCK_RET(VT_PTR, iret, 0, FD_API_OTHER, "%p", cp); + + return iret; +} + +in_addr_t inet_network(const char *cp) +{ + static in_addr_t (*inet_networkp)(const char *cp); + in_addr_t iret; + + BEFORE_ORIGINAL(inet_network, LIBC); + + iret = inet_networkp(cp); + + AFTER_ORIGINAL_NOSOCK_RET(VT_PTR, iret, 0, FD_API_OTHER, "%p", cp); + + return iret; +} + +char *inet_ntoa(struct in_addr in) +{ + static char * (*inet_ntoap)(struct in_addr in); + char* sret; + + BEFORE_ORIGINAL(inet_ntoa, LIBC); + + sret = inet_ntoap(in); + + AFTER_ORIGINAL_NOSOCK_RET(VT_PTR, sret, 0, FD_API_OTHER, "%u", in.s_addr); + + return sret; +} + +#if 0 +struct in_addr inet_makeaddr(int net, int host) +{ + static struct in_addr (*inet_makeaddrp)(int net, int host); + struct in_addr iret; + + BEFORE_ORIGINAL(inet_makeaddr, LIBC); + + iret = inet_makeaddrp(net,host); + + AFTER_ORIGINAL_NOSOCK_RET(VT_UINT32_T, iret.s_addr, 0, FD_API_OTHER, + "%d, %d", net, host); + + return iret; +} +#endif + +in_addr_t inet_lnaof(struct in_addr in) +{ + static in_addr_t (*inet_lnaofp)(struct in_addr in); + in_addr_t iret; + + BEFORE_ORIGINAL(inet_lnaof, LIBC); + + iret = inet_lnaofp(in); + + AFTER_ORIGINAL_NOSOCK_RET(VT_UINT32_T, iret, 0, FD_API_OTHER, "%u", in.s_addr); + + return iret; +} + +in_addr_t inet_netof(struct in_addr in) +{ + static in_addr_t (*inet_netofp)(struct in_addr in); + in_addr_t iret; + + BEFORE_ORIGINAL(inet_netof, LIBC); + + iret = inet_netofp(in); + + AFTER_ORIGINAL_NOSOCK_RET(VT_UINT32_T, iret, 0, FD_API_OTHER, "%u", in.s_addr); + + return iret; +} + +const char *inet_ntop(int af, const void *src, char *dst, socklen_t size) +{ + static const char* (*inet_ntopp)(int af, const void *src, char *dst, socklen_t size); + const char* cret; + + BEFORE_ORIGINAL(inet_ntop, LIBC); + + cret = inet_ntopp(af, src, dst, size); + + AFTER_ORIGINAL_NOSOCK_RET(VT_PTR, cret, size, FD_API_OTHER, + "%d, %p, %p, %d", af, src, dst, size); + + return cret; +} + +int inet_pton(int af, const char *src, void *dst) +{ + static int (*inet_ptonp)(int af, const char *src, void *dst); + + BEFORE_ORIGINAL(inet_pton, LIBC); + + ret = inet_ptonp(af, src, dst); + + AFTER_ORIGINAL_NOSOCK(0, FD_API_OTHER, "%d, %p, %p", af, src, dst); + + return ret; +} + +int getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res) +{ + static int (*getaddrinfop)(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res); + + BEFORE_ORIGINAL_NOFILTER(getaddrinfo, LIBC); + + ret = getaddrinfop(node, service, hints, res); + + AFTER_ORIGINAL_NOSOCK(0, FD_API_OTHER, "%p, %p, %p, %p", node, service, hints, res); + + return ret; +} + +void freeaddrinfo(struct addrinfo *res) +{ + static void (*freeaddrinfop)(struct addrinfo *res); + + BEFORE_ORIGINAL_NOFILTER(freeaddrinfo, LIBC); + + freeaddrinfop(res); + + AFTER_ORIGINAL_NOSOCK_RET(VT_NULL, NULL, 0, FD_API_OTHER, "%p", res); +} + +const char *gai_strerror(int errcode) +{ + static const char * (*gai_strerrorp)(int errcode); + const char * cret; + + BEFORE_ORIGINAL(gai_strerror, LIBC); + + cret = gai_strerrorp(errcode); + + AFTER_ORIGINAL_NOSOCK_RET(VT_PTR, cret, 0, FD_API_OTHER, "%d", errcode); + + return cret; +} + +int gai_suspend(const struct gaicb* const list[], int nitems, const struct timespec *timeout) +{ + static int (*gai_suspendp)(const struct gaicb* const list[], int nitems, const struct timespec *timeout); + + BEFORE_ORIGINAL(gai_suspend, LIBC); + + ret = gai_suspendp(list,nitems,timeout); + + AFTER_ORIGINAL_NOSOCK(0, FD_API_OTHER, "%p, %d, %p", list, nitems, timeout); + + return ret; +} + +int gai_error(struct gaicb *req) +{ + static int (*gai_errorp)(struct gaicb *req); + + BEFORE_ORIGINAL(gai_error, LIBC); + + ret = gai_errorp(req); + + AFTER_ORIGINAL_NOSOCK(0, FD_API_OTHER, "%p", req); + + return ret; +} + +int gai_cancel(struct gaicb *req) +{ + static int (*gai_cancelp)(struct gaicb *req); + + BEFORE_ORIGINAL(gai_cancel, LIBC); + + ret = gai_cancelp(req); + + AFTER_ORIGINAL_NOSOCK(0, FD_API_OTHER, "%p", req); + + return ret; +} + +int getaddrinfo_a(int mode, struct gaicb *list[], int nitems, struct sigevent *sevp) +{ + static int (*getaddrinfo_ap)(int mode, struct gaicb *list[], int nitems, struct sigevent *sevp); + + BEFORE_ORIGINAL(getaddrinfo_a, LIBC); + + ret = getaddrinfo_ap(mode, list,nitems, sevp); + + AFTER_ORIGINAL_NOSOCK(0, FD_API_OTHER, "%d, %p, %d, %p", mode, list, nitems, sevp); + + return ret; +} +#endif + +int getsockopt(int socket, int level, int option_name, void *option_value, socklen_t *option_len) +{ + static int (*getsockoptp)(int socket, int level, int option_name, void *option_value, socklen_t *option_len); + + BEFORE_ORIGINAL(getsockopt, LIBC); + + ret = getsockoptp(socket, level, option_name, option_value, option_len); + + AFTER_ORIGINAL_SOCK(0, socket, FD_API_OPTION, "%d, %d, %d, %p, %p", + socket, level, option_name, option_value, option_len); + + return ret; +} + +int setsockopt(int socket, int level, int option_name, const void *option_value, socklen_t option_len) +{ + static int (*setsockoptp)(int socket, int level, int option_name, const void *option_value, socklen_t option_len); + + BEFORE_ORIGINAL(setsockopt, LIBC); + + ret = setsockoptp(socket, level, option_name, option_value, option_len); + + AFTER_ORIGINAL_SOCK(option_len, socket, FD_API_OPTION, "%d, %d, %d, %p, %d", + socket, level, option_name, option_value, option_len); + + return ret; +} + +#if 1 +int getsockname(int sockfd, struct sockaddr *addr, socklen_t *addrlen ) +{ + static int (*getsocknamep)(int sockfd, struct sockaddr *addr, socklen_t *addrlen ); + + BEFORE_ORIGINAL(getsockname, LIBC); + + ret = getsocknamep(sockfd, addr, addrlen); + + AFTER_ORIGINAL_SOCK(0, sockfd, FD_API_OTHER, "%d, %p, %p", sockfd, addr, addrlen); + + return ret; +} + +int getdomainname(char *name, size_t len) +{ + static int (*getdomainnamep)(char *name, size_t len); + + BEFORE_ORIGINAL(getdomainname, LIBC); + + ret = getdomainnamep(name, len); + + AFTER_ORIGINAL_NOSOCK(len, FD_API_OTHER, "%p, %u", name, len); + + return ret; +} + +int setdomainname(const char *name, size_t len) +{ + static int (*setdomainnamep)(const char *name, size_t len); + + BEFORE_ORIGINAL(setdomainname, LIBC); + + ret = setdomainnamep(name, len); + + AFTER_ORIGINAL_NOSOCK(len, FD_API_OTHER, "%p, %u", name, len); + + return ret; +} + +int gethostname(char *name, size_t len) +{ + static int (*gethostnamep)(char *name, size_t len); + + BEFORE_ORIGINAL(gethostname, LIBC); + + ret = gethostnamep(name, len); + + AFTER_ORIGINAL_NOSOCK(len, FD_API_OTHER, "%p, %u", name, len); + + return ret; +} + +int sethostname(const char *name, size_t len) +{ + static int (*sethostnamep)(const char *name, size_t len); + + BEFORE_ORIGINAL(sethostname, LIBC); + + ret = sethostnamep(name, len); + + AFTER_ORIGINAL_NOSOCK(len, FD_API_OTHER, "%p, %u", name, len); + + return ret; +} + +int getpeername(int s, struct sockaddr *addr, socklen_t *len) +{ + static int (*getpeernamep)(int s, struct sockaddr *addr, socklen_t *len); + + BEFORE_ORIGINAL(getpeername, LIBC); + + ret = getpeernamep(s, addr, len); + + AFTER_ORIGINAL_SOCK(0, s, FD_API_OTHER, "%d, %p, %p", s, addr, len); + + return ret; +} + +#if GCC_VERSION < 40800 +int getnameinfo(const struct sockaddr *sa, socklen_t salen, char *host, socklen_t hostlen, char *serv, socklen_t servlen, unsigned int flags) +{ + static int (*getnameinfop)(const struct sockaddr *sa, socklen_t salen, char *host, socklen_t hostlen, char *serv, socklen_t servlen, unsigned int flags); +#else +int getnameinfo(const struct sockaddr *sa, socklen_t salen, char *host, size_t hostlen, char *serv, size_t servlen, int flags) +{ + static int (*getnameinfop)(const struct sockaddr *sa, socklen_t salen, char *host, size_t hostlen, char *serv, size_t servlen, int flags); +#endif + BEFORE_ORIGINAL(getnameinfo, LIBC); + + ret = getnameinfop(sa, salen,host, hostlen, serv, servlen, flags); + + AFTER_ORIGINAL_NOSOCK(0, FD_API_OTHER, "%p, %d, %p, %u, %p, %u, %d", + sa, salen, host, hostlen, serv, servlen, flags); + + return ret; +} + +struct hostent *gethostbyname(const char *name) +{ + static struct hostent * (*gethostbynamep)(const char *name); + struct hostent* pret; + + BEFORE_ORIGINAL(gethostbyname, LIBC); + + pret = gethostbynamep(name); + + AFTER_ORIGINAL_NOSOCK_RET(VT_PTR, pret, 0, FD_API_OTHER, "%p", name); + + return pret; +} + +struct hostent *gethostbyaddr(const void *addr, socklen_t len, int type) +{ + static struct hostent * (*gethostbyaddrp)(const void *addr, socklen_t len, int type); + struct hostent* pret; + + BEFORE_ORIGINAL(gethostbyaddr, LIBC); + + pret = gethostbyaddrp(addr, len, type); + + AFTER_ORIGINAL_NOSOCK_RET(VT_PTR, pret, 0, FD_API_OTHER, + "%p, %d, %d", addr, len, type); + + return pret; +} + +void sethostent(int stayopen) +{ + static void (*sethostentp)(int stayopen); + + BEFORE_ORIGINAL(sethostent, LIBC); + + sethostentp(stayopen); + + AFTER_ORIGINAL_NOSOCK_RET(VT_NULL, NULL, 0, FD_API_OTHER, "%d", stayopen); +} + +void endhostent(void) +{ + static void (*endhostentp)(void); + + BEFORE_ORIGINAL(endhostent, LIBC); + + endhostentp(); + + AFTER_ORIGINAL_NOSOCK_RET(VT_NULL, NULL, 0, FD_API_OTHER, "%s", ""); +} + +void herror(const char *s) +{ + static void (*herrorp)(const char *s); + + BEFORE_ORIGINAL(herror, LIBC); + + herrorp(s); + + AFTER_ORIGINAL_NOSOCK_RET(VT_NULL, NULL, 0, FD_API_OTHER, "%p", s); +} + +const char *hstrerror(int err) +{ + static const char* (*hstrerrorp)(int err); + const char* cret; + + BEFORE_ORIGINAL(hstrerror, LIBC); + + cret = hstrerrorp(err); + + AFTER_ORIGINAL_NOSOCK_RET(VT_PTR, cret, 0, FD_API_OTHER, "%d", err); + + return cret; +} + +struct hostent *gethostent(void) +{ + static struct hostent* (*gethostentp)(void); + struct hostent* pret; + + BEFORE_ORIGINAL(gethostent, LIBC); + + pret = gethostentp(); + + AFTER_ORIGINAL_NOSOCK_RET(VT_PTR, pret, 0, FD_API_OTHER, "%s", ""); + + return pret; +} + +struct hostent *gethostbyname2(const char *name, int af) +{ + static struct hostent * (*gethostbyname2p)(const char *name, int af); + struct hostent* pret; + + BEFORE_ORIGINAL(gethostbyname2, LIBC); + + pret = gethostbyname2p(name, af); + + AFTER_ORIGINAL_NOSOCK_RET(VT_PTR, pret, 0, FD_API_OTHER, "%p, %d", name, af); + + return pret; +} + +int gethostent_r(struct hostent *rret, char *buf, size_t buflen, struct hostent **result, int *h_errnop) +{ + static int (*gethostent_rp)(struct hostent *rret, char *buf, size_t buflen, struct hostent **result, int *h_errnop); + + BEFORE_ORIGINAL(gethostent_r, LIBC); + + ret = gethostent_rp(rret, buf, buflen, result, h_errnop); + + AFTER_ORIGINAL_NOSOCK(0, FD_API_OTHER, "%p, %p, %u, %p, %p", + rret, buf, buflen, result, h_errnop); + + return ret; +} + +int gethostbyaddr_r(const void *addr, socklen_t len, int type, struct hostent *rret, char *buf, size_t buflen, struct hostent **result, int *h_errnop) +{ + static int (*gethostbyaddr_rp)(const void *addr, socklen_t len, int type, struct hostent *rret, char *buf, size_t buflen, struct hostent **result, int *h_errnop); + + BEFORE_ORIGINAL(gethostbyaddr_r, LIBC); + + ret = gethostbyaddr_rp(addr, len, type, rret, buf, buflen, result, h_errnop); + + AFTER_ORIGINAL_NOSOCK(0, FD_API_OTHER, "%p, %d, %d, %p, %p, %u, %p, %p", + addr, len, type, rret, buf, buflen, result, h_errnop); + + return ret; +} + +int gethostbyname_r(const char *name, struct hostent *rret, char *buf, size_t buflen, struct hostent **result, int *h_errnop) +{ + static int (*gethostbyname_rp)(const char *name, struct hostent *rret, char *buf, size_t buflen, struct hostent **result, int *h_errnop); + + BEFORE_ORIGINAL(gethostbyname_r, LIBC); + + ret = gethostbyname_rp(name, rret, buf, buflen, result, h_errnop); + + AFTER_ORIGINAL_NOSOCK(0, FD_API_OTHER, "%p, %p, %p, %u, %p, %p", + name, rret, buf, buflen, result, h_errnop); + + return ret; +} + +int gethostbyname2_r(const char *name, int af, struct hostent *rret, char *buf, size_t buflen, struct hostent **result, int *h_errnop) +{ + static int (*gethostbyname2_rp)(const char *name, int af, struct hostent *rret, char *buf, size_t buflen, struct hostent **result, int *h_errnop); + + BEFORE_ORIGINAL(gethostbyname2_r, LIBC); + + ret = gethostbyname2_rp(name, af, rret, buf, buflen, result, h_errnop); + + AFTER_ORIGINAL_NOSOCK(0, FD_API_OTHER, "%p, %d, %p, %p, %u, %p, %p", + name, af, rret, buf, buflen, result, h_errnop); + + return ret; +} + +struct servent *getservbyname(const char *name, const char *proto) +{ + static struct servent * (*getservbynamep)(const char *name, const char *proto); + struct servent* pret; + + BEFORE_ORIGINAL(getservbyname, LIBC); + + pret = getservbynamep(name, proto); + + AFTER_ORIGINAL_NOSOCK_RET(VT_PTR, pret, 0, FD_API_OTHER, "%p, %p", name, proto); + + return pret; +} + +void setservent(int stayopen) +{ + static void (*setserventp)(int stayopen); + + BEFORE_ORIGINAL(setservent, LIBC); + + setserventp(stayopen); + + AFTER_ORIGINAL_NOSOCK_RET(VT_NULL, NULL, 0, FD_API_OTHER, "%d", stayopen); +} + +void endservent(void) +{ + static void (*endserventp)(void); + + BEFORE_ORIGINAL(endservent, LIBC); + + endserventp(); + + AFTER_ORIGINAL_NOSOCK_RET(VT_NULL, NULL, 0, FD_API_OTHER, "%s", ""); +} + +struct servent *getservent(void) +{ + static struct servent * (*getserventp)(void); + struct servent* pret; + + BEFORE_ORIGINAL(getservent, LIBC); + + pret = getserventp(); + + AFTER_ORIGINAL_NOSOCK_RET(VT_PTR, pret, 0, FD_API_OTHER, "%s", ""); + + return pret; +} + +struct servent *getservbyport(int port, const char *proto) +{ + static struct servent * (*getservbyportp)(int port, const char *proto); + struct servent* pret; + + BEFORE_ORIGINAL(getservbyport, LIBC); + + pret = getservbyportp(port, proto); + + AFTER_ORIGINAL_NOSOCK_RET(VT_PTR, pret, 0, FD_API_OTHER, "%d, %p", port, proto); + + return pret; +} + +int getservent_r(struct servent *result_buf, char *buf, size_t buflen, struct servent **result) +{ + static int (*getservent_rp)(struct servent *result_buf, char *buf, size_t buflen, struct servent **result); + + BEFORE_ORIGINAL(getservent_r, LIBC); + + ret = getservent_rp(result_buf, buf, buflen, result); + + AFTER_ORIGINAL_NOSOCK(0, FD_API_OTHER, "%p, %p, %u, %p", + result_buf, buf, buflen, result); + + return ret; +} + +int getservbyname_r(const char *name, const char *proto, struct servent *result_buf, char *buf, size_t buflen, struct servent **result) +{ + static int (*getservbyname_rp)(const char *name, const char *proto, struct servent *result_buf, char *buf, size_t buflen, struct servent **result); + + BEFORE_ORIGINAL(getservbyname_r, LIBC); + + ret = getservbyname_rp(name, proto, result_buf, buf, buflen, result); + + AFTER_ORIGINAL_NOSOCK(0, FD_API_OTHER, "%p, %p, %p, %p, %u, %p", + name, proto, result_buf, buf, buflen, result); + + return ret; +} + +int getservbyport_r(int port, const char *proto, struct servent *result_buf, char *buf, size_t buflen, struct servent **result) +{ + static int (*getservbyport_rp)(int port, const char *proto, struct servent *result_buf, char *buf, size_t buflen, struct servent **result); + + BEFORE_ORIGINAL(getservbyport_r, LIBC); + + ret = getservbyport_rp(port, proto, result_buf, buf, buflen, result); + + AFTER_ORIGINAL_NOSOCK(0, FD_API_OTHER, "%d, %p, %p, %p, %u, %p", + port, proto, result_buf, buf, buflen, result); + + return ret; +} + +struct netent* getnetent(void) +{ + static struct netent * (*getnetentp)(void); + struct netent* pret; + + BEFORE_ORIGINAL(getnetent, LIBC); + + pret = getnetentp(); + + AFTER_ORIGINAL_NOSOCK_RET(VT_PTR, pret, 0, FD_API_OTHER, "%s", ""); + + return pret; +} + +struct netent *getnetbyname(const char *name) +{ + static struct netent * (*getnetbynamep)(const char *name); + struct netent* pret; + + BEFORE_ORIGINAL(getnetbyname, LIBC); + + pret = getnetbynamep(name); + + AFTER_ORIGINAL_NOSOCK_RET(VT_PTR, pret, 0, FD_API_OTHER, "%p", name); + + return pret; +} + +struct netent *getnetbyaddr(uint32_t net, int type) +{ + static struct netent * (*getnetbyaddrp)(uint32_t net, int type); + struct netent * pret; + + BEFORE_ORIGINAL(getnetbyaddr, LIBC); + + pret = getnetbyaddrp(net, type); + + AFTER_ORIGINAL_NOSOCK_RET(VT_PTR, pret, 0, FD_API_OTHER, "%u, %d", net, type); + + return pret; +} + +void setnetent(int stayopen) +{ + static void (*setnetentp)(int stayopen); + + BEFORE_ORIGINAL(setnetent, LIBC); + + setnetentp(stayopen); + + AFTER_ORIGINAL_NOSOCK_RET(VT_NULL, NULL, 0, FD_API_OTHER, "%d", stayopen); +} + +void endnetent(void) +{ + static void (*endnetentp)(void); + + BEFORE_ORIGINAL(endnetent, LIBC); + + endnetentp(); + + AFTER_ORIGINAL_NOSOCK_RET(VT_NULL, NULL, 0, FD_API_OTHER, "%s", ""); +} + +int getnetent_r(struct netent *result_buf, char *buf, size_t buflen, struct netent **result, int *h_errnop) +{ + static int (*getnetent_rp)(struct netent *result_buf, char *buf, size_t buflen, struct netent **result, int *h_errnop); + + BEFORE_ORIGINAL(getnetent_r, LIBC); + + ret = getnetent_rp(result_buf, buf, buflen, result, h_errnop); + + AFTER_ORIGINAL_NOSOCK(0, FD_API_OTHER, "%p, %p, %u, %p, %p", + result_buf, buf, buflen, result, h_errnop); + + return ret; +} + +int getnetbyname_r(const char *name, struct netent *result_buf, char *buf, size_t buflen, struct netent **result, int *h_errnop) +{ + static int (*getnetbyname_rp)(const char *name, struct netent *result_buf, char *buf, size_t buflen, struct netent **result, int *h_errnop); + + BEFORE_ORIGINAL(getnetbyname_r, LIBC); + + ret = getnetbyname_rp(name,result_buf, buf, buflen, result, h_errnop); + + AFTER_ORIGINAL_NOSOCK(0, FD_API_OTHER, "%p, %p, %p, %u, %p, %p", + name, result_buf, buf, buflen, result, h_errnop); + + return ret; +} + +int getnetbyaddr_r(uint32_t net, int type, struct netent *result_buf, char *buf, size_t buflen, struct netent **result, int *h_errnop) +{ + static int (*getnetbyaddr_rp)(uint32_t net, int type, struct netent *result_buf, char *buf, size_t buflen, struct netent **result, int *h_errnop); + + BEFORE_ORIGINAL(getnetbyaddr_r, LIBC); + + ret = getnetbyaddr_rp(net, type, result_buf, buf, buflen, result, h_errnop); + + AFTER_ORIGINAL_NOSOCK(0, FD_API_OTHER, "%u, %d, %p, %p, %u, %p, %p", + net, type, result_buf, buf, buflen, result, h_errnop); + + return ret; +} + +struct protoent *getprotoent(void) +{ + static struct protoent * (*getprotoentp)(void); + struct protoent * pret; + + BEFORE_ORIGINAL(getprotoent, LIBC); + + pret = getprotoentp(); + + AFTER_ORIGINAL_NOSOCK_RET(VT_PTR, pret, 0, FD_API_OTHER, "%s", ""); + + return pret; +} + +struct protoent *getprotobyname(const char *name) +{ + static struct protoent * (*getprotobynamep)(const char *name); + struct protoent * pret; + + BEFORE_ORIGINAL(getprotobyname, LIBC); + + pret = getprotobynamep(name); + + AFTER_ORIGINAL_NOSOCK_RET(VT_PTR, pret, 0, FD_API_OTHER, "%p", name); + + return pret; +} + +struct protoent *getprotobynumber(int proto) +{ + static struct protoent * (*getprotobynumberp)(int proto); + struct protoent * pret; + + BEFORE_ORIGINAL(getprotobynumber, LIBC); + + pret = getprotobynumberp(proto); + + AFTER_ORIGINAL_NOSOCK_RET(VT_PTR, pret, 0, FD_API_OTHER, "%d", proto); + + return pret; +} + +void setprotoent(int stayopen) +{ + static void (*setprotoentp)(int stayopen); + + BEFORE_ORIGINAL(setprotoent, LIBC); + + setprotoentp(stayopen); + + AFTER_ORIGINAL_NOSOCK_RET(VT_NULL, NULL, 0, FD_API_OTHER, "%d", stayopen); +} + +void endprotoent(void) +{ + static void (*endprotoentp)(void); + + BEFORE_ORIGINAL(endprotoent, LIBC); + + endprotoentp(); + + AFTER_ORIGINAL_NOSOCK_RET(VT_NULL, NULL, 0, FD_API_OTHER, "%s", ""); +} + +int getprotoent_r(struct protoent *result_buf, char *buf, size_t buflen, struct protoent **result) +{ + static int (*getprotoent_rp)(struct protoent *result_buf, char *buf, size_t buflen, struct protoent **result); + + BEFORE_ORIGINAL(getprotoent_r, LIBC); + + ret = getprotoent_rp(result_buf, buf, buflen, result); + + AFTER_ORIGINAL_NOSOCK(0, FD_API_OTHER, "%p, %p, %u, %p", + result_buf, buf, buflen, result); + + return ret; +} + +int getprotobyname_r(const char *name, struct protoent *result_buf, char *buf, size_t buflen, struct protoent **result) +{ + static int (*getprotobyname_rp)(const char *name, struct protoent *result_buf, char *buf, size_t buflen, struct protoent **result); + + BEFORE_ORIGINAL(getprotobyname_r, LIBC); + + ret = getprotobyname_rp(name, result_buf, buf, buflen, result); + + AFTER_ORIGINAL_NOSOCK(0, FD_API_OTHER, "%p, %p, %p, %u, %p", + name, result_buf, buf, buflen, result); + + return ret; +} + +int getprotobynumber_r(int proto, struct protoent *result_buf, char *buf, size_t buflen, struct protoent **result) +{ + static int (*getprotobynumber_rp)(int proto, struct protoent *result_buf, char *buf, size_t buflen, struct protoent **result); + + BEFORE_ORIGINAL(getprotobynumber_r, LIBC); + + ret = getprotobynumber_rp(proto, result_buf, buf, buflen, result); + + AFTER_ORIGINAL_NOSOCK(0, FD_API_OTHER, "%d, %p, %p, %u, %p", + proto, result_buf, buf, buflen, result); + + return ret; +} + +unsigned int if_nametoindex (__const char *__ifname) +{ + static unsigned int (*if_nametoindexp)(__const char *__ifname); + unsigned int uret; + + BEFORE_ORIGINAL(if_nametoindex, LIBC); + + uret = if_nametoindexp(__ifname); + + AFTER_ORIGINAL_NOSOCK_RET(VT_UINT, uret, 0, FD_API_OTHER, "%p", __ifname); + + return uret; +} + +char *if_indextoname (unsigned int __ifindex, char *__ifname) +{ + static char * (*if_indextonamep)(unsigned int __ifindex, char *__ifname); + char * cret; + + BEFORE_ORIGINAL(if_indextoname, LIBC); + + cret = if_indextonamep(__ifindex, __ifname); + + AFTER_ORIGINAL_NOSOCK_RET(VT_PTR, cret, 0, FD_API_OTHER, + "%u, %p", __ifindex, __ifname); + + return cret; +} + +struct if_nameindex *if_nameindex (void) +{ + static struct if_nameindex * (*if_nameindexp)(void); + struct if_nameindex * pret; + + BEFORE_ORIGINAL_NOFILTER(if_nameindex, LIBC); + + pret = if_nameindexp(); + + AFTER_ORIGINAL_NOSOCK_RET(VT_PTR, pret, 0, FD_API_OTHER, "%s", ""); + + return pret; +} + +void if_freenameindex (struct if_nameindex *__ptr) +{ + static void (*if_freenameindexp)(struct if_nameindex *__ptr); + + BEFORE_ORIGINAL_NOFILTER(if_freenameindex, LIBC); + + if_freenameindexp(__ptr); + + AFTER_ORIGINAL_NOSOCK_RET(VT_NULL, NULL, 0, FD_API_OTHER, "%p", __ptr); +} + +int getifaddrs(struct ifaddrs **ifap) +{ + static int (*getifaddrsp)(struct ifaddrs **ifap); + + BEFORE_ORIGINAL_NOFILTER(getifaddrs, LIBC); + + ret = getifaddrsp(ifap); + + AFTER_ORIGINAL_NOSOCK(0, FD_API_OTHER, "%p", ifap); + + return ret; +} + +void freeifaddrs(struct ifaddrs *ifa) +{ + static void (*freeifaddrsp)(struct ifaddrs *ifa); + + BEFORE_ORIGINAL_NOFILTER(freeifaddrs, LIBC); + + freeifaddrsp(ifa); + + AFTER_ORIGINAL_NOSOCK_RET(VT_NULL, NULL, 0, FD_API_OTHER, "%p", ifa); +} + +#if 0 +int poll(struct pollfd *ufds, unsigned int nfds, int timeout) +{ + static int (*pollp)(struct pollfd *ufds, unsigned int nfds, int timeout); + + BEFORE_ORIGINAL(poll, LIBC); + + ret = pollp(ufds, nfds, timeout); + + AFTER_ORIGINAL_NOSOCK(timeout, FD_API_OTHER, "%p, %u, %d", ufds, nfds, timeout); + + return ret; +} + +int ppoll(struct pollfd *fds, nfds_t nfds, const struct timespec *timeout_ts, const sigset_t *sigmask) +{ + static int (*ppollp)(struct pollfd *fds, nfds_t nfds, const struct timespec *timeout_ts, const sigset_t *sigmask); + + BEFORE_ORIGINAL(ppoll, LIBC); + + ret = ppollp(fds, nfds, timeout_ts, sigmask); + + AFTER_ORIGINAL_NOSOCK(0, FD_API_OTHER, "%p, %lu, %p, %p", + fds, nfds, timeout_ts, sigmask); + + return ret; +} +#endif + +#endif diff --git a/probe_third/libdaemon.c b/probe_third/libdaemon.c new file mode 100644 index 0000000..755d9e8 --- /dev/null +++ b/probe_third/libdaemon.c @@ -0,0 +1,89 @@ +/* + * DA probe + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Jaewon Lim + * Woojin Jung + * Juyoung Kim + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#include // for malloc +#include // for memcpy +#include // for errno + +#include "daprobe.h" +#include "dahelper.h" + +int daemon_close_allv(const int except_fds[]) +{ + static int (*daemon_close_allvp)(const int except_fds[]); + int i, saved_errno, ret; + int* fds; + + GET_REAL_FUNCP(daemon_close_allv, LIBDAEMON, daemon_close_allvp); + + probeBlockStart(); + // get number of fds + for(i = 0; ; i++) + { + if(except_fds[i] == -1) + break; + } + + // allocate memory for new except fds + fds = (int*)malloc((i + 2) * sizeof(int)); + + // copy fds + if(fds) + { + if(i > 0) + memcpy(fds, except_fds, i * sizeof(int)); + fds[i] = gTraceInfo.socket.daemonSock; + fds[i + 1] = -1; + } + else + { + // do nothing + } + probeBlockEnd(); + + // call original function + if(fds) + { + ret = daemon_close_allvp(fds); + } + else + { + ret = daemon_close_allvp(except_fds); + } + + probeBlockStart(); + saved_errno = errno; + free(fds); + errno = saved_errno; + probeBlockEnd(); + + return ret; +} + diff --git a/probe_thread/da_sync.h b/probe_thread/da_sync.h new file mode 100644 index 0000000..88d6e7d --- /dev/null +++ b/probe_thread/da_sync.h @@ -0,0 +1,89 @@ +/* + * DA probe + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Woojin Jung + * Jaewon Lim + * Juyoung Kim + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#ifndef __DA_SYNC_H__ +#define __DA_SYNC_H__ + +#include "daprobe.h" + +#ifdef __cplusplus +extern "C"{ +#endif + +int real_pthread_mutex_lock(pthread_mutex_t *mutex); +int real_pthread_mutex_unlock(pthread_mutex_t *mutex); +int real_pthread_setcancelstate(int state, int *oldstate); + +#define BEFORE_ORIGINAL_SYNC(FUNCNAME, LIBNAME) \ + DECLARE_VARIABLE_STANDARD; \ + GET_REAL_FUNC(FUNCNAME, LIBNAME); \ + PRE_PROBEBLOCK() + +#define POST_PROBEBLOCK_MIDDLE_SYNCVAL(SYNCVAL, SYNCTYPE, APITYPE) \ + log.length += sprintf(log.data + log.length, "`,%p`,%d`,%d", \ + SYNCVAL, SYNCTYPE, APITYPE) + +#define POST_PROBEBLOCK_MIDDLE_NOSYNCVAL(SYNCTYPE, APITYPE) \ + log.length += sprintf(log.data + log.length, "`,0`,%d`,%d", \ + SYNCTYPE, APITYPE) + +#define AFTER_ORIGINAL_SYNCVAL_RET(RTYPE, RVAL, SYNCVAL, SYNCTYPE, APITYPE, INPUTFORMAT, ...) \ + POST_PROBEBLOCK_BEGIN(LC_SYNC, RTYPE, RVAL, INPUTFORMAT, __VA_ARGS__); \ + POST_PROBEBLOCK_MIDDLE_SYNCVAL(SYNCVAL, SYNCTYPE, APITYPE); \ + POST_PROBEBLOCK_CALLSTACK(); \ + POST_PROBEBLOCK_END() + +#define AFTER_ORIGINAL_NOSYNCVAL_RET(RTYPE, RVAL, SYNCTYPE, APITYPE, INPUTFORMAT, ...) \ + POST_PROBEBLOCK_BEGIN(LC_SYNC, RTYPE, RVAL, INPUTFORMAT, __VA_ARGS__); \ + POST_PROBEBLOCK_MIDDLE_NOSYNCVAL(SYNCTYPE, APITYPE); \ + POST_PROBEBLOCK_CALLSTACK(); \ + POST_PROBEBLOCK_END() + +#define BEFORE_ORIGINAL_START_END_SYNC(FUNCNAME, LIBNAME, SYNCVAL, SYNCTYPE, APITYPE, INPUTFORMAT, ...) \ + DECLARE_VARIABLE_STANDARD; \ + GET_REAL_FUNC(FUNCNAME, LIBNAME); \ + PRE_START_END_PROBEBLOCK_BEGIN(LC_SYNC, INPUTFORMAT, __VA_ARGS__); \ + POST_PROBEBLOCK_MIDDLE_SYNCVAL(SYNCVAL, SYNCTYPE, APITYPE); \ + APPEND_LOG_NULL_CALLSTACK(); \ + printLog(&log, MSG_LOG); \ + PRE_PROBEBLOCK_END() + +#define AFTER_ORIGINAL_START_END_SYNCVAL_RET(RTYPE, RVAL, SYNCVAL, SYNCTYPE, APITYPE, INPUTFORMAT, ...) \ + POST_START_END_PROBEBLOCK_BEGIN(LC_SYNC, RTYPE, RVAL, INPUTFORMAT, __VA_ARGS__); \ + POST_PROBEBLOCK_MIDDLE_SYNCVAL(SYNCVAL, SYNCTYPE, APITYPE); \ + POST_PROBEBLOCK_CALLSTACK(); \ + POST_PROBEBLOCK_END() + +#ifdef __cplusplus +} +#endif + +#endif // __DA_SYNC_H__ + diff --git a/probe_thread/da_thread.h b/probe_thread/da_thread.h new file mode 100644 index 0000000..8ab43fb --- /dev/null +++ b/probe_thread/da_thread.h @@ -0,0 +1,71 @@ +/* + * DA probe + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Woojin Jung + * Jaewon Lim + * Juyoung Kim + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#ifndef __DA_THREAD_H__ +#define __DA_THREAD_H__ + +#include "daprobe.h" + +#define DECLARE_VARIABLE_THREAD \ + DECLARE_VARIABLE_STANDARD +// pthread_t pSelf + +#define BEFORE_ORIGINAL_THREAD(FUNCNAME, LIBNAME) \ + DECLARE_VARIABLE_THREAD; \ + GET_REAL_FUNC(FUNCNAME, LIBNAME); \ + PRE_PROBEBLOCK() + +#define POST_PROBEBLOCK_MIDDLE_THREAD(THREADVAL, APITYPE) \ + log.length += sprintf(log.data + log.length, "`,%lu`,`,%d`,%d", \ + THREADVAL, THREAD_PTHREAD, APITYPE) + +#define AFTER_ORIGINAL_THREAD_RET(RTYPE, RVAL, THREADVAL, APITYPE, INPUTFORMAT, ...) \ + POST_PROBEBLOCK_BEGIN(LC_THREAD, RTYPE, RVAL, INPUTFORMAT, __VA_ARGS__); \ + POST_PROBEBLOCK_MIDDLE_THREAD(THREADVAL, APITYPE); \ + POST_PROBEBLOCK_CALLSTACK(); \ + POST_PROBEBLOCK_END() + +#define BEFORE_ORIGINAL_START_END_THREAD(FUNCNAME, LIBNAME, THREADVAL, APITYPE, INPUTFORMAT, ...) \ + DECLARE_VARIABLE_THREAD; \ + GET_REAL_FUNC(FUNCNAME, LIBNAME); \ + PRE_START_END_PROBEBLOCK_BEGIN(LC_THREAD, INPUTFORMAT, __VA_ARGS__); \ + POST_PROBEBLOCK_MIDDLE_THREAD(THREADVAL, APITYPE); \ + APPEND_LOG_NULL_CALLSTACK(); \ + printLog(&log, MSG_LOG); \ + PRE_PROBEBLOCK_END() + +#define AFTER_ORIGINAL_START_END_THREAD_RET(RTYPE, RVAL, THREADVAL, APITYPE, INPUTFORMAT, ...) \ + POST_START_END_PROBEBLOCK_BEGIN(LC_THREAD, RTYPE, RVAL, INPUTFORMAT, __VA_ARGS__); \ + POST_PROBEBLOCK_MIDDLE_THREAD(THREADVAL, APITYPE); \ + POST_PROBEBLOCK_CALLSTACK(); \ + POST_PROBEBLOCK_END() + +#endif // __DA_THREAD_H__ + diff --git a/probe_thread/libdasync.c b/probe_thread/libdasync.c new file mode 100644 index 0000000..f7a4fdc --- /dev/null +++ b/probe_thread/libdasync.c @@ -0,0 +1,416 @@ +/* + * DA probe + * + * Copyright 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Woojin Jung + * Jaewon Lim + * Juyoung Kim + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#include +#include +#include +#include "daprobe.h" +#include "probeinfo.h" +#include "dahelper.h" +#include "da_sync.h" + +static enum DaOptions _sopt = OPT_THREAD; + +int pthread_mutex_init(pthread_mutex_t *mutex, + const pthread_mutexattr_t *attr) { + static int (*pthread_mutex_initp)(pthread_mutex_t *mutex, + const pthread_mutexattr_t *attr); + + BEFORE_ORIGINAL_SYNC(pthread_mutex_init, LIBPTHREAD); + + ret = pthread_mutex_initp(mutex, attr); + + AFTER_ORIGINAL_SYNCVAL_RET(VT_INT, ret, mutex, SYNC_PTHREAD_MUTEX, + SYNC_API_OTHER, "%p,%p", mutex, attr); + + return ret; +} + +int pthread_mutex_destroy(pthread_mutex_t *mutex) { + static int (*pthread_mutex_destroyp)(pthread_mutex_t *mutex); + + BEFORE_ORIGINAL_SYNC(pthread_mutex_destroy, LIBPTHREAD); + + ret = pthread_mutex_destroyp(mutex); + + AFTER_ORIGINAL_SYNCVAL_RET(VT_INT, ret, mutex, SYNC_PTHREAD_MUTEX, + SYNC_API_OTHER, "%p", mutex); + + return ret; +} + +int real_pthread_mutex_lock(pthread_mutex_t *mutex) { + static int (*pthread_mutex_lockp)(pthread_mutex_t *mutex); + + GET_REAL_FUNC(pthread_mutex_lock, LIBPTHREAD); + + return pthread_mutex_lockp(mutex); +} + +int pthread_mutex_lock(pthread_mutex_t *mutex) { + static int (*pthread_mutex_lockp)(pthread_mutex_t *mutex); + + BEFORE_ORIGINAL_START_END_SYNC(pthread_mutex_lock, LIBPTHREAD, mutex, SYNC_PTHREAD_MUTEX, SYNC_API_ACQUIRE_WAIT_START, "%p", mutex); + + ret = pthread_mutex_lockp(mutex); + + AFTER_ORIGINAL_START_END_SYNCVAL_RET(VT_INT, ret, mutex, SYNC_PTHREAD_MUTEX, SYNC_API_ACQUIRE_WAIT_END, "%p", mutex); + + return ret; +} + +int pthread_mutex_timedlock(pthread_mutex_t *mutex, + const struct timespec *abs_timeout) { + static int (*pthread_mutex_timedlockp)(pthread_mutex_t *mutex, + const struct timespec *abs_timeout); + + BEFORE_ORIGINAL_START_END_SYNC(pthread_mutex_timedlock, LIBPTHREAD, mutex, SYNC_PTHREAD_MUTEX, SYNC_API_ACQUIRE_WAIT_START, "%p,%p", mutex, abs_timeout); + + ret = pthread_mutex_timedlockp(mutex, abs_timeout); + + AFTER_ORIGINAL_START_END_SYNCVAL_RET(VT_INT, ret, mutex, SYNC_PTHREAD_MUTEX, SYNC_API_ACQUIRE_WAIT_END, "%p,%p", mutex, abs_timeout); + + return ret; +} + +int pthread_mutex_trylock(pthread_mutex_t *mutex) { + static int (*pthread_mutex_trylockp)(pthread_mutex_t *mutex); + + BEFORE_ORIGINAL_SYNC(pthread_mutex_trylock, LIBPTHREAD); + + ret = pthread_mutex_trylockp(mutex); + + AFTER_ORIGINAL_SYNCVAL_RET(VT_INT, ret, mutex, SYNC_PTHREAD_MUTEX, + SYNC_API_TRY_ACQUIRE, "%p", mutex); + + return ret; +} + +int real_pthread_mutex_unlock(pthread_mutex_t *mutex) { + static int (*pthread_mutex_unlockp)(pthread_mutex_t *mutex); + + GET_REAL_FUNC(pthread_mutex_unlock, LIBPTHREAD); + + return pthread_mutex_unlockp(mutex); +} + +int pthread_mutex_unlock(pthread_mutex_t *mutex) { + static int (*pthread_mutex_unlockp)(pthread_mutex_t *mutex); + + BEFORE_ORIGINAL_SYNC(pthread_mutex_unlock, LIBPTHREAD); + + ret = pthread_mutex_unlockp(mutex); + + AFTER_ORIGINAL_SYNCVAL_RET(VT_INT, ret, mutex, SYNC_PTHREAD_MUTEX, + SYNC_API_RELEASE, "%p", mutex); + + return ret; +} + +int pthread_mutexattr_init(pthread_mutexattr_t *attr) { + static int (*pthread_mutexattr_initp)(pthread_mutexattr_t *attr); + + BEFORE_ORIGINAL_SYNC(pthread_mutexattr_init, LIBPTHREAD); + + ret = pthread_mutexattr_initp(attr); + + AFTER_ORIGINAL_NOSYNCVAL_RET(VT_INT, ret, SYNC_PTHREAD_MUTEX, + SYNC_API_OTHER, "%p", attr); + + return ret; +} + +int pthread_mutexattr_destroy(pthread_mutexattr_t *attr) { + static int (*pthread_mutexattr_destroyp)(pthread_mutexattr_t *attr); + + BEFORE_ORIGINAL_SYNC(pthread_mutexattr_destroy, LIBPTHREAD); + + ret = pthread_mutexattr_destroyp(attr); + + AFTER_ORIGINAL_NOSYNCVAL_RET(VT_INT, ret, SYNC_PTHREAD_MUTEX, + SYNC_API_OTHER, "%p", attr); + + return ret; +} + +int pthread_mutexattr_getprioceiling(const pthread_mutexattr_t *attr, + int *prioceiling) { + static int (*pthread_mutexattr_getprioceilingp)( + const pthread_mutexattr_t *attr, int *prioceiling); + + BEFORE_ORIGINAL_SYNC(pthread_mutexattr_getprioceiling, LIBPTHREAD); + + ret = pthread_mutexattr_getprioceilingp(attr, prioceiling); + + AFTER_ORIGINAL_NOSYNCVAL_RET(VT_INT, ret, SYNC_PTHREAD_MUTEX, + SYNC_API_OTHER, "%p,%p", attr, prioceiling); + + return ret; +} + +int pthread_mutexattr_setprioceiling(pthread_mutexattr_t *attr, + int prioceiling) { + static int (*pthread_mutexattr_setprioceilingp)( + pthread_mutexattr_t *attr, int prioceiling); + + BEFORE_ORIGINAL_SYNC(pthread_mutexattr_setprioceiling, LIBPTHREAD); + + ret = pthread_mutexattr_setprioceilingp(attr, prioceiling); + + AFTER_ORIGINAL_NOSYNCVAL_RET(VT_INT, ret, SYNC_PTHREAD_MUTEX, + SYNC_API_OTHER, "%p,%d", attr, prioceiling); + + return ret; +} + +int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *attr, + int *protocol) { + static int (*pthread_mutexattr_getprotocolp)( + const pthread_mutexattr_t *attr, int *protocol); + + BEFORE_ORIGINAL_SYNC(pthread_mutexattr_getprotocol, LIBPTHREAD); + + ret = pthread_mutexattr_getprotocolp(attr, protocol); + + AFTER_ORIGINAL_NOSYNCVAL_RET(VT_INT, ret, SYNC_PTHREAD_MUTEX, + SYNC_API_OTHER, "%p,%p", attr, protocol); + + return ret; +} + +int pthread_mutexattr_setprotocol(pthread_mutexattr_t *attr, + int protocol) { + static int (*pthread_mutexattr_setprotocolp)( + pthread_mutexattr_t *attr, int protocol); + + BEFORE_ORIGINAL_SYNC(pthread_mutexattr_setprotocol, LIBPTHREAD); + + ret = pthread_mutexattr_setprotocolp(attr, protocol); + + AFTER_ORIGINAL_NOSYNCVAL_RET(VT_INT, ret, SYNC_PTHREAD_MUTEX, + SYNC_API_OTHER, "%p,%d", attr, protocol); + + return ret; +} + +int pthread_mutexattr_getpshared(const pthread_mutexattr_t *attr, + int *pshared) { + static int (*pthread_mutexattr_getpsharedp)( + const pthread_mutexattr_t *attr, int *pshared); + + BEFORE_ORIGINAL_SYNC(pthread_mutexattr_getpshared, LIBPTHREAD); + + ret = pthread_mutexattr_getpsharedp(attr, pshared); + + AFTER_ORIGINAL_NOSYNCVAL_RET(VT_INT, ret, SYNC_PTHREAD_MUTEX, + SYNC_API_OTHER, "%p,%p", attr, pshared); + + return ret; +} + +int pthread_mutexattr_setpshared(pthread_mutexattr_t *attr, + int pshared) { + static int (*pthread_mutexattr_setpsharedp)( + pthread_mutexattr_t *attr, int pshared); + + BEFORE_ORIGINAL_SYNC(pthread_mutexattr_setpshared, LIBPTHREAD); + + ret = pthread_mutexattr_setpsharedp(attr, pshared); + + AFTER_ORIGINAL_NOSYNCVAL_RET(VT_INT, ret, SYNC_PTHREAD_MUTEX, + SYNC_API_OTHER, "%p,%d", attr, pshared); + + return ret; +} + +int pthread_mutexattr_gettype(const pthread_mutexattr_t *attr, int *type) { + static int (*pthread_mutexattr_gettypep)( + const pthread_mutexattr_t *attr, int *type); + + BEFORE_ORIGINAL_SYNC(pthread_mutexattr_gettype, LIBPTHREAD); + + ret = pthread_mutexattr_gettypep(attr, type); + + AFTER_ORIGINAL_NOSYNCVAL_RET(VT_INT, ret, SYNC_PTHREAD_MUTEX, + SYNC_API_OTHER, "%p,%p", attr, type); + + return ret; +} + +int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type) { + static int (*pthread_mutexattr_settypep)( + pthread_mutexattr_t *attr, int type); + + BEFORE_ORIGINAL_SYNC(pthread_mutexattr_settype, LIBPTHREAD); + + ret = pthread_mutexattr_settypep(attr, type); + + AFTER_ORIGINAL_NOSYNCVAL_RET(VT_INT, ret, SYNC_PTHREAD_MUTEX, + SYNC_API_OTHER, "%p,%d", attr, type); + + return ret; +} + +/* +int pthread_mutex_getprioceiling(const pthread_mutex_t *mutex, + int *prioceiling); +int pthread_mutex_setprioceiling(pthread_mutex_t *mutex, + int prioceiling, int *old_ceiling); +*/ + +int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr) { + static int (*pthread_cond_initp)(pthread_cond_t *cond, + const pthread_condattr_t *attr); + + BEFORE_ORIGINAL_SYNC(pthread_cond_init, LIBPTHREAD); + + ret = pthread_cond_initp(cond, attr); + + AFTER_ORIGINAL_SYNCVAL_RET(VT_INT, ret, cond, SYNC_PTHREAD_COND_VARIABLE, + SYNC_API_OTHER, "%p,%p", cond, attr); + + return ret; +} + +int pthread_cond_destroy(pthread_cond_t *cond) { + static int (*pthread_cond_destroyp)(pthread_cond_t *cond); + + BEFORE_ORIGINAL_SYNC(pthread_cond_destroy, LIBPTHREAD); + + ret = pthread_cond_destroyp(cond); + + AFTER_ORIGINAL_SYNCVAL_RET(VT_INT, ret, cond, SYNC_PTHREAD_COND_VARIABLE, + SYNC_API_OTHER, "%p", cond); + + return ret; +} + +int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex) { + static int (*pthread_cond_waitp)(pthread_cond_t *cond, + pthread_mutex_t *mutex); + + BEFORE_ORIGINAL_START_END_SYNC(pthread_cond_wait, LIBPTHREAD, cond, SYNC_PTHREAD_COND_VARIABLE, SYNC_API_COND_WAIT_START, "%p,%p", cond, mutex); + + ret = pthread_cond_waitp(cond, mutex); + + AFTER_ORIGINAL_START_END_SYNCVAL_RET(VT_INT, ret, cond, SYNC_PTHREAD_COND_VARIABLE, SYNC_API_COND_WAIT_END, "%p,%p", cond, mutex); + + return ret; +} + +int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, + const struct timespec *abstime) { + static int (*pthread_cond_timedwaitp)(pthread_cond_t *cond, + pthread_mutex_t *mutex, const struct timespec *abstime); + + BEFORE_ORIGINAL_START_END_SYNC(pthread_cond_timedwait, LIBPTHREAD, cond, SYNC_PTHREAD_COND_VARIABLE, SYNC_API_COND_WAIT_START, "%p,%p,%p", cond, mutex, abstime); + + ret = pthread_cond_timedwaitp(cond, mutex, abstime); + + AFTER_ORIGINAL_START_END_SYNCVAL_RET(VT_INT, ret, cond, SYNC_PTHREAD_COND_VARIABLE, SYNC_API_COND_WAIT_END, "%p,%p,%p", cond, mutex, abstime); + + return ret; +} + +int pthread_cond_signal(pthread_cond_t *cond) { + static int (*pthread_cond_signalp)(pthread_cond_t *cond); + + BEFORE_ORIGINAL_SYNC(pthread_cond_signal, LIBPTHREAD); + + ret = pthread_cond_signalp(cond); + + AFTER_ORIGINAL_SYNCVAL_RET(VT_INT, ret, cond, SYNC_PTHREAD_COND_VARIABLE, + SYNC_API_NOTIFY, "%p", cond); + + return ret; +} + +int pthread_cond_broadcast(pthread_cond_t *cond) { + static int (*pthread_cond_broadcastp)(pthread_cond_t *cond); + + BEFORE_ORIGINAL_SYNC(pthread_cond_broadcast, LIBPTHREAD); + + ret = pthread_cond_broadcastp(cond); + + AFTER_ORIGINAL_SYNCVAL_RET(VT_INT, ret, cond, SYNC_PTHREAD_COND_VARIABLE, + SYNC_API_NOTIFY_ALL, "%p", cond); + + return ret; +} + +/* +int pthread_condattr_init(pthread_condattr_t *attr); +int pthread_condattr_destroy(pthread_condattr_t *attr); +int pthread_condattr_getclock(const pthread_condattr_t *attr, + clockid_t *clock_id); +int pthread_condattr_setclock(pthread_condattr_t *attr, + clockid_t clock_id); +int pthread_condattr_getpshared(const pthread_condattr_t *attr, int *pshared); +int pthread_condattr_setpshared(pthread_condattr_t *attr, int pshared); +*/ + +/* +int pthread_rwlock_init(pthread_rwlock_t *rwlock, + const pthread_rwlockattr_t *attr); +int pthread_rwlock_destroy(pthread_rwlock_t *rwlock); +int pthread_rwlock_rdlock(pthread_rwlock_t *rwlock); +int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock); +int pthread_rwlock_timedrdlock(pthread_rwlock_t *rwlock, + const struct timespec *abs_timeout); +int pthread_rwlock_timedwrlock(pthread_rwlock_t *rwlock, + const struct timespec *abs_timeout); +int pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock); +int pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock); +int pthread_rwlock_unlock(pthread_rwlock_t *rwlock); +int pthread_rwlockattr_init(pthread_rwlockattr_t *attr); +int pthread_rwlockattr_destroy(pthread_rwlockattr_t *attr); +int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *attr, + int *pshared); +int pthread_rwlockattr_setpshared(pthread_rwlockattr_t *attr, + int pshared); + +int pthread_spin_init(pthread_spinlock_t *lock, int pshared); +int pthread_spin_destroy(pthread_spinlock_t *lock); +int pthread_spin_lock(pthread_spinlock_t *lock); +int pthread_spin_trylock(pthread_spinlock_t *lock); +int pthread_spin_unlock(pthread_spinlock_t *lock); + +int pthread_barrier_init(pthread_barrier_t *barrier, + const pthread_barrierattr_t *attr, unsigned int count); +int pthread_barrier_destroy(pthread_barrier_t *barrier); +int pthread_barrier_wait(pthread_barrier_t *barrier); +int pthread_barrierattr_init(pthread_barrierattr_t *attr); +int pthread_barrierattr_destroy(pthread_barrierattr_t *attr); +int pthread_barrierattr_getpshared(const pthread_barrierattr_t *attr, + int *pshared); +int pthread_barrierattr_setpshared(pthread_barrierattr_t, + int pshared); +*/ + diff --git a/probe_thread/libdathread.c b/probe_thread/libdathread.c new file mode 100644 index 0000000..bc52e47 --- /dev/null +++ b/probe_thread/libdathread.c @@ -0,0 +1,646 @@ +/* + * DA probe + * + * Copyright 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Woojin Jung + * Jaewon Lim + * Juyoung Kim + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#include +#include +#include "daprobe.h" +#include "probeinfo.h" +#include "dahelper.h" +#include "da_thread.h" +#include "da_sync.h" + +typedef struct thread_routine_call_t { + void *(*thread_routine)(void *); + void *argument; +} thread_routine_call; + +static enum DaOptions _sopt = OPT_THREAD; + +// called when pthread_exit, pthread_cancel is called +void _da_cleanup_handler(void *data) +{ + pthread_t pSelf; + + DECLARE_COMMON_VARIABLE; + INIT_LOG; + + // unlock socket mutex to prevent deadlock + // in case of cancellation happened while log sending + real_pthread_mutex_unlock(&(gTraceInfo.socket.sockMutex)); + + PRE_UNCONDITIONAL_BLOCK_BEGIN(); + APPEND_LOG_BASIC(LC_THREAD); + // input,ret,PCAddr,errno,InternalCall,CallerPCAddr + log.length += sprintf(log.data + log.length, "`,`,`,0`,0`,1`,0"); + pSelf = pthread_self(); + log.length += sprintf(log.data + log.length, "`,%lu`,`,%d`,%d", + pSelf, THREAD_PTHREAD, THREAD_API_INTERNAL_STOP); + APPEND_LOG_NULL_CALLSTACK(); + printLog(&log, MSG_LOG); + PRE_UNCONDITIONAL_BLOCK_END(); + + return; +} + +void *_da_ThreadProc(void *params) +{ + void *ret; + thread_routine_call *ptrc; + ptrc = (thread_routine_call *) params; + pthread_t pSelf; + int old_state; + int new_state = PTHREAD_CANCEL_DISABLE; + + DECLARE_COMMON_VARIABLE; + + // send INTERNAL_START log + INIT_LOG; + + // disable cancellation to prevent deadlock + real_pthread_setcancelstate(new_state, &old_state); + + PRE_UNCONDITIONAL_BLOCK_BEGIN(); + APPEND_LOG_BASIC(LC_THREAD); + // input,ret,PCAddr,errno,InternalCall,CallerPCAddr + log.length += sprintf(log.data + log.length, "`,`,`,0`,0`,1`,0"); + pSelf = pthread_self(); + log.length += sprintf(log.data + log.length, "`,%lu`,`,%d`,%d", + pSelf, THREAD_PTHREAD, THREAD_API_INTERNAL_START); + APPEND_LOG_NULL_CALLSTACK(); + printLog(&log, MSG_LOG); + PRE_UNCONDITIONAL_BLOCK_END(); + + // restore cancellation state + real_pthread_setcancelstate(old_state, NULL); + + pthread_cleanup_push(_da_cleanup_handler, NULL); + // call user-defined thread routine + ret = ptrc->thread_routine(ptrc->argument); + pthread_cleanup_pop(0); + + // disable cancellation to prevent deadlock + real_pthread_setcancelstate(new_state, &old_state); + + // send INTERNAL_STOP log + INIT_LOG; + + PRE_UNCONDITIONAL_BLOCK_BEGIN(); + APPEND_LOG_BASIC(LC_THREAD); + // input,ret,PCAddr,errno,InternalCall,CallerPCAddr + log.length += sprintf(log.data + log.length, "`,`,`,0`,0`,1`,0"); + pSelf = pthread_self(); + log.length += sprintf(log.data + log.length, "`,%lu`,`,%d`,%d", + pSelf, THREAD_PTHREAD, THREAD_API_INTERNAL_STOP); + APPEND_LOG_NULL_CALLSTACK(); + printLog(&log, MSG_LOG); + PRE_UNCONDITIONAL_BLOCK_END(); + + free(ptrc); + return ret; +} + +int pthread_create(pthread_t *thread, const pthread_attr_t *attr, + void *(*start_routine) (void*), void *arg) +{ + static int (*pthread_createp)(pthread_t *thread, + const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg); + + BEFORE_ORIGINAL_THREAD(pthread_create, LIBPTHREAD); + + if(blockresult) + { + probeBlockStart(); + thread_routine_call *ptrc = + (thread_routine_call *) malloc(sizeof(thread_routine_call)); + ptrc->thread_routine = start_routine; + ptrc->argument = arg; + probeBlockEnd(); + + ret = pthread_createp(thread, attr, _da_ThreadProc, (void *) ptrc); + } + else // when pthread_create is called inside probe so (ex. custom chart, sampling thread) + { + ret = pthread_createp(thread, attr, start_routine, arg); + } + + AFTER_ORIGINAL_THREAD_RET(VT_INT, ret, *thread, THREAD_API_START, + "%p,%p,%p,%p", thread, attr, start_routine, arg); + + return ret; +} + +int pthread_join(pthread_t thread, void **retval) +{ + static int (*pthread_joinp)(pthread_t thread, void **retval); + + BEFORE_ORIGINAL_START_END_THREAD(pthread_join, LIBPTHREAD, thread, THREAD_API_WAIT_START, "%lu,%p", thread, retval); + + ret = pthread_joinp(thread, retval); + + AFTER_ORIGINAL_START_END_THREAD_RET(VT_INT, ret, thread, THREAD_API_WAIT_END, "%lu,%p", thread, retval); + + return ret; +} + +void pthread_exit(void *retval) +{ + pthread_t pSelf; + static void (*pthread_exitp)(void *retval) __attribute__((noreturn)); + + DECLARE_VARIABLE_STANDARD; + GET_REAL_FUNC(pthread_exit, LIBPTHREAD); + + PRE_PROBEBLOCK_BEGIN(); + newerrno = 0; + INIT_LOG; + APPEND_LOG_BASIC(LC_THREAD); + APPEND_LOG_INPUT("%p", retval); + //ret,PCAddr,errno,InternalCall + log.length += sprintf(log.data + log.length, "`,`,0`,0`,%d", blockresult); + APPEND_LOG_CALLER(); + pSelf = pthread_self(); + log.length += sprintf(log.data + log.length, "`,%lu`,`,%d`,%d", + pSelf, THREAD_PTHREAD, THREAD_API_EXIT); + APPEND_LOG_NULL_CALLSTACK(); + printLog(&log, MSG_LOG); + PRE_PROBEBLOCK_END(); + + pthread_exitp(retval); +} + +int pthread_cancel(pthread_t thread) +{ + static int (*pthread_cancelp)(pthread_t thread); + + BEFORE_ORIGINAL_THREAD(pthread_cancel, LIBPTHREAD); + + ret = pthread_cancelp(thread); + + AFTER_ORIGINAL_THREAD_RET(VT_INT, ret, thread, THREAD_API_STOP, "%lu", thread); + + return ret; +} + +int pthread_detach(pthread_t thread) +{ + static int (*pthread_detachp)(pthread_t thread); + + BEFORE_ORIGINAL_THREAD(pthread_detach, LIBPTHREAD); + + ret = pthread_detachp(thread); + + AFTER_ORIGINAL_THREAD_RET(VT_INT, ret, thread, THREAD_API_OTHER, "%lu", thread); + + return ret; +} + +pthread_t pthread_self(void) +{ + pthread_t ret_pthr; + static pthread_t (*pthread_selfp)(void); + + BEFORE_ORIGINAL_THREAD(pthread_self, LIBPTHREAD); + + ret_pthr = pthread_selfp(); + + newerrno = errno; + if(postBlockBegin(blockresult)) { + INIT_LOG; + APPEND_LOG_BASIC(LC_THREAD); + log.length += sprintf(log.data + log.length, "`,"); + APPEND_LOG_RESULT(VT_ULONG, ret_pthr); + APPEND_LOG_CALLER(); + + POST_PROBEBLOCK_MIDDLE_THREAD(ret_pthr, THREAD_API_OTHER); + POST_PROBEBLOCK_CALLSTACK(); + printLog(&log, MSG_LOG); + postBlockEnd(); + } + + return ret_pthr; +} + +int pthread_equal(pthread_t t1, pthread_t t2) +{ + static int (*pthread_equalp)(pthread_t t1, pthread_t t2); + + BEFORE_ORIGINAL_THREAD(pthread_equal, LIBPTHREAD); + + ret = pthread_equalp(t1, t2); + + AFTER_ORIGINAL_THREAD_RET(VT_INT, ret, t1, THREAD_API_OTHER, "%lu,%lu", t1, t2); + + return ret; +} + +int real_pthread_setcancelstate(int state, int *oldstate) +{ + static int (*pthread_setcancelstatep)(int state, int *oldstate); + + GET_REAL_FUNC(pthread_setcancelstate, LIBPTHREAD); + + return pthread_setcancelstatep(state, oldstate); +} + +int pthread_setcancelstate(int state, int *oldstate) +{ + pthread_t pSelf; + static int (*pthread_setcancelstatep)(int state, int *oldstate); + + BEFORE_ORIGINAL_THREAD(pthread_setcancelstate, LIBPTHREAD); + + pSelf = pthread_self(); + ret = pthread_setcancelstatep(state, oldstate); + + AFTER_ORIGINAL_THREAD_RET(VT_INT, ret, pSelf, THREAD_API_OTHER, + "%d,%p", state, oldstate); + + return ret; +} + +int pthread_setcanceltype(int type, int *oldtype) +{ + pthread_t pSelf; + static int (*pthread_setcanceltypep)(int type, int *oldtype); + + BEFORE_ORIGINAL_THREAD(pthread_setcanceltype, LIBPTHREAD); + + pSelf = pthread_self(); + ret = pthread_setcanceltypep(type, oldtype); + + AFTER_ORIGINAL_THREAD_RET(VT_INT, ret, pSelf, THREAD_API_OTHER, + "%d,%p", type, oldtype); + + return ret; +} + +int pthread_attr_init(pthread_attr_t *attr) +{ + pthread_t thread = 0; + static int (*pthread_attr_initp)(pthread_attr_t *attr); + + BEFORE_ORIGINAL_THREAD(pthread_attr_init, LIBPTHREAD); + + ret = pthread_attr_initp(attr); + + AFTER_ORIGINAL_THREAD_RET(VT_INT, ret, thread, THREAD_API_OTHER, "%p", attr); + + return ret; +} + +int pthread_attr_destroy(pthread_attr_t *attr) +{ + pthread_t thread = 0; + static int (*pthread_attr_destroyp)(pthread_attr_t *attr); + + BEFORE_ORIGINAL_THREAD(pthread_attr_destroy, LIBPTHREAD); + + ret = pthread_attr_destroyp(attr); + + AFTER_ORIGINAL_THREAD_RET(VT_INT, ret, thread, THREAD_API_OTHER, "%p", attr); + + return ret; +} + +int pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate) +{ + pthread_t thread = 0; + static int (*pthread_attr_getdetachstatep)(const pthread_attr_t *attr, + int *detachstate); + + BEFORE_ORIGINAL_THREAD(pthread_attr_getdetachstate, LIBPTHREAD); + + ret = pthread_attr_getdetachstatep(attr, detachstate); + + AFTER_ORIGINAL_THREAD_RET(VT_INT, ret, thread, THREAD_API_OTHER, + "%p,%p", attr, detachstate); + + return ret; +} + +int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate) +{ + pthread_t thread = 0; + static int (*pthread_attr_setdetachstatep)(pthread_attr_t *attr, + int detachstate); + + BEFORE_ORIGINAL_THREAD(pthread_attr_setdetachstate, LIBPTHREAD); + + ret = pthread_attr_setdetachstatep(attr, detachstate); + + AFTER_ORIGINAL_THREAD_RET(VT_INT, ret, thread, THREAD_API_OTHER, + "%p,%d", attr, detachstate); + + return ret; +} + +int pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stacksize) +{ + pthread_t thread = 0; + static int (*pthread_attr_getstacksizep)(const pthread_attr_t *attr, + size_t *stacksize); + + BEFORE_ORIGINAL_THREAD(pthread_attr_getstacksize, LIBPTHREAD); + + ret = pthread_attr_getstacksizep(attr, stacksize); + + AFTER_ORIGINAL_THREAD_RET(VT_INT, ret, thread, THREAD_API_OTHER, + "%p,%p", attr, stacksize); + + return ret; +} + +int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize) +{ + pthread_t thread = 0; + static int (*pthread_attr_setstacksizep)(pthread_attr_t *attr, + size_t stacksize); + + BEFORE_ORIGINAL_THREAD(pthread_attr_setstacksize, LIBPTHREAD); + + ret = pthread_attr_setstacksizep(attr, stacksize); + + AFTER_ORIGINAL_THREAD_RET(VT_INT, ret, thread, THREAD_API_OTHER, + "%p,%u", attr, stacksize); + + return ret; +} + +int pthread_attr_getstackaddr(const pthread_attr_t *attr, void **stackaddr) +{ + pthread_t thread = 0; + static int (*pthread_attr_getstackaddrp)(const pthread_attr_t *attr, + void **stackaddr); + + BEFORE_ORIGINAL_THREAD(pthread_attr_getstackaddr, LIBPTHREAD); + + ret = pthread_attr_getstackaddrp(attr, stackaddr); + + AFTER_ORIGINAL_THREAD_RET(VT_INT, ret, thread, THREAD_API_OTHER, + "%p,%p", attr, stackaddr); + + return ret; +} + +int pthread_attr_setstackaddr(pthread_attr_t *attr, void *stackaddr) +{ + pthread_t thread = 0; + static int (*pthread_attr_setstackaddrp)(pthread_attr_t *attr, + void *stackaddr); + + BEFORE_ORIGINAL_THREAD(pthread_attr_setstackaddr, LIBPTHREAD); + + ret = pthread_attr_setstackaddrp(attr, stackaddr); + + AFTER_ORIGINAL_THREAD_RET(VT_INT, ret, thread, THREAD_API_OTHER, + "%p,%p", attr, stackaddr); + + return ret; +} + +int pthread_attr_getinheritsched(const pthread_attr_t *attr, int *inheritsched) +{ + pthread_t thread = 0; + static int (*pthread_attr_getinheritschedp)(const pthread_attr_t *attr, + int *inheritsched); + + BEFORE_ORIGINAL_THREAD(pthread_attr_getinheritsched, LIBPTHREAD); + + ret = pthread_attr_getinheritschedp(attr, inheritsched); + + AFTER_ORIGINAL_THREAD_RET(VT_INT, ret, thread, THREAD_API_OTHER, + "%p,%p", attr, inheritsched); + + return ret; +} + +int pthread_attr_setinheritsched(pthread_attr_t *attr, int inheritsched) +{ + pthread_t thread = 0; + static int (*pthread_attr_setinheritschedp)(pthread_attr_t *attr, + int inheritsched); + + BEFORE_ORIGINAL_THREAD(pthread_attr_setinheritsched, LIBPTHREAD); + + ret = pthread_attr_setinheritschedp(attr, inheritsched); + + AFTER_ORIGINAL_THREAD_RET(VT_INT, ret, thread, THREAD_API_OTHER, + "%p,%d", attr, inheritsched); + + return ret; +} + +int pthread_attr_getschedparam(const pthread_attr_t *attr, + struct sched_param *param) +{ + pthread_t thread = 0; + static int (*pthread_attr_getschedparamp)(const pthread_attr_t *attr, + struct sched_param *param); + + BEFORE_ORIGINAL_THREAD(pthread_attr_getschedparam, LIBPTHREAD); + + ret = pthread_attr_getschedparamp(attr, param); + + AFTER_ORIGINAL_THREAD_RET(VT_INT, ret, thread, THREAD_API_OTHER, + "%p,%p", attr, param); + + return ret; +} + +int pthread_attr_setschedparam(pthread_attr_t *attr, + const struct sched_param *param) +{ + pthread_t thread = 0; + static int (*pthread_attr_setschedparamp)(pthread_attr_t *attr, + const struct sched_param *param); + + BEFORE_ORIGINAL_THREAD(pthread_attr_setschedparam, LIBPTHREAD); + + ret = pthread_attr_setschedparamp(attr, param); + + AFTER_ORIGINAL_THREAD_RET(VT_INT, ret, thread, THREAD_API_OTHER, + "%p,%p", attr, param); + + return ret; +} + +int pthread_attr_getschedpolicy(const pthread_attr_t *attr, int *policy) +{ + pthread_t thread = 0; + static int (*pthread_attr_getschedpolicyp)(const pthread_attr_t *attr, + int *policy); + + BEFORE_ORIGINAL_THREAD(pthread_attr_getschedpolicy, LIBPTHREAD); + + ret = pthread_attr_getschedpolicyp(attr, policy); + + AFTER_ORIGINAL_THREAD_RET(VT_INT, ret, thread, THREAD_API_OTHER, + "%p,%p", attr, policy); + + return ret; +} + +int pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy) +{ + pthread_t thread = 0; + static int (*pthread_attr_setschedpolicyp)(pthread_attr_t *attr, + int policy); + + BEFORE_ORIGINAL_THREAD(pthread_attr_setschedpolicy, LIBPTHREAD); + + ret = pthread_attr_setschedpolicyp(attr, policy); + + AFTER_ORIGINAL_THREAD_RET(VT_INT, ret, thread, THREAD_API_OTHER, + "%p,%d", attr, policy); + + return ret; +} + +int pthread_attr_getguardsize(const pthread_attr_t *attr, size_t *guardsize) +{ + pthread_t thread = 0; + static int (*pthread_attr_getguardsizep)(const pthread_attr_t *attr, + size_t *guardsize); + + BEFORE_ORIGINAL_THREAD(pthread_attr_getguardsize, LIBPTHREAD); + + ret = pthread_attr_getguardsizep(attr, guardsize); + + AFTER_ORIGINAL_THREAD_RET(VT_INT, ret, thread, THREAD_API_OTHER, + "%p,%p", attr, guardsize); + + return ret; +} + +int pthread_attr_setguardsize(pthread_attr_t *attr, size_t guardsize) +{ + pthread_t thread = 0; + static int (*pthread_attr_setguardsizep)(pthread_attr_t *attr, + size_t guardsize); + + BEFORE_ORIGINAL_THREAD(pthread_attr_setguardsize, LIBPTHREAD); + + ret = pthread_attr_setguardsizep(attr, guardsize); + + AFTER_ORIGINAL_THREAD_RET(VT_INT, ret, thread, THREAD_API_OTHER, + "%p,%u", attr, guardsize); + + return ret; +} + +int pthread_attr_getscope(const pthread_attr_t *attr, int *contentionscope) +{ + pthread_t thread = 0; + static int (*pthread_attr_getscopep)(const pthread_attr_t *attr, + int *contentionscope); + + BEFORE_ORIGINAL_THREAD(pthread_attr_getscope, LIBPTHREAD); + + ret = pthread_attr_getscopep(attr, contentionscope); + + AFTER_ORIGINAL_THREAD_RET(VT_INT, ret, thread, THREAD_API_OTHER, + "%p,%p", attr, contentionscope); + + return ret; +} + +int pthread_attr_setscope(pthread_attr_t *attr, int contentionscope) +{ + pthread_t thread = 0; + static int (*pthread_attr_setscopep)(pthread_attr_t *attr, + int contentionscope); + + BEFORE_ORIGINAL_THREAD(pthread_attr_setscope, LIBPTHREAD); + + ret = pthread_attr_setscopep(attr, contentionscope); + + AFTER_ORIGINAL_THREAD_RET(VT_INT, ret, thread, THREAD_API_OTHER, + "%p,%d", attr, contentionscope); + + return ret; +} + +int pthread_attr_getstack(const pthread_attr_t *attr, + void **stackaddr, size_t *stacksize) +{ + pthread_t thread = 0; + static int (*pthread_attr_getstackp)(const pthread_attr_t *attr, + void **stackaddr, size_t *stacksize); + + BEFORE_ORIGINAL_THREAD(pthread_attr_getstack, LIBPTHREAD); + + ret = pthread_attr_getstackp(attr, stackaddr, stacksize); + + AFTER_ORIGINAL_THREAD_RET(VT_INT, ret, thread, THREAD_API_OTHER, + "%p,%p,%p", attr, stackaddr, stacksize); + + return ret; +} + +int pthread_attr_setstack(pthread_attr_t *attr, + void *stackaddr, size_t stacksize) +{ + pthread_t thread = 0; + static int (*pthread_attr_setstackp)(pthread_attr_t *attr, + void *stackaddr, size_t stacksize); + + BEFORE_ORIGINAL_THREAD(pthread_attr_setstack, LIBPTHREAD); + + ret = pthread_attr_setstackp(attr, stackaddr, stacksize); + + AFTER_ORIGINAL_THREAD_RET(VT_INT, ret, thread, THREAD_API_OTHER, + "%p,%p,%u", attr, stackaddr, stacksize); + + return ret; +} + +/* +void pthread_testcancel(void); + +int pthread_key_create(pthread_key_t *key, void (*destructor)(void*)); +int pthread_key_delete(pthread_key_t key); + +int pthread_getconcurrency(void); +int pthread_setconcurrency(int new_level); +int pthread_getcpuclockid(pthread_t thread_id, clockid_t *clock_id); +int pthread_getschedparam(pthread_t thread, int *policy, + struct sched_param *param); +int pthread_setschedparam(pthread_t thread, int policy, + const struct sched_param *param); +int pthread_setschedprio(pthread_t thread, int prio); +void *pthread_getspecific(pthread_key_t key); +int pthread_setspecific(pthread_key_t key, const void *value); + +int pthread_once(pthread_once_t *once_control, void (*init_routine)(void)); + +int pthread_atfork(void (*prepare)(void), void (*parent)(void), + void (*child)(void)); +*/ + diff --git a/probe_tizenapi/tizen_constructor.cpp b/probe_tizenapi/tizen_constructor.cpp new file mode 100755 index 0000000..abc731e --- /dev/null +++ b/probe_tizenapi/tizen_constructor.cpp @@ -0,0 +1,1164 @@ +/* + * DA probe + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Jaewon Lim + * Woojin Jung + * Juyoung Kim + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#include "daprobe.h" +#include "dahelper.h" +#include "dacollection.h" +#include "tizen_probe.h" + +namespace Tizen { namespace Ui { + +class Control +{ + Control(void); + ~Control(void); +}; + +class CustomControlBase +{ + CustomControlBase(void); +}; + +class Container +{ + Container(void); +}; + +class Window +{ + Window(void); +}; + +Control::Control(void) +{ + typedef void (Control::*methodType)(void); + static methodType control_controlp; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui7ControlC2Ev, LIBOSP_UIFW, control_controlp); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "Control"); + probeBlockEnd(); + + (this->*control_controlp)(); +} + +Control::~Control(void) +{ + typedef void (Control::*methodType)(void); + static methodType control__controlvoidp; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui7ControlD2Ev, LIBOSP_UIFW, control__controlvoidp); + + probeBlockStart(); + del_uiobject_hash(static_cast(this)); + probeBlockEnd(); + + (this->*control__controlvoidp)(); +} + +CustomControlBase::CustomControlBase(void) +{ + typedef void (CustomControlBase::*methodType)(void); + static methodType customcontrolbase_customcontrolbasep; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui17CustomControlBaseC2Ev, LIBOSP_UIFW, customcontrolbase_customcontrolbasep); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "CustomControlBase"); + probeBlockEnd(); + + (this->*customcontrolbase_customcontrolbasep)(); +} + +Container::Container(void) +{ + typedef void (Container::*methodType)(void); + static methodType container_containerp; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui9ContainerC2Ev, LIBOSP_UIFW, container_containerp); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "Container"); + probeBlockEnd(); + + (this->*container_containerp)(); +} + +Window::Window(void) +{ + typedef void (Window::*methodType)(void); + static methodType window_windowp; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui6WindowC2Ev, LIBOSP_UIFW, window_windowp); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "Window"); + probeBlockEnd(); + + (this->*window_windowp)(); +} + +namespace Controls { + +class Animation +{ + Animation(void); +}; + +class Button +{ + Button(void); +}; + +class CheckButton +{ + CheckButton(void); +}; + +class ColorPicker +{ + ColorPicker(void); +}; + +class CustomList +{ + CustomList(void); +}; + +class EditArea +{ + EditArea(void); +}; + +class EditDate +{ + EditDate(void); +}; + +class EditField +{ + EditField(void); +}; + +class EditTime +{ + EditTime(void); +}; + +class ExpandableEditArea +{ + ExpandableEditArea(void); +}; + +class ExpandableList +{ + ExpandableList(void); +}; + +class Footer +{ + Footer(void); +}; + +class Gallery +{ + Gallery(void); +}; + +class GroupedList +{ + GroupedList(void); +}; + +class GroupedListView +{ + GroupedListView(void); +}; + +class Header +{ + Header(void); +}; + +class IconList +{ + IconList(void); +}; + +class IconListView +{ + IconListView(void); +}; + +class Label +{ + Label(void); +}; + +class List +{ + List(void); +}; + +class ListView +{ + ListView(void); +}; + +class Progress +{ + Progress(void); +}; + +class RadioGroup +{ + RadioGroup(void); +}; + +class SearchBar +{ + SearchBar(void); +}; + +class SlidableGroupedList +{ + SlidableGroupedList(void); +}; + +class SlidableList +{ + SlidableList(void); +}; + +class Slider +{ + Slider(void); +}; + +class SplitPanel +{ + SplitPanel(void); +}; + +class Tab +{ + Tab(void); +}; + +class TabBar +{ + TabBar(void); +}; + +class TextBox +{ + TextBox(void); +}; + +class Form +{ + Form(void); +}; + +class GroupedTableView +{ + GroupedTableView(void); +}; + +class Panel +{ + Panel(void); +}; + +class OverlayPanel +{ + OverlayPanel(void); +}; + +class ScrollPanel +{ + ScrollPanel(void); +}; + +class SectionTableView +{ + SectionTableView(void); +}; + +class TableView +{ + TableView(void); +}; + +class TableViewItemBase +{ + TableViewItemBase(void); +}; + +class TableViewContextItem +{ + TableViewContextItem(void); +}; + +class TableViewGroupItem +{ + TableViewGroupItem(void); +}; + +class TableViewItem +{ + TableViewItem(void); +}; + +class TableViewSimpleGroupItem +{ + TableViewSimpleGroupItem(void); +}; + +class TableViewSimpleItem +{ + TableViewSimpleItem(void); +}; + +class ContextMenu +{ + ContextMenu(void); +}; + +class DatePicker +{ + DatePicker(void); +}; + +class DateTimePicker +{ + DateTimePicker(void); +}; + +class Frame +{ + Frame(void); +}; + +class Keypad +{ + Keypad(void); +}; + +class MessageBox +{ + MessageBox(void); +}; + +class OptionMenu +{ + OptionMenu(void); +}; + +class Popup +{ + Popup(void); +}; + +class TimePicker +{ + TimePicker(void); +}; + +Animation::Animation(void) +{ + typedef void (Animation::*methodType)(void); + static methodType animation_animationp; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui8Controls9AnimationC2Ev, LIBOSP_UIFW, animation_animationp); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "Animation"); + probeBlockEnd(); + + (this->*animation_animationp)(); +} + +Button::Button(void) +{ + typedef void (Button::*methodType)(void); + static methodType button_buttonp; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui8Controls6ButtonC2Ev, LIBOSP_UIFW, button_buttonp); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "Button"); + probeBlockEnd(); + + (this->*button_buttonp)(); +} + +CheckButton::CheckButton(void) +{ + typedef void (CheckButton::*methodType)(void); + static methodType checkbutton_checkbuttonp; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui8Controls11CheckButtonC2Ev, LIBOSP_UIFW, checkbutton_checkbuttonp); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "CheckButton"); + probeBlockEnd(); + + (this->*checkbutton_checkbuttonp)(); +} + +ColorPicker::ColorPicker(void) +{ + typedef void (ColorPicker::*methodType)(void); + static methodType colorpicker_colorpickerp; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui8Controls11ColorPickerC2Ev, LIBOSP_UIFW, colorpicker_colorpickerp); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "ColorPicker"); + probeBlockEnd(); + + (this->*colorpicker_colorpickerp)(); +} + +CustomList::CustomList(void) +{ + typedef void (CustomList::*methodType)(void); + static methodType customlist_customlistp; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui8Controls10CustomListC2Ev, LIBOSP_UIFW, customlist_customlistp); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "CustomList"); + probeBlockEnd(); + + (this->*customlist_customlistp)(); +} + +EditArea::EditArea(void) +{ + typedef void (EditArea::*methodType)(void); + static methodType editarea_editareap; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui8Controls8EditAreaC2Ev, LIBOSP_UIFW, editarea_editareap); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "EditArea"); + probeBlockEnd(); + + (this->*editarea_editareap)(); +} + +EditDate::EditDate(void) +{ + typedef void (EditDate::*methodType)(void); + static methodType editdate_editdatep; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui8Controls8EditDateC2Ev, LIBOSP_UIFW, editdate_editdatep); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "EditDate"); + probeBlockEnd(); + + (this->*editdate_editdatep)(); +} + +EditField::EditField(void) +{ + typedef void (EditField::*methodType)(void); + static methodType editfield_editfieldp; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui8Controls9EditFieldC2Ev, LIBOSP_UIFW, editfield_editfieldp); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "EditField"); + probeBlockEnd(); + + (this->*editfield_editfieldp)(); +} + +EditTime::EditTime(void) +{ + typedef void (EditTime::*methodType)(void); + static methodType edittime_edittimep; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui8Controls8EditTimeC2Ev, LIBOSP_UIFW, edittime_edittimep); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "EditTime"); + probeBlockEnd(); + + (this->*edittime_edittimep)(); +} + +ExpandableEditArea::ExpandableEditArea(void) +{ + typedef void (ExpandableEditArea::*methodType)(void); + static methodType expandableeditarea_expandableeditareap; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui8Controls18ExpandableEditAreaC2Ev, LIBOSP_UIFW, expandableeditarea_expandableeditareap); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "ExpandableEditArea"); + probeBlockEnd(); + + (this->*expandableeditarea_expandableeditareap)(); +} + +ExpandableList::ExpandableList(void) +{ + typedef void (ExpandableList::*methodType)(void); + static methodType expandablelist_expandablelistp; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui8Controls14ExpandableListC2Ev, LIBOSP_UIFW, expandablelist_expandablelistp); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "ExpandableList"); + probeBlockEnd(); + + (this->*expandablelist_expandablelistp)(); +} + +Footer::Footer(void) +{ + typedef void (Footer::*methodType)(void); + static methodType footer_footerp; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui8Controls6FooterC2Ev, LIBOSP_UIFW, footer_footerp); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "Footer"); + probeBlockEnd(); + + (this->*footer_footerp)(); +} + +Gallery::Gallery(void) +{ + typedef void (Gallery::*methodType)(void); + static methodType gallery_galleryp; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui8Controls7GalleryC2Ev, LIBOSP_UIFW, gallery_galleryp); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "Gallery"); + probeBlockEnd(); + + (this->*gallery_galleryp)(); +} + +GroupedList::GroupedList(void) +{ + typedef void (GroupedList::*methodType)(void); + static methodType groupedlist_groupedlistp; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui8Controls11GroupedListC2Ev, LIBOSP_UIFW, groupedlist_groupedlistp); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "GroupedList"); + probeBlockEnd(); + + (this->*groupedlist_groupedlistp)(); +} + +GroupedListView::GroupedListView(void) +{ + typedef void (GroupedListView::*methodType)(void); + static methodType groupedlistview_groupedlistviewp; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui8Controls15GroupedListViewC2Ev, LIBOSP_UIFW, groupedlistview_groupedlistviewp); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "GroupedListView"); + probeBlockEnd(); + + (this->*groupedlistview_groupedlistviewp)(); +} + +Header::Header(void) +{ + typedef void (Header::*methodType)(void); + static methodType header_headerp; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui8Controls6HeaderC2Ev, LIBOSP_UIFW, header_headerp); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "Header"); + probeBlockEnd(); + + (this->*header_headerp)(); +} + +IconList::IconList(void) +{ + typedef void (IconList::*methodType)(void); + static methodType iconlist_iconlistp; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui8Controls8IconListC2Ev, LIBOSP_UIFW, iconlist_iconlistp); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "IconList"); + probeBlockEnd(); + + (this->*iconlist_iconlistp)(); +} + +IconListView::IconListView(void) +{ + typedef void (IconListView::*methodType)(void); + static methodType iconlistview_iconlistviewp; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui8Controls12IconListViewC2Ev, LIBOSP_UIFW, iconlistview_iconlistviewp); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "IconListView"); + probeBlockEnd(); + + (this->*iconlistview_iconlistviewp)(); +} + +Label::Label(void) +{ + typedef void (Label::*methodType)(void); + static methodType label_labelp; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui8Controls5LabelC2Ev, LIBOSP_UIFW, label_labelp); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "Label"); + probeBlockEnd(); + + (this->*label_labelp)(); +} + +List::List(void) +{ + typedef void (List::*methodType)(void); + static methodType list_listp; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui8Controls4ListC2Ev, LIBOSP_UIFW, list_listp); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "List"); + probeBlockEnd(); + + (this->*list_listp)(); +} + +ListView::ListView(void) +{ + typedef void (ListView::*methodType)(void); + static methodType listview_listviewp; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui8Controls8ListViewC2Ev, LIBOSP_UIFW, listview_listviewp); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "ListView"); + probeBlockEnd(); + + (this->*listview_listviewp)(); +} + +Progress::Progress(void) +{ + typedef void (Progress::*methodType)(void); + static methodType progress_progressp; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui8Controls8ProgressC2Ev, LIBOSP_UIFW, progress_progressp); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "Progress"); + probeBlockEnd(); + + (this->*progress_progressp)(); +} + +RadioGroup::RadioGroup(void) +{ + typedef void (RadioGroup::*methodType)(void); + static methodType radiogroup_radiogroupp; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui8Controls10RadioGroupC2Ev, LIBOSP_UIFW, radiogroup_radiogroupp); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "RadioGroup"); + probeBlockEnd(); + + (this->*radiogroup_radiogroupp)(); +} + +SearchBar::SearchBar(void) +{ + typedef void (SearchBar::*methodType)(void); + static methodType searchbar_searchbarp; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui8Controls9SearchBarC2Ev, LIBOSP_UIFW, searchbar_searchbarp); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "SearchBar"); + probeBlockEnd(); + + (this->*searchbar_searchbarp)(); +} + +SlidableGroupedList::SlidableGroupedList(void) +{ + typedef void (SlidableGroupedList::*methodType)(void); + static methodType slidablegroupedlist_slidablegroupedlistp; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui8Controls19SlidableGroupedListC2Ev, LIBOSP_UIFW, slidablegroupedlist_slidablegroupedlistp); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "SlidableGroupedList"); + probeBlockEnd(); + + (this->*slidablegroupedlist_slidablegroupedlistp)(); +} + +SlidableList::SlidableList(void) +{ + typedef void (SlidableList::*methodType)(void); + static methodType slidablelist_slidablelistp; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui8Controls12SlidableListC2Ev, LIBOSP_UIFW, slidablelist_slidablelistp); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "SlidableList"); + probeBlockEnd(); + + (this->*slidablelist_slidablelistp)(); +} + +Slider::Slider(void) +{ + typedef void (Slider::*methodType)(void); + static methodType slider_sliderp; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui8Controls6SliderC2Ev, LIBOSP_UIFW, slider_sliderp); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "Slider"); + probeBlockEnd(); + + (this->*slider_sliderp)(); +} + +SplitPanel::SplitPanel(void) +{ + typedef void (SplitPanel::*methodType)(void); + static methodType splitpanel_splitpanelp; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui8Controls10SplitPanelC2Ev, LIBOSP_UIFW, splitpanel_splitpanelp); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "SplitPanel"); + probeBlockEnd(); + + (this->*splitpanel_splitpanelp)(); +} + +Tab::Tab(void) +{ + typedef void (Tab::*methodType)(void); + static methodType tab_tabp; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui8Controls3TabC2Ev, LIBOSP_UIFW, tab_tabp); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "Tab"); + probeBlockEnd(); + + (this->*tab_tabp)(); +} + +TabBar::TabBar(void) +{ + typedef void (TabBar::*methodType)(void); + static methodType tabbar_tabbarp; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui8Controls6TabBarC2Ev, LIBOSP_UIFW, tabbar_tabbarp); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "TabBar"); + probeBlockEnd(); + + (this->*tabbar_tabbarp)(); +} + +TextBox::TextBox(void) +{ + typedef void (TextBox::*methodType)(void); + static methodType textbox_textboxp; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui8Controls7TextBoxC2Ev, LIBOSP_UIFW, textbox_textboxp); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "TextBox"); + probeBlockEnd(); + + (this->*textbox_textboxp)(); +} + +Form::Form(void) +{ + typedef void (Form::*methodType)(void); + static methodType form_formp; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui8Controls4FormC2Ev, LIBOSP_UIFW, form_formp); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "Form"); + probeBlockEnd(); + + (this->*form_formp)(); +} + +GroupedTableView::GroupedTableView(void) +{ + typedef void (GroupedTableView::*methodType)(void); + static methodType groupedtableview_groupedtableviewp; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui8Controls16GroupedTableViewC2Ev, LIBOSP_UIFW, groupedtableview_groupedtableviewp); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "GroupedTableView"); + probeBlockEnd(); + + (this->*groupedtableview_groupedtableviewp)(); +} + +Panel::Panel(void) +{ + typedef void (Panel::*methodType)(void); + static methodType panel_panelp; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui8Controls5PanelC2Ev, LIBOSP_UIFW, panel_panelp); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "Panel"); + probeBlockEnd(); + + (this->*panel_panelp)(); +} + +OverlayPanel::OverlayPanel(void) +{ + typedef void (OverlayPanel::*methodType)(void); + static methodType overlaypanel_overlaypanelp; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui8Controls12OverlayPanelC2Ev, LIBOSP_UIFW, overlaypanel_overlaypanelp); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "OverlayPanel"); + probeBlockEnd(); + + (this->*overlaypanel_overlaypanelp)(); +} + +ScrollPanel::ScrollPanel(void) +{ + typedef void (ScrollPanel::*methodType)(void); + static methodType scrollpanel_scrollpanelp; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui8Controls11ScrollPanelC2Ev, LIBOSP_UIFW, scrollpanel_scrollpanelp); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "ScrollPanel"); + probeBlockEnd(); + + (this->*scrollpanel_scrollpanelp)(); +} + +SectionTableView::SectionTableView(void) +{ + typedef void (SectionTableView::*methodType)(void); + static methodType sectiontableview_sectiontableviewp; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui8Controls16SectionTableViewC2Ev, LIBOSP_UIFW, sectiontableview_sectiontableviewp); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "SectionTableView"); + probeBlockEnd(); + + (this->*sectiontableview_sectiontableviewp)(); +} + +TableView::TableView(void) +{ + typedef void (TableView::*methodType)(void); + static methodType tableview_tableviewp; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui8Controls9TableViewC2Ev, LIBOSP_UIFW, tableview_tableviewp); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "TableView"); + probeBlockEnd(); + + (this->*tableview_tableviewp)(); +} + +TableViewItemBase::TableViewItemBase(void) +{ + typedef void (TableViewItemBase::*methodType)(void); + static methodType tableviewitembase_tableviewitembasep; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui8Controls17TableViewItemBaseC2Ev, LIBOSP_UIFW, tableviewitembase_tableviewitembasep); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "TableViewItemBase"); + probeBlockEnd(); + + (this->*tableviewitembase_tableviewitembasep)(); +} + +TableViewContextItem::TableViewContextItem(void) +{ + typedef void (TableViewContextItem::*methodType)(void); + static methodType tableviewcontextitem_tableviewcontextitemp; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui8Controls20TableViewContextItemC2Ev, LIBOSP_UIFW, tableviewcontextitem_tableviewcontextitemp); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "TableViewContextItem"); + probeBlockEnd(); + + (this->*tableviewcontextitem_tableviewcontextitemp)(); +} + +TableViewGroupItem::TableViewGroupItem(void) +{ + typedef void (TableViewGroupItem::*methodType)(void); + static methodType tableviewgroupitem_tableviewgroupitemp; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui8Controls18TableViewGroupItemC2Ev, LIBOSP_UIFW, tableviewgroupitem_tableviewgroupitemp); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "TableViewGroupItem"); + probeBlockEnd(); + + (this->*tableviewgroupitem_tableviewgroupitemp)(); +} + +TableViewItem::TableViewItem(void) +{ + typedef void (TableViewItem::*methodType)(void); + static methodType tableviewitem_tableviewitemp; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui8Controls13TableViewItemC2Ev, LIBOSP_UIFW, tableviewitem_tableviewitemp); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "TableViewItem"); + probeBlockEnd(); + + (this->*tableviewitem_tableviewitemp)(); +} + +TableViewSimpleGroupItem::TableViewSimpleGroupItem(void) +{ + typedef void (TableViewSimpleGroupItem::*methodType)(void); + static methodType tableviewsimplegroupitem_tableviewsimplegroupitemp; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui8Controls24TableViewSimpleGroupItemC2Ev, LIBOSP_UIFW, tableviewsimplegroupitem_tableviewsimplegroupitemp); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "TableViewSimpleGroupItem"); + probeBlockEnd(); + + (this->*tableviewsimplegroupitem_tableviewsimplegroupitemp)(); +} + +TableViewSimpleItem::TableViewSimpleItem(void) +{ + typedef void (TableViewSimpleItem::*methodType)(void); + static methodType tableviewsimpleitem_tableviewsimpleitemp; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui8Controls19TableViewSimpleItemC2Ev, LIBOSP_UIFW, tableviewsimpleitem_tableviewsimpleitemp); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "TableViewSimpleItem"); + probeBlockEnd(); + + (this->*tableviewsimpleitem_tableviewsimpleitemp)(); +} + +ContextMenu::ContextMenu(void) +{ + typedef void (ContextMenu::*methodType)(void); + static methodType contextmenu_contextmenup; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui8Controls11ContextMenuC2Ev, LIBOSP_UIFW, contextmenu_contextmenup); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "ContextMenu"); + probeBlockEnd(); + + (this->*contextmenu_contextmenup)(); +} + +DatePicker::DatePicker(void) +{ + typedef void (DatePicker::*methodType)(void); + static methodType datepicker_datepickerp; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui8Controls10DatePickerC2Ev, LIBOSP_UIFW, datepicker_datepickerp); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "DatePicker"); + probeBlockEnd(); + + (this->*datepicker_datepickerp)(); +} + +DateTimePicker::DateTimePicker(void) +{ + typedef void (DateTimePicker::*methodType)(void); + static methodType datetimepicker_datetimepickerp; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui8Controls14DateTimePickerC2Ev, LIBOSP_UIFW, datetimepicker_datetimepickerp); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "DateTimePicker"); + probeBlockEnd(); + + (this->*datetimepicker_datetimepickerp)(); +} + +Frame::Frame(void) +{ + typedef void (Frame::*methodType)(void); + static methodType frame_framep; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui8Controls5FrameC2Ev, LIBOSP_UIFW, frame_framep); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "Frame"); + probeBlockEnd(); + + (this->*frame_framep)(); +} + +Keypad::Keypad(void) +{ + typedef void (Keypad::*methodType)(void); + static methodType keypad_keypadp; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui8Controls6KeypadC2Ev, LIBOSP_UIFW, keypad_keypadp); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "Keypad"); + probeBlockEnd(); + + (this->*keypad_keypadp)(); +} + +MessageBox::MessageBox(void) +{ + typedef void (MessageBox::*methodType)(void); + static methodType messagebox_messageboxp; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui8Controls10MessageBoxC2Ev, LIBOSP_UIFW, messagebox_messageboxp); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "MessageBox"); + probeBlockEnd(); + + (this->*messagebox_messageboxp)(); +} + +OptionMenu::OptionMenu(void) +{ + typedef void (OptionMenu::*methodType)(void); + static methodType optionmenu_optionmenup; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui8Controls10OptionMenuC2Ev, LIBOSP_UIFW, optionmenu_optionmenup); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "OptionMenu"); + probeBlockEnd(); + + (this->*optionmenu_optionmenup)(); +} + +Popup::Popup(void) +{ + typedef void (Popup::*methodType)(void); + static methodType popup_popupp; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui8Controls5PopupC2Ev, LIBOSP_UIFW, popup_popupp); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "Popup"); + probeBlockEnd(); + + (this->*popup_popupp)(); +} + +TimePicker::TimePicker(void) +{ + typedef void (TimePicker::*methodType)(void); + static methodType timepicker_timepickerp; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui8Controls10TimePickerC2Ev, LIBOSP_UIFW, timepicker_timepickerp); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "TimePicker"); + probeBlockEnd(); + + (this->*timepicker_timepickerp)(); +} + +} // end of namespace Tizen::Ui::Controls + +} } // end of namespace Tizen::Ui + + +namespace Tizen { namespace Web { namespace Controls { + +class Web +{ + Web(void); +}; + +Web::Web(void) +{ + typedef void (Web::*methodType)(void); + static methodType web_webp; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen3Web8Controls3WebC2Ev, LIBOSP_WEB, web_webp); + + probeBlockStart(); + add_uiobject_hash_type((void*)this, "Web"); + probeBlockEnd(); + + (this->*web_webp)(); +} + +} } } // end of namespace Tizen::Web::Controls diff --git a/probe_tizenapi/tizen_controls.cpp b/probe_tizenapi/tizen_controls.cpp new file mode 100755 index 0000000..ee5863d --- /dev/null +++ b/probe_tizenapi/tizen_controls.cpp @@ -0,0 +1,469 @@ +/* + * DA probe + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Jaewon Lim + * Woojin Jung + * Juyoung Kim + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#include +#include +#include + +#include "daprobe.h" +#include "dacollection.h" +#include "dahelper.h" +#include "tizen_probe.h" + +using namespace Tizen::Ui; +using namespace Tizen::Ui::Controls; +using namespace Tizen::Ui::Animations; + +#define APPEND_LOG_CONTROL_TIZEN(CONTROL) \ + do { \ + if(unlikely(CONTROL == NULL)) { \ + log.length += sprintf(log.data + log.length, "`,`,`,"); \ + } else { \ + char *type = NULL, *name = NULL; \ + if(find_uiobject_hash((void*)(CONTROL), &type, &name) == 1) { \ + log.length += sprintf(log.data + log.length, "`,%s`,%s", type, name); \ + } else { \ + log.length += sprintf(log.data + log.length, "`,`,"); \ + } \ + log.length += sprintf(log.data + log.length, "`,%p", \ + (void*)(CONTROL)); \ + } \ + } while(0) + +extern IFrameAnimatorEventListener& GetFrameAnimatorEventListener(); + +bool IsRegisteredFrameAnimatorEventListener = false; + +namespace Tizen { namespace App { + +result UiApp::AddFrame(const Tizen::Ui::Controls::Frame& frame) +{ + typedef result (UiApp::*methodType)(const Tizen::Ui::Controls::Frame& frame); + static methodType uiapp_addframep; + DECLARE_COMMON_VARIABLE; + result ret; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen3App5UiApp8AddFrameERKNS_2Ui8Controls5FrameE, LIBOSP_UIFW, uiapp_addframep); + + ret = (this->*uiapp_addframep)(frame); + + probeBlockStart(); + if(ret == E_SUCCESS) + { + frame.IsInTouchMode(); + + if(isOptionEnabled(OPT_UI)) + { + Control* parent = NULL; + setProbePoint(&probeInfo); + INIT_LOG; + APPEND_LOG_BASIC_NAME(LC_UICREATE, "AddFrame"); + APPEND_LOG_COMMON_NONE(CALLER_ADDRESS); + APPEND_LOG_CONTROL_TIZEN(parent); + APPEND_LOG_CONTROL_TIZEN(&frame); + printLog(&log, MSG_LOG); + } + } + probeBlockEnd(); + + return ret; +} + +result UiApp::RemoveFrame(const Tizen::Ui::Controls::Frame &frame) +{ + typedef result (UiApp::*methodType)(const Tizen::Ui::Controls::Frame& frame); + static methodType uiapp_removeframep; + DECLARE_COMMON_VARIABLE; + result ret; + bool bOption; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen3App5UiApp11RemoveFrameERKNS_2Ui8Controls5FrameE, LIBOSP_UIFW, uiapp_removeframep); + + probeBlockStart(); + frame.IsInTouchMode(); + + if((bOption = isOptionEnabled(OPT_UI))) + { + Control* parent = NULL; + setProbePoint(&probeInfo); + INIT_LOG; + APPEND_LOG_BASIC_NAME(LC_UICREATE, "RemoveFrame"); + APPEND_LOG_COMMON_NONE(CALLER_ADDRESS); + APPEND_LOG_CONTROL_TIZEN(parent); + APPEND_LOG_CONTROL_TIZEN(&frame); + } + probeBlockEnd(); + + ret = (this->*uiapp_removeframep)(frame); + + probeBlockStart(); + if(ret == E_SUCCESS) + { + if(bOption) + printLog(&log, MSG_LOG); + } + probeBlockEnd(); + + return ret; +} + +} } // end of namespce Tizen::App + + +namespace Tizen { namespace Ui { + +bool Control::IsInTouchMode(void) const +{ + typedef bool (Control::*methodType)(void) const; + static methodType control_isintouchmodep; + + GET_REAL_FUNC_TIZEN(_ZNK5Tizen2Ui7Control13IsInTouchModeEv, LIBOSP_UIFW, control_isintouchmodep); + + probeBlockStart(); + add_uiobject_hash_class((void*)(this), typeid(*this).name()); + probeBlockEnd(); + + return (this->*control_isintouchmodep)(); +} + +void Control::SetName(const Tizen::Base::String &name) +{ + typedef void (Control::*methodType)(const Tizen::Base::String &name); + static methodType control_setnamep; + DECLARE_COMMON_VARIABLE; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui7Control7SetNameERKNS_4Base6StringE, LIBOSP_UIFW, control_setnamep); + + (this->*control_setnamep)(name); + + probeBlockStart(); + IsInTouchMode(); + + if(isOptionEnabled(OPT_UI)) + { + Control* parent = NULL; + setProbePoint(&probeInfo); + INIT_LOG; + APPEND_LOG_BASIC_NAME(LC_UICREATE, "SetName"); + APPEND_LOG_COMMON_NONE(CALLER_ADDRESS); + APPEND_LOG_CONTROL_TIZEN(this); + APPEND_LOG_CONTROL_TIZEN(parent); + printLog(&log, MSG_LOG); + } + probeBlockEnd(); +} + +result Container::AddControl(const Control &control) +{ + typedef result (Container::*methodType)(const Control &control); + static methodType container_addcontrolp; + DECLARE_COMMON_VARIABLE; + int blockresult; + bool bfiltering = false; + result ret; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui9Container10AddControlERKNS0_7ControlE, LIBOSP_UIFW, container_addcontrolp); + + if((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, OPT_ALWAYSON)) != 0) + { + if(unlikely(IsRegisteredFrameAnimatorEventListener == false)) + { + char *type = NULL, *classname = NULL; + if(likely(find_uiobject_hash((void*)this, &type, &classname) == 1)) // there is entry in object hash + { + if(strcmp(type, "Frame") == 0) + { + FrameAnimator* fa = ((Frame*)this)->GetFrameAnimator(); + if(fa != NULL) + { + fa->AddFrameAnimatorEventListener(GetFrameAnimatorEventListener()); + IsRegisteredFrameAnimatorEventListener = true; + } + else // frame is not yet constructed + { + } + } + } + } + preBlockEnd(); + } + + ret = (this->*container_addcontrolp)(control); + + if(postBlockBegin(blockresult)) + { + if(ret == E_SUCCESS) + { + IsInTouchMode(); + control.IsInTouchMode(); + + if(isOptionEnabled(OPT_UI)) + { + setProbePoint(&probeInfo); + INIT_LOG; + APPEND_LOG_BASIC_NAME(LC_UICREATE, "AddControl"); + APPEND_LOG_COMMON_NONE(CALLER_ADDRESS); + APPEND_LOG_CONTROL_TIZEN(this); + APPEND_LOG_CONTROL_TIZEN(&control); + printLog(&log, MSG_LOG); + } + } + postBlockEnd(); + } + + return ret; +} + +result Container::AddControl(Control* control) +{ + typedef result (Container::*methodType)(Control* control); + static methodType container_addcontrolp; + DECLARE_COMMON_VARIABLE; + int blockresult; + bool bfiltering = false; + result ret; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui9Container10AddControlEPNS0_7ControlE, LIBOSP_UIFW, container_addcontrolp); + + if((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, OPT_ALWAYSON)) != 0) + { + if(unlikely(IsRegisteredFrameAnimatorEventListener == false)) + { + char *type = NULL, *classname = NULL; + if(likely(find_uiobject_hash((void*)this, &type, &classname) == 1)) // there is entry in object hash + { + if(strcmp(type, "Frame") == 0) + { + FrameAnimator* fa = ((Frame*)this)->GetFrameAnimator(); + if(fa != NULL) + { + fa->AddFrameAnimatorEventListener(GetFrameAnimatorEventListener()); + IsRegisteredFrameAnimatorEventListener = true; + } + else // frame is not yet constructed + { + } + } + } + } + preBlockEnd(); + } + + ret = (this->*container_addcontrolp)(control); + + if(postBlockBegin(blockresult)) + { + if(ret == E_SUCCESS) + { + IsInTouchMode(); + control->IsInTouchMode(); + + if(isOptionEnabled(OPT_UI)) + { + setProbePoint(&probeInfo); + INIT_LOG; + APPEND_LOG_BASIC_NAME(LC_UICREATE, "AddControl"); + APPEND_LOG_COMMON_NONE(CALLER_ADDRESS); + APPEND_LOG_CONTROL_TIZEN(this); + APPEND_LOG_CONTROL_TIZEN(control); + printLog(&log, MSG_LOG); + } + } + postBlockEnd(); + } + + return ret; +} + +result Container::RemoveControl(const Control &control) +{ + typedef result (Container::*methodType)(const Control &control); + static methodType container_removecontrolp; + DECLARE_COMMON_VARIABLE; + int blockresult; + bool bfiltering = false; + result ret; + bool bOption; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui9Container13RemoveControlERKNS0_7ControlE, LIBOSP_UIFW, container_removecontrolp); + + if((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, OPT_ALWAYSON)) != 0) + { + control.IsInTouchMode(); + + if((bOption = isOptionEnabled(OPT_UI))) + { + setProbePoint(&probeInfo); + INIT_LOG; + APPEND_LOG_BASIC_NAME(LC_UICREATE, "RemoveControl"); + APPEND_LOG_COMMON_NONE(CALLER_ADDRESS); + APPEND_LOG_CONTROL_TIZEN(this); + APPEND_LOG_CONTROL_TIZEN(&control); + } + preBlockEnd(); + } + + ret = (this->*container_removecontrolp)(control); + + if(postBlockBegin(blockresult)) + { + if(ret == E_SUCCESS) + { + if(bOption) + printLog(&log, MSG_LOG); + } + postBlockEnd(); + } + + return ret; +} + +result Container::RemoveControl(Control* control) +{ + typedef result (Container::*methodType)(Control* control); + static methodType container_removecontrolp; + DECLARE_COMMON_VARIABLE; + int blockresult; + bool bfiltering = false; + result ret; + bool bOption; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui9Container13RemoveControlEPNS0_7ControlE, LIBOSP_UIFW, container_removecontrolp); + + if((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, OPT_ALWAYSON)) != 0) + { + control->IsInTouchMode(); + + if((bOption = isOptionEnabled(OPT_UI))) + { + setProbePoint(&probeInfo); + INIT_LOG; + APPEND_LOG_BASIC_NAME(LC_UICREATE, "RemoveControl"); + APPEND_LOG_COMMON_NONE(CALLER_ADDRESS); + APPEND_LOG_CONTROL_TIZEN(this); + APPEND_LOG_CONTROL_TIZEN(control); + } + preBlockEnd(); + } + + ret = (this->*container_removecontrolp)(control); + + if(postBlockBegin(blockresult)) + { + if(ret == E_SUCCESS) + { + if(bOption) + printLog(&log, MSG_LOG); + } + postBlockEnd(); + } + + return ret; +} + +result Container::RemoveControl(int index) +{ + typedef result (Container::*methodType)(int index); + static methodType container_removecontrolip; + DECLARE_COMMON_VARIABLE; + int blockresult; + bool bfiltering = false; + result ret; + bool bOption; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui9Container13RemoveControlEi, LIBOSP_UIFW, container_removecontrolip); + + if((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, OPT_ALWAYSON)) != 0) + { + Control* pcontrol = GetControl(index); + pcontrol->IsInTouchMode(); + + if((bOption = isOptionEnabled(OPT_UI))) + { + setProbePoint(&probeInfo); + INIT_LOG; + APPEND_LOG_BASIC_NAME(LC_UICREATE, "RemoveControl"); + APPEND_LOG_COMMON_NONE(CALLER_ADDRESS); + APPEND_LOG_CONTROL_TIZEN(this); + APPEND_LOG_CONTROL_TIZEN(pcontrol); + } + preBlockEnd(); + } + + ret = (this->*container_removecontrolip)(index); + + if(postBlockBegin(blockresult)) + { + if(ret == E_SUCCESS) + { + if(bOption) + printLog(&log, MSG_LOG); + } + postBlockEnd(); + } + + return ret; +} + +void Container::RemoveAllControls(void) +{ + typedef void (Container::*methodType)(void); + static methodType container_removeallcontrolp; + DECLARE_COMMON_VARIABLE; + int blockresult; + bool bfiltering = false; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui9Container17RemoveAllControlsEv, LIBOSP_UIFW, container_removeallcontrolp); + + if((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, OPT_ALWAYSON)) != 0) + { + if(isOptionEnabled(OPT_UI)) + { + Control* pcontrol = NULL; + setProbePoint(&probeInfo); + INIT_LOG; + APPEND_LOG_BASIC_NAME(LC_UICREATE, "RemoveAllControl"); + APPEND_LOG_COMMON_NONE(CALLER_ADDRESS); + APPEND_LOG_CONTROL_TIZEN(this); + APPEND_LOG_CONTROL_TIZEN(pcontrol); + printLog(&log, MSG_LOG); + } + preBlockEnd(); + } + + (this->*container_removeallcontrolp)(); + + if(postBlockBegin(blockresult)) + { + postBlockEnd(); + } +} + +} } // end of namespace Tizen::Ui diff --git a/probe_tizenapi/tizen_file.cpp b/probe_tizenapi/tizen_file.cpp new file mode 100755 index 0000000..1ab43d5 --- /dev/null +++ b/probe_tizenapi/tizen_file.cpp @@ -0,0 +1,1383 @@ +/* + * DA probe + * + * Copyright (File::*c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Jaewon Lim + * Woojin Jung + * Juyoung Kim + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#include +#include "daprobe.h" +#include "probeinfo.h" +#include "dahelper.h" +#include "dacollection.h" + +static enum DaOptions _sopt = OPT_FILE; + +namespace Tizen { +namespace Io { + +result File::Construct(const Tizen::Base::String& filePath, + const Tizen::Base::String& openMode, bool createParentDirectories) { + typedef result (File::*methodType)(const Tizen::Base::String& filePath, + const Tizen::Base::String& openMode, bool createParentDirectories); + static methodType Constructp = 0; + result ret; + probeInfo_t probeInfo; + log_t log; + int blockresult; + bool bfiltering = true; + char temp[PATH_MAX]; + FileAttributes attr; + long long size = 0L; + + if (!Constructp) { + probeBlockStart(); + void *tmpPtr = dlsym(RTLD_NEXT, + "_ZN5Tizen2Io4File9ConstructERKNS_4Base6StringES5_b"); + + if (tmpPtr == NULL || dlerror() != NULL) { + perror("dlsym failed : Tizen::Io::File::Construct"); + exit(0); + } + + memcpy(&Constructp, &tmpPtr, sizeof(tmpPtr)); + probeBlockEnd(); + } + + if((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { + setProbePoint(&probeInfo); + preBlockEnd(); + } + + ret = (this->*Constructp)(filePath, openMode, createParentDirectories); + + if(gProbeBlockCount == 0 && blockresult) + { + add_object_hash((void*)this, OBJECT_EXTERNAL); + } + + if(postBlockBegin(blockresult)) { + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", + LC_RESOURCE, probeInfo.eventIndex, "File::Construct", + probeInfo.currentTime, probeInfo.pID, probeInfo.tID); + //Input,ret + WcharToChar(temp,filePath.GetPointer()); + log.length += sprintf(log.data + log.length,"`,%s",temp); + WcharToChar(temp,openMode.GetPointer()); + log.length += sprintf(log.data + log.length,", %s",temp); + log.length += sprintf(log.data + log.length,", %s`,%ld",(createParentDirectories == 0 ? "false" : "true"),ret); + //PCAddr,errno,InternalCall,size,FD,FDType,FDApiType,FileSize,FilePath + if(ret == E_SUCCESS && E_SUCCESS == File::GetAttributes(this->GetName(),attr)) + size = attr.GetFileSize(); + WcharToChar(temp,filePath.GetPointer()); +// WcharToChar(temp,this->GetName().GetPointer()); + log.length += sprintf(log.data + log.length,"`,0`,%lu`,%d`,%u`,0`,0x%x`,%d`,%d`,%lld`,%s",ret,blockresult,(unsigned int)CALLER_ADDRESS,(unsigned int)this,FD_FILE,FD_API_OPEN,size,temp); + //callstack + +// if(E_SUCCESS != ret || blockresult == 2) { +// log.length += sprintf(log.data + log.length, +// "`,\ncallstack_start`,`,callstack_end"); +// } else{ + log.length += sprintf(log.data + log.length, + "`,\ncallstack_start`,"); + getBacktraceString(&log, 4096 - log.length - 17); + log.length += sprintf(log.data + log.length, "`,callstack_end"); +// } + + printLog(&log, MSG_LOG); + postBlockEnd(); + } + + return ret; +} + +result File::Construct(const Tizen::Base::String& filePath, + const Tizen::Base::String& openMode) { + typedef result (File::*methodType)(const Tizen::Base::String& filePath, + const Tizen::Base::String& openMode); + static methodType Constructp = 0; + result ret; + probeInfo_t probeInfo; + log_t log; + int blockresult; + bool bfiltering = true; + char temp[PATH_MAX]; + FileAttributes attr; + long long size = 0L; + + if(!Constructp) { + probeBlockStart(); + void *tmpPtr = dlsym(RTLD_NEXT, + "_ZN5Tizen2Io4File9ConstructERKNS_4Base6StringES5_"); + + if(tmpPtr == NULL || dlerror() != NULL) { + perror("dlsym failed : Tizen::Io::File::Construct"); + exit(0); + } + + memcpy(&Constructp, &tmpPtr, sizeof(tmpPtr)); + probeBlockEnd(); + } + + if((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { + setProbePoint(&probeInfo); + preBlockEnd(); + } + + ret = (this->*Constructp)(filePath, openMode); + + if(gProbeBlockCount == 0 && blockresult) + { + add_object_hash((void*)this, OBJECT_EXTERNAL); + } + + if(postBlockBegin(blockresult)) { + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", + LC_RESOURCE, probeInfo.eventIndex, "File::Construct", + probeInfo.currentTime, probeInfo.pID, probeInfo.tID); + //Input,ret + WcharToChar(temp,filePath.GetPointer()); + log.length += sprintf(log.data + log.length,"`,%s",temp); + WcharToChar(temp,openMode.GetPointer()); + log.length += sprintf(log.data + log.length,", %s`,%ld",temp,ret); + //PCAddr,errno,InternalCall,size,FD,FDType,FDApiType,FileSize,FilePath + if(ret == E_SUCCESS && E_SUCCESS == File::GetAttributes(this->GetName(),attr)) + size = attr.GetFileSize(); + WcharToChar(temp,filePath.GetPointer()); +// WcharToChar(temp,this->GetName().GetPointer()); + log.length += sprintf(log.data + log.length,"`,0`,%lu`,%d`,%u`,0`,0x%x`,%d`,%d`,%lld`,%s",ret,blockresult,(unsigned int)CALLER_ADDRESS,(unsigned int)this,FD_FILE,FD_API_OPEN,size,temp); + //callstack + +// if(E_SUCCESS != ret || blockresult == 2) { +// log.length += sprintf(log.data + log.length, +// "`,\ncallstack_start`,`,callstack_end"); +// } else{ + log.length += sprintf(log.data + log.length, + "`,\ncallstack_start`,"); + getBacktraceString(&log, 4096 - log.length - 17); + log.length += sprintf(log.data + log.length, "`,callstack_end"); +// } + + printLog(&log, MSG_LOG); + postBlockEnd(); + } + + return ret; +} + +result File::Construct(const Tizen::Base::String& filePath, + const char *pOpenMode) { + typedef result (File::*methodType)(const Tizen::Base::String& filePath, + const char *pOpenMode); + static methodType Constructp = 0; + result ret; + probeInfo_t probeInfo; + log_t log; + int blockresult; + bool bfiltering = true; + char temp[PATH_MAX]; + FileAttributes attr; + long long size = 0L; + + if(!Constructp) { + probeBlockStart(); + void *tmpPtr = dlsym(RTLD_NEXT, + "_ZN5Tizen2Io4File9ConstructERKNS_4Base6StringEPKc"); + + if(tmpPtr == NULL || dlerror() != NULL) { + perror("dlsym failed : Tizen::Io::File::Construct"); + exit(0); + } + + memcpy(&Constructp, &tmpPtr, sizeof(tmpPtr)); + probeBlockEnd(); + } + + if((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { + setProbePoint(&probeInfo); + preBlockEnd(); + } + + ret = (this->*Constructp)(filePath, pOpenMode); + + if(gProbeBlockCount == 0 && blockresult) + { + add_object_hash((void*)this, OBJECT_EXTERNAL); + } + + if(postBlockBegin(blockresult)) { + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", + LC_RESOURCE, probeInfo.eventIndex, "File::Construct", + probeInfo.currentTime, probeInfo.pID, probeInfo.tID); + //Input,ret + WcharToChar(temp,filePath.GetPointer()); + log.length += sprintf(log.data + log.length,"`,%s",temp); + log.length += sprintf(log.data + log.length,", %s`,%ld",pOpenMode,ret); + //PCAddr,errno,InternalCall,size,FD,FDType,FDApiType,FileSize,FilePath + if(ret == E_SUCCESS && E_SUCCESS == File::GetAttributes(this->GetName(),attr)) + size = attr.GetFileSize(); + WcharToChar(temp,filePath.GetPointer()); +// WcharToChar(temp,this->GetName().GetPointer()); + log.length += sprintf(log.data + log.length,"`,0`,%lu`,%d`,%u`,0`,0x%x`,%d`,%d`,%lld`,%s",ret,blockresult,(unsigned int)CALLER_ADDRESS,(unsigned int)this,FD_FILE,FD_API_OPEN,size,temp); + //callstack + +// if(E_SUCCESS != ret || blockresult == 2) { +// log.length += sprintf(log.data + log.length, +// "`,\ncallstack_start`,`,callstack_end"); +// } else{ + log.length += sprintf(log.data + log.length, + "`,\ncallstack_start`,"); + getBacktraceString(&log, 4096 - log.length - 17); + log.length += sprintf(log.data + log.length, "`,callstack_end"); +// } + + printLog(&log, MSG_LOG); + postBlockEnd(); + } + + return ret; +} + +result File::Construct(const Tizen::Base::String& filePath, + const char *pOpenMode, + const Tizen::Base::ByteBuffer& secretKey) { + typedef result (File::*methodType)(const Tizen::Base::String& filePath, + const char *pOpenMode, + const Tizen::Base::ByteBuffer& secretKey); + static methodType Constructp = 0; + result ret; + probeInfo_t probeInfo; + log_t log; + int blockresult; + bool bfiltering = true; + char temp[PATH_MAX]; + FileAttributes attr; + long long size = 0L; + + if(!Constructp) { + probeBlockStart(); + + void *tmpPtr = dlsym(RTLD_NEXT, + "_ZN5Tizen2Io4File9ConstructERKNS_4Base6StringEPKcRKNS2_10ByteBufferE"); + + if(tmpPtr == NULL || dlerror() != NULL) { + perror("dlsym failed : Tizen::Io::File::Construct"); + exit(0); + } + + memcpy(&Constructp, &tmpPtr, sizeof(tmpPtr)); + probeBlockEnd(); + } + + if((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { + setProbePoint(&probeInfo); + preBlockEnd(); + } + + ret = (this->*Constructp)(filePath, pOpenMode, secretKey); + + if(gProbeBlockCount == 0 && blockresult) + { + add_object_hash((void*)this, OBJECT_EXTERNAL); + } + + if(postBlockBegin(blockresult)) { + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", + LC_RESOURCE, probeInfo.eventIndex, "File::Construct", + probeInfo.currentTime, probeInfo.pID, probeInfo.tID); + //Input,ret + WcharToChar(temp,filePath.GetPointer()); + log.length += sprintf(log.data + log.length,"`,%s",temp); + log.length += sprintf(log.data + log.length,", %s",pOpenMode); + log.length += sprintf(log.data + log.length,", 0x%x`,%ld",(unsigned int)&secretKey,ret); + //PCAddr,errno,InternalCall,size,FD,FDType,FDApiType,FileSize,FilePath + if(ret == E_SUCCESS && E_SUCCESS == File::GetAttributes(this->GetName(),attr)) + size = attr.GetFileSize(); + WcharToChar(temp,filePath.GetPointer()); + log.length += sprintf(log.data + log.length,"`,0`,%lu`,%d`,%u`,0`,0x%x`,%d`,%d`,%lld`,%s",ret,blockresult,(unsigned int)CALLER_ADDRESS,(unsigned int)this,FD_FILE,FD_API_OPEN,size,temp); + //callstack + +// if(E_SUCCESS != ret || blockresult == 2) { +// log.length += sprintf(log.data + log.length, +// "`,\ncallstack_start`,`,callstack_end"); +// } else{ + log.length += sprintf(log.data + log.length, + "`,\ncallstack_start`,"); + getBacktraceString(&log, 4096 - log.length - 17); + log.length += sprintf(log.data + log.length, "`,callstack_end"); +// } + + printLog(&log, MSG_LOG); + postBlockEnd(); + } + + return ret; +} + +result File::Flush(void) { + typedef result (File::*methodType)(void); + static methodType Flushp = 0; + result ret; + probeInfo_t probeInfo; + log_t log; + int blockresult; + bool bfiltering = true; + char temp[PATH_MAX]; + FileAttributes attr; + long long size = 0L; + + if (!Flushp) { + probeBlockStart(); + + void *tmpPtr = dlsym(RTLD_NEXT, "_ZN5Tizen2Io4File5FlushEv"); + + if (tmpPtr == NULL || dlerror() != NULL) { + perror("dlsym failed : Tizen::Io::File::Flush"); + exit(0); + } + + memcpy(&Flushp, &tmpPtr, sizeof(tmpPtr)); + probeBlockEnd(); + } + + if((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { + setProbePoint(&probeInfo); + preBlockEnd(); + } + + ret = (this->*Flushp)(); + + if(postBlockBegin(blockresult)) { + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", + LC_RESOURCE, probeInfo.eventIndex, "File::Flush", + probeInfo.currentTime, probeInfo.pID, probeInfo.tID); + //Input,ret + log.length += sprintf(log.data + log.length,"`,`,%ld",ret); + //PCAddr,errno,InternalCall,size,FD,FDType,FDApiType,FileSize,FilePath + if(E_SUCCESS == File::GetAttributes(this->GetName(),attr)) + size = attr.GetFileSize(); + WcharToChar(temp,this->GetName().GetPointer()); + log.length += sprintf(log.data + log.length,"`,0`,%lu`,%d`,%u`,0`,0x%x`,%d`,%d`,%lld`,%s",ret,blockresult,(unsigned int)CALLER_ADDRESS,(unsigned int)this,FD_FILE,FD_API_OTHER,size,temp); + //callstack + + // if(E_SUCCESS != ret || blockresult == 2) { +// log.length += sprintf(log.data + log.length, +// "`,\ncallstack_start`,`,callstack_end"); +// } else{ + log.length += sprintf(log.data + log.length, + "`,\ncallstack_start`,"); + getBacktraceString(&log, 4096 - log.length - 17); + log.length += sprintf(log.data + log.length, "`,callstack_end"); +// } + + printLog(&log, MSG_LOG); + postBlockEnd(); + } + + return ret; +} + +Tizen::Base::String File::GetName(void) const{ + typedef Tizen::Base::String (File::*methodType)(void) const; + static methodType GetNamep = 0; + Tizen::Base::String ret; + probeInfo_t probeInfo; + log_t log; + int blockresult; + bool bfiltering = true; + char temp[PATH_MAX]; + FileAttributes attr; + long long size = 0L; + + if (!GetNamep) { + probeBlockStart(); + + void *tmpPtr = dlsym(RTLD_NEXT, "_ZNK5Tizen2Io4File7GetNameEv"); + + if (tmpPtr == NULL || dlerror() != NULL) { + perror("dlsym failed : Tizen::Io::File::GetName"); + exit(0); + } + + memcpy(&GetNamep, &tmpPtr, sizeof(tmpPtr)); + probeBlockEnd(); + } + + if((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { + setProbePoint(&probeInfo); + preBlockEnd(); + } + + ret = (this->*GetNamep)(); + result res = GetLastResult(); + + if(postBlockBegin(blockresult)) { + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", + LC_RESOURCE, probeInfo.eventIndex, "File::GetName", + probeInfo.currentTime, probeInfo.pID, probeInfo.tID); + //Input,ret + WcharToChar(temp,ret.GetPointer()); + log.length += sprintf(log.data + log.length,"`,`,%s",temp); + //PCAddr,errno,InternalCall,size,FD,FDType,FDApiType,FileSize,FilePath + if(E_SUCCESS == File::GetAttributes(ret,attr)) + size = attr.GetFileSize(); + log.length += sprintf(log.data + log.length,"`,0`,%lu`,%d`,%u`,0`,0x%x`,%d`,%d`,%lld`,%s",res,blockresult,(unsigned int)CALLER_ADDRESS,(unsigned int)this,FD_FILE,FD_API_OTHER,size,temp); + //callstack + +// if(E_SUCCESS != res || blockresult == 2) { +// log.length += sprintf(log.data + log.length, +// "`,\ncallstack_start`,`,callstack_end"); +// } else{ + log.length += sprintf(log.data + log.length, + "`,\ncallstack_start`,"); + getBacktraceString(&log, 4096 - log.length - 17); + log.length += sprintf(log.data + log.length, "`,callstack_end"); +// } + + printLog(&log, MSG_LOG); + postBlockEnd(); + } + + return ret; +} + +result File::Read(Tizen::Base::String& buffer) { + typedef result (File::*methodType)(Tizen::Base::String & buffer); + static methodType Readp = 0; + result ret; + probeInfo_t probeInfo; + log_t log; + int blockresult; + bool bfiltering = true; + char temp[PATH_MAX]; + int nRead = 0; + FileAttributes attr; + long long size = 0L; + + if (!Readp) { + probeBlockStart(); + + void *tmpPtr = dlsym(RTLD_NEXT, + "_ZN5Tizen2Io4File4ReadERNS_4Base6StringE"); + + if (tmpPtr == NULL || dlerror() != NULL) { + perror("dlsym failed : Tizen::Io::File::Read"); + exit(0); + } + + memcpy(&Readp, &tmpPtr, sizeof(tmpPtr)); + probeBlockEnd(); + } + + if((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { + setProbePoint(&probeInfo); + nRead = Tell(); + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", + LC_RESOURCE, probeInfo.eventIndex, "File::Read", + probeInfo.currentTime, probeInfo.pID, probeInfo.tID); + //Input,ret + log.length += sprintf(log.data + log.length,"`,0x%x`,",(unsigned int)&buffer); + //PCAddr,errno,InternalCall,size,FD,FDType,FDApiType,FileSize,FilePath + if(E_SUCCESS == File::GetAttributes(this->GetName(),attr)) + size = attr.GetFileSize(); + WcharToChar(temp,this->GetName().GetPointer()); + log.length += sprintf(log.data + log.length,"`,0`,0`,%d`,%u`,0`,0x%x`,%d`,%d`,%lld`,%s",blockresult,(unsigned int)CALLER_ADDRESS,(unsigned int)this,FD_FILE,FD_API_READ_START,size,temp); + //callstack + log.length += sprintf(log.data + log.length, "`,\ncallstack_start`,"); + log.length += sprintf(log.data + log.length, "`,callstack_end"); + printLog(&log, MSG_LOG); + preBlockEnd(); + } + + ret = (this->*Readp)(buffer); + + if(postBlockBegin(blockresult)) { + setProbePoint(&probeInfo); + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", + LC_RESOURCE, probeInfo.eventIndex, "File::Read", + probeInfo.currentTime, probeInfo.pID, probeInfo.tID); + //Input,ret + log.length += sprintf(log.data + log.length,"`,0x%x`,%ld",(unsigned int)&buffer,ret); + //PCAddr,errno,InternalCall,size,FD,FDType,FDApiType,FileSize,FilePath + if(E_SUCCESS == File::GetAttributes(this->GetName(),attr)) + size = attr.GetFileSize(); + WcharToChar(temp,this->GetName().GetPointer()); + nRead = Tell() - nRead; + log.length += sprintf(log.data + log.length,"`,0`,%lu`,%d`,%u`,%d`,0x%x`,%d`,%d`,%lld`,%s",ret,blockresult,(unsigned int)CALLER_ADDRESS,nRead,(unsigned int)this,FD_FILE,FD_API_READ_END,size,temp); + //callstack + + // if(E_SUCCESS != ret || blockresult == 2) { +// log.length += sprintf(log.data + log.length, +// "`,\ncallstack_start`,`,callstack_end"); +// } else{ + log.length += sprintf(log.data + log.length, + "`,\ncallstack_start`,"); + getBacktraceString(&log, 4096 - log.length - 17); + log.length += sprintf(log.data + log.length, "`,callstack_end"); +// } + + printLog(&log, MSG_LOG); + postBlockEnd(); + } + + return ret; +} + +result File::Read(Tizen::Base::ByteBuffer& buffer) { + typedef result (File::*methodType)(Tizen::Base::ByteBuffer & buffer); + static methodType Readp = 0; + result ret; + probeInfo_t probeInfo; + log_t log; + int blockresult; + bool bfiltering = true; + char temp[PATH_MAX]; + int nRead = 0; + FileAttributes attr; + long long size = 0L; + + if (!Readp) { + probeBlockStart(); + + void *tmpPtr = dlsym(RTLD_NEXT, + "_ZN5Tizen2Io4File4ReadERNS_4Base10ByteBufferE"); + + if (tmpPtr == NULL || dlerror() != NULL) { + perror("dlsym failed : Tizen::Io::File::Read"); + exit(0); + } + + memcpy(&Readp, &tmpPtr, sizeof(tmpPtr)); + probeBlockEnd(); + } + + if((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { + setProbePoint(&probeInfo); + nRead = Tell(); + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", + LC_RESOURCE, probeInfo.eventIndex, "File::Read", + probeInfo.currentTime, probeInfo.pID, probeInfo.tID); + //Input,ret + log.length += sprintf(log.data + log.length,"`,0x%x`,",(unsigned int)&buffer); + //PCAddr,errno,InternalCall,size,FD,FDType,FDApiType,FileSize,FilePath + if(E_SUCCESS == File::GetAttributes(this->GetName(),attr)) + size = attr.GetFileSize(); + WcharToChar(temp,this->GetName().GetPointer()); + log.length += sprintf(log.data + log.length,"`,0`,0`,%d`,%u`,0`,0x%x`,%d`,%d`,%lld`,%s",blockresult,(unsigned int)CALLER_ADDRESS,(unsigned int)this,FD_FILE,FD_API_READ_START,size,temp); + log.length += sprintf(log.data + log.length, "`,\ncallstack_start`,"); + log.length += sprintf(log.data + log.length, "`,callstack_end"); + printLog(&log, MSG_LOG); + preBlockEnd(); + } + + ret = (this->*Readp)(buffer); + + if(postBlockBegin(blockresult)) { + setProbePoint(&probeInfo); + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", + LC_RESOURCE, probeInfo.eventIndex, "File::Read", + probeInfo.currentTime, probeInfo.pID, probeInfo.tID); + //Input,ret + log.length += sprintf(log.data + log.length,"`,0x%x`,%ld",(unsigned int)&buffer,ret); + //PCAddr,errno,InternalCall,size,FD,FDType,FDApiType,FileSize,FilePath + if(E_SUCCESS == File::GetAttributes(this->GetName(),attr)) + size = attr.GetFileSize(); + WcharToChar(temp,this->GetName().GetPointer()); + nRead = Tell() - nRead; + log.length += sprintf(log.data + log.length,"`,0`,%lu`,%d`,%u`,%d`,0x%x`,%d`,%d`,%lld`,%s",ret,blockresult,(unsigned int)CALLER_ADDRESS,nRead,(unsigned int)this,FD_FILE,FD_API_READ_END,size,temp); + //callstack + + // if(E_SUCCESS != ret || blockresult == 2) { +// log.length += sprintf(log.data + log.length, +// "`,\ncallstack_start`,`,callstack_end"); +// } else{ + log.length += sprintf(log.data + log.length, + "`,\ncallstack_start`,"); + getBacktraceString(&log, 4096 - log.length - 17); + log.length += sprintf(log.data + log.length, "`,callstack_end"); +// } + + printLog(&log, MSG_LOG); + postBlockEnd(); + } + + return ret; +} + +int File::Read(void *buffer, int length) { + typedef int (File::*methodType)(void *buffer, int length); + static methodType Readp = 0; + int ret; + probeInfo_t probeInfo; + log_t log; + int blockresult; + bool bfiltering = true; + char temp[PATH_MAX]; + int nRead = 0; + FileAttributes attr; + long long size = 0L; + + if (!Readp) { + probeBlockStart(); + + void *tmpPtr = dlsym(RTLD_NEXT, "_ZN5Tizen2Io4File4ReadEPvi"); + + if (tmpPtr == NULL || dlerror() != NULL) { + perror("dlsym failed : Tizen::Io::File::Read"); + exit(0); + } + + memcpy(&Readp, &tmpPtr, sizeof(tmpPtr)); + probeBlockEnd(); + } + + if((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { + setProbePoint(&probeInfo); + nRead = Tell(); + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", + LC_RESOURCE, probeInfo.eventIndex, "File::Read", + probeInfo.currentTime, probeInfo.pID, probeInfo.tID); + //Input,ret + log.length += sprintf(log.data + log.length,"`,0x%x, %d`,",(unsigned int)buffer,length); + //PCAddr,errno,InternalCall,size,FD,FDType,FDApiType,FileSize,FilePath + if(E_SUCCESS == File::GetAttributes(this->GetName(),attr)) + size = attr.GetFileSize(); + WcharToChar(temp,this->GetName().GetPointer()); + log.length += sprintf(log.data + log.length,"`,0`,0`,%d`,%u`,0`,0x%x`,%d`,%d`,%lld`,%s",blockresult,(unsigned int)CALLER_ADDRESS,(unsigned int)this,FD_FILE,FD_API_READ_START,size,temp); + log.length += sprintf(log.data + log.length, "`,\ncallstack_start`,"); + log.length += sprintf(log.data + log.length, "`,callstack_end"); + printLog(&log, MSG_LOG); + preBlockEnd(); + } + + ret = (this->*Readp)(buffer, length); + result res = GetLastResult(); + + if(postBlockBegin(blockresult)) { + setProbePoint(&probeInfo); + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", + LC_RESOURCE, probeInfo.eventIndex, "File::Read", + probeInfo.currentTime, probeInfo.pID, probeInfo.tID); + //Input,ret + log.length += sprintf(log.data + log.length,"`,0x%x, %d`,%d",(unsigned int)buffer,length,ret); + //PCAddr,errno,InternalCall,size,FD,FDType,FDApiType,FileSize,FilePath + if(E_SUCCESS == File::GetAttributes(this->GetName(),attr)) + size = attr.GetFileSize(); + WcharToChar(temp,this->GetName().GetPointer()); + nRead = Tell() - nRead; + log.length += sprintf(log.data + log.length,"`,0`,%lu`,%d`,%u`,%d`,0x%x`,%d`,%d`,%lld`,%s",res,blockresult,(unsigned int)CALLER_ADDRESS,nRead,(unsigned int)this,FD_FILE,FD_API_READ_END,size,temp); + //callstack + + // if(E_SUCCESS != ret || blockresult == 2) { +// log.length += sprintf(log.data + log.length, +// "`,\ncallstack_start`,`,callstack_end"); +// } else{ + log.length += sprintf(log.data + log.length, + "`,\ncallstack_start`,"); + getBacktraceString(&log, 4096 - log.length - 17); + log.length += sprintf(log.data + log.length, "`,callstack_end"); +// } + + printLog(&log, MSG_LOG); + postBlockEnd(); + } + + return ret; +} + +result File::Seek(FileSeekPosition position, long offset) { + typedef result (File::*methodType)(FileSeekPosition position, long offset); + static methodType Seekp = 0; + result ret; + probeInfo_t probeInfo; + log_t log; + int blockresult; + bool bfiltering = true; + char temp[PATH_MAX]; + FileAttributes attr; + long long size = 0L; + + if (!Seekp) { + probeBlockStart(); + + void *tmpPtr = dlsym(RTLD_NEXT, + "_ZN5Tizen2Io4File4SeekENS0_16FileSeekPositionEl"); + + if (tmpPtr == NULL || dlerror() != NULL) { + perror("dlsym failed : Tizen::Io::File::Seek"); + exit(0); + } + + memcpy(&Seekp, &tmpPtr, sizeof(tmpPtr)); + + probeBlockEnd(); + } + + if((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { + setProbePoint(&probeInfo); + preBlockEnd(); + } + + ret = (this->*Seekp)(position, offset); + + if(postBlockBegin(blockresult)) { + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", + LC_RESOURCE, probeInfo.eventIndex, "File::Seek", + probeInfo.currentTime, probeInfo.pID, probeInfo.tID); + //Input,ret + if(FILESEEKPOSITION_BEGIN == position) + log.length += sprintf(log.data + log.length,"`,FILESEEKPOSITION_BEGIN"); + else if(FILESEEKPOSITION_CURRENT == position) + log.length += sprintf(log.data + log.length,"`,FILESEEKPOSITION_CURRENT"); + else if(FILESEEKPOSITION_END == position) + log.length += sprintf(log.data + log.length,"`,FILESEEKPOSITION_END"); + else + log.length += sprintf(log.data + log.length,"`,%d",position); + log.length += sprintf(log.data + log.length,", %ld`,%ld",offset,ret); + //PCAddr,errno,InternalCall,size,FD,FDType,FDApiType,FileSize,FilePath + if(E_SUCCESS == File::GetAttributes(this->GetName(),attr)) + size = attr.GetFileSize(); + WcharToChar(temp,this->GetName().GetPointer()); + log.length += sprintf(log.data + log.length,"`,0`,%lu`,%d`,%u`,0`,0x%x`,%d`,%d`,%lld`,%s",ret,blockresult,(unsigned int)CALLER_ADDRESS,(unsigned int)this,FD_FILE,FD_API_OTHER,size,temp); + //callstack + + // if(E_SUCCESS != ret || blockresult == 2) { +// log.length += sprintf(log.data + log.length, +// "`,\ncallstack_start`,`,callstack_end"); +// } else{ + log.length += sprintf(log.data + log.length, + "`,\ncallstack_start`,"); + getBacktraceString(&log, 4096 - log.length - 17); + log.length += sprintf(log.data + log.length, "`,callstack_end"); +// } + + printLog(&log, MSG_LOG); + postBlockEnd(); + } + + return ret; +} + +int File::Tell(void) const { + typedef int (File::*methodType)(void) const; + static methodType Tellp = 0; + int ret; + probeInfo_t probeInfo; + log_t log; + int blockresult; + bool bfiltering = true; + char temp[PATH_MAX]; + FileAttributes attr; + long long size = 0L; + + if (!Tellp) { + probeBlockStart(); + + void *tmpPtr = dlsym(RTLD_NEXT, "_ZNK5Tizen2Io4File4TellEv"); + + if (tmpPtr == NULL || dlerror() != NULL) { + perror("dlsym failed : Tizen::Io::File::Tell"); + exit(0); + } + + memcpy(&Tellp, &tmpPtr, sizeof(tmpPtr)); + + probeBlockEnd(); + } + + if((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { + setProbePoint(&probeInfo); + preBlockEnd(); + } + + ret = (this->*Tellp)(); + result res = GetLastResult(); + + if(postBlockBegin(blockresult)) { + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", + LC_RESOURCE, probeInfo.eventIndex, "File::Tell", + probeInfo.currentTime, probeInfo.pID, probeInfo.tID); + //Input,ret + log.length += sprintf(log.data + log.length,"`,`,%d",ret); + //PCAddr,errno,InternalCall,size,FD,FDType,FDApiType,FileSize,FilePath + if(E_SUCCESS == File::GetAttributes(this->GetName(),attr)) + size = attr.GetFileSize(); + WcharToChar(temp,this->GetName().GetPointer()); + log.length += sprintf(log.data + log.length,"`,0`,%lu`,%d`,%u`,0`,0x%x`,%d`,%d`,%lld`,%s",res,blockresult,(unsigned int)CALLER_ADDRESS,(unsigned int)this,FD_FILE,FD_API_OTHER,size,temp); + //callstack + + // if(E_SUCCESS != ret || blockresult == 2) { +// log.length += sprintf(log.data + log.length, +// "`,\ncallstack_start`,`,callstack_end"); +// } else{ + log.length += sprintf(log.data + log.length, + "`,\ncallstack_start`,"); + getBacktraceString(&log, 4096 - log.length - 17); + log.length += sprintf(log.data + log.length, "`,callstack_end"); +// } + + printLog(&log, MSG_LOG); + postBlockEnd(); + } + + return ret; +} + +result File::Truncate(int length) { + typedef result (File::*methodType)(int length); + static methodType Truncatep = 0; + result ret; + probeInfo_t probeInfo; + log_t log; + int blockresult; + bool bfiltering = true; + char temp[PATH_MAX]; + FileAttributes attr; + long long size = 0L; + + if (!Truncatep) { + probeBlockStart(); + + void *tmpPtr = dlsym(RTLD_NEXT, "_ZN5Tizen2Io4File8TruncateEi"); + + if (tmpPtr == NULL || dlerror() != NULL) { + perror("dlsym failed : Tizen::Io::File::Truncate"); + exit(0); + } + + memcpy(&Truncatep, &tmpPtr, sizeof(tmpPtr)); + probeBlockEnd(); + } + + if((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { + setProbePoint(&probeInfo); + preBlockEnd(); + } + + ret = (this->*Truncatep)(length); + + if(postBlockBegin(blockresult)) { + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", + LC_RESOURCE, probeInfo.eventIndex, "File::Truncate", + probeInfo.currentTime, probeInfo.pID, probeInfo.tID); + //Input,ret + log.length += sprintf(log.data + log.length,"`,%d`,%ld",length,ret); + //PCAddr,errno,InternalCall,size,FD,FDType,FDApiType,FileSize,FilePath + if(E_SUCCESS == File::GetAttributes(this->GetName(),attr)) + size = attr.GetFileSize(); + WcharToChar(temp,this->GetName().GetPointer()); + log.length += sprintf(log.data + log.length,"`,0`,%lu`,%d`,%u`,0`,0x%x`,%d`,%d`,%lld`,%s",ret,blockresult,(unsigned int)CALLER_ADDRESS,(unsigned int)this,FD_FILE,FD_API_OTHER,size,temp); + //callstack + + // if(E_SUCCESS != ret || blockresult == 2) { +// log.length += sprintf(log.data + log.length, +// "`,\ncallstack_start`,`,callstack_end"); +// } else{ + log.length += sprintf(log.data + log.length, + "`,\ncallstack_start`,"); + getBacktraceString(&log, 4096 - log.length - 17); + log.length += sprintf(log.data + log.length, "`,callstack_end"); +// } + + printLog(&log, MSG_LOG); + postBlockEnd(); + } + + return ret; +} + +result File::Write(const void *buffer, int length) { + typedef result (File::*methodType)(const void *buffer, int length); + static methodType Writep = 0; + result ret; + probeInfo_t probeInfo; + log_t log; + int blockresult; + bool bfiltering = true; + char temp[PATH_MAX]; + int nWritten = 0; + FileAttributes attr; + long long size = 0L; + + if (!Writep) { + probeBlockStart(); + + void *tmpPtr = dlsym(RTLD_NEXT, "_ZN5Tizen2Io4File5WriteEPKvi"); + + if (tmpPtr == NULL || dlerror() != NULL) { + perror("dlsym failed : Tizen::Io::File::Write"); + exit(0); + } + + memcpy(&Writep, &tmpPtr, sizeof(tmpPtr)); + probeBlockEnd(); + } + + if((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { + setProbePoint(&probeInfo); + nWritten = Tell(); + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", + LC_RESOURCE, probeInfo.eventIndex, "File::Write", + probeInfo.currentTime, probeInfo.pID, probeInfo.tID); + //Input,ret + log.length += sprintf(log.data + log.length,"`,0x%x, %d`,",(unsigned int)buffer,length); + //PCAddr,errno,InternalCall,size,FD,FDType,FDApiType,FileSize,FilePath + if(E_SUCCESS == File::GetAttributes(this->GetName(),attr)) + size = attr.GetFileSize(); + WcharToChar(temp,this->GetName().GetPointer()); + log.length += sprintf(log.data + log.length,"`,0`,0`,%d`,%u`,0`,0x%x`,%d`,%d`,%lld`,%s",blockresult,(unsigned int)CALLER_ADDRESS,(unsigned int)this,FD_FILE,FD_API_WRITE_START,size,temp); + log.length += sprintf(log.data + log.length, "`,\ncallstack_start`,"); + log.length += sprintf(log.data + log.length, "`,callstack_end"); + printLog(&log, MSG_LOG); + preBlockEnd(); + } + + ret = (this->*Writep)(buffer, length); + + if(postBlockBegin(blockresult)) { + setProbePoint(&probeInfo); + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", + LC_RESOURCE, probeInfo.eventIndex, "File::Write", + probeInfo.currentTime, probeInfo.pID, probeInfo.tID); + //Input,ret + log.length += sprintf(log.data + log.length,"`,0x%x, %d`,%ld",(unsigned int)buffer,length,ret); + //PCAddr,errno,InternalCall,size,FD,FDType,FDApiType,FileSize,FilePath + if(E_SUCCESS == File::GetAttributes(this->GetName(),attr)) + size = attr.GetFileSize(); + WcharToChar(temp,this->GetName().GetPointer()); + nWritten = Tell() - nWritten; + log.length += sprintf(log.data + log.length,"`,0`,%lu`,%d`,%u`,%d`,0x%x`,%d`,%d`,%lld`,%s",ret,blockresult,(unsigned int)CALLER_ADDRESS,nWritten,(unsigned int)this,FD_FILE,FD_API_WRITE_END,size,temp); + //callstack + + // if(E_SUCCESS != ret || blockresult == 2) { +// log.length += sprintf(log.data + log.length, +// "`,\ncallstack_start`,`,callstack_end"); +// } else{ + log.length += sprintf(log.data + log.length, + "`,\ncallstack_start`,"); + getBacktraceString(&log, 4096 - log.length - 17); + log.length += sprintf(log.data + log.length, "`,callstack_end"); +// } + + printLog(&log, MSG_LOG); + postBlockEnd(); + } + + return ret; +} + +result File::Write(const Tizen::Base::ByteBuffer& buffer) { + typedef result (File::*methodType)(const Tizen::Base::ByteBuffer& buffer); + static methodType Writep = 0; + result ret; + probeInfo_t probeInfo; + log_t log; + int blockresult; + bool bfiltering = true; + char temp[PATH_MAX]; + int nWritten = 0; + FileAttributes attr; + long long size = 0L; + + if (!Writep) { + probeBlockStart(); + + void *tmpPtr = dlsym(RTLD_NEXT, "_ZN5Tizen2Io4File5WriteERKNS_4Base10ByteBufferE"); + + if (tmpPtr == NULL || dlerror() != NULL) { + perror("dlsym failed : Tizen::Io::File::Write"); + exit(0); + } + + memcpy(&Writep, &tmpPtr, sizeof(tmpPtr)); + probeBlockEnd(); + } + + if((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { + setProbePoint(&probeInfo); + nWritten = Tell(); + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", + LC_RESOURCE, probeInfo.eventIndex, "File::Write", + probeInfo.currentTime, probeInfo.pID, probeInfo.tID); + //Input,ret + log.length += sprintf(log.data + log.length,"`,0x%x`,",(unsigned int)&buffer); + //PCAddr,errno,InternalCall,size,FD,FDType,FDApiType,FileSize,FilePath + if(E_SUCCESS == File::GetAttributes(this->GetName(),attr)) + size = attr.GetFileSize(); + WcharToChar(temp,this->GetName().GetPointer()); + log.length += sprintf(log.data + log.length,"`,0`,0`,%d`,%u`,0`,0x%x`,%d`,%d`,%lld`,%s",blockresult,(unsigned int)CALLER_ADDRESS,(unsigned int)this,FD_FILE,FD_API_WRITE_START,size,temp); + log.length += sprintf(log.data + log.length, "`,\ncallstack_start`,"); + log.length += sprintf(log.data + log.length, "`,callstack_end"); + printLog(&log, MSG_LOG); + preBlockEnd(); + } + + ret = (this->*Writep)(buffer); + + if(postBlockBegin(blockresult)) { + setProbePoint(&probeInfo); + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", + LC_RESOURCE, probeInfo.eventIndex, "File::Write", + probeInfo.currentTime, probeInfo.pID, probeInfo.tID); + //Input,ret + log.length += sprintf(log.data + log.length,"`,0x%x`,%ld",(unsigned int)&buffer,ret); + //PCAddr,errno,InternalCall,size,FD,FDType,FDApiType,FileSize,FilePath + if(E_SUCCESS == File::GetAttributes(this->GetName(),attr)) + size = attr.GetFileSize(); + WcharToChar(temp,this->GetName().GetPointer()); + nWritten = Tell() - nWritten; + log.length += sprintf(log.data + log.length,"`,0`,%lu`,%d`,%u`,%d`,0x%x`,%d`,%d`,%lld`,%s",ret,blockresult,(unsigned int)CALLER_ADDRESS,nWritten,(unsigned int)this,FD_FILE,FD_API_WRITE_END,size,temp); + //callstack + + // if(E_SUCCESS != ret || blockresult == 2) { +// log.length += sprintf(log.data + log.length, +// "`,\ncallstack_start`,`,callstack_end"); +// } else{ + log.length += sprintf(log.data + log.length, + "`,\ncallstack_start`,"); + getBacktraceString(&log, 4096 - log.length - 17); + log.length += sprintf(log.data + log.length, "`,callstack_end"); +// } + + printLog(&log, MSG_LOG); + postBlockEnd(); + } + + return ret; +} + +result File::Write(const Tizen::Base::String& buffer) { + typedef result (File::*methodType)(const Tizen::Base::String& buffer); + static methodType Writep = 0; + result ret; + probeInfo_t probeInfo; + log_t log; + int blockresult; + bool bfiltering = true; + char temp[PATH_MAX]; + int nWritten = 0; + FileAttributes attr; + long long size = 0L; + + if (!Writep) { + probeBlockStart(); + + void *tmpPtr = dlsym(RTLD_NEXT, "_ZN5Tizen2Io4File5WriteERKNS_4Base6StringE"); + + if (tmpPtr == NULL || dlerror() != NULL) { + perror("dlsym failed : Tizen::Io::File::Write"); + exit(0); + } + + memcpy(&Writep, &tmpPtr, sizeof(tmpPtr)); + probeBlockEnd(); + } + + if((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { + setProbePoint(&probeInfo); + nWritten = Tell(); + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", + LC_RESOURCE, probeInfo.eventIndex, "File::Write", + probeInfo.currentTime, probeInfo.pID, probeInfo.tID); + //Input,ret + WcharToChar(temp,buffer.GetPointer()); + log.length += sprintf(log.data + log.length,"`,%s`,",temp); + //PCAddr,errno,InternalCall,size,FD,FDType,FDApiType,FileSize,FilePath + if(E_SUCCESS == File::GetAttributes(this->GetName(),attr)) + size = attr.GetFileSize(); + WcharToChar(temp,this->GetName().GetPointer()); + log.length += sprintf(log.data + log.length,"`,0`,0`,%d`,%u`,0`,0x%x`,%d`,%d`,%lld`,%s",blockresult,(unsigned int)CALLER_ADDRESS,(unsigned int)this,FD_FILE,FD_API_WRITE_START,size,temp); + log.length += sprintf(log.data + log.length, "`,\ncallstack_start`,"); + log.length += sprintf(log.data + log.length, "`,callstack_end"); + printLog(&log, MSG_LOG); + preBlockEnd(); + } + + ret = (this->*Writep)(buffer); + + if(postBlockBegin(blockresult)) { + setProbePoint(&probeInfo); + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", + LC_RESOURCE, probeInfo.eventIndex, "File::Write", + probeInfo.currentTime, probeInfo.pID, probeInfo.tID); + //Input,ret + WcharToChar(temp,buffer.GetPointer()); + log.length += sprintf(log.data + log.length,"`,%s`,%ld",temp,ret); + //PCAddr,errno,InternalCall,size,FD,FDType,FDApiType,FileSize,FilePath + if(E_SUCCESS == File::GetAttributes(this->GetName(),attr)) + size = attr.GetFileSize(); + WcharToChar(temp,this->GetName().GetPointer()); + nWritten = Tell() - nWritten; + log.length += sprintf(log.data + log.length,"`,0`,%lu`,%d`,%u`,%d`,0x%x`,%d`,%d`,%lld`,%s",ret,blockresult,(unsigned int)CALLER_ADDRESS,nWritten,(unsigned int)this,FD_FILE,FD_API_WRITE_END,size,temp); + //callstack + + // if(E_SUCCESS != ret || blockresult == 2) { +// log.length += sprintf(log.data + log.length, +// "`,\ncallstack_start`,`,callstack_end"); +// } else{ + log.length += sprintf(log.data + log.length, + "`,\ncallstack_start`,"); + getBacktraceString(&log, 4096 - log.length - 17); + log.length += sprintf(log.data + log.length, "`,callstack_end"); +// } + + printLog(&log, MSG_LOG); + postBlockEnd(); + } + return ret; +} + +File::~File(void) { + typedef void (File::*methodType)(); + static methodType FileDp = 0; + probeInfo_t probeInfo; + log_t log; + int blockresult; + bool bfiltering = true; + void *tmpPtr; +// FileAttributes attr; + long long size = 0L; + unsigned short caller; + int ret; + + if (!FileDp) { + probeBlockStart(); + + tmpPtr = dlsym(RTLD_NEXT, "_ZN5Tizen2Io4FileD1Ev"); + + if (tmpPtr == NULL || dlerror() != NULL) { + perror("dlsym failed : Tizen::Io::File::~File"); + exit(0); + } + + memcpy(&FileDp, &tmpPtr, sizeof(tmpPtr)); + probeBlockEnd(); + } + + if((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { + setProbePoint(&probeInfo); + // error occur if File class was failed to construct +// if(E_SUCCESS == File::GetAttributes(this->GetName(),attr)) +// size = attr.GetFileSize(); + preBlockEnd(); + } + + if(gProbeBlockCount == 0) + { + probeBlockStart(); + ret = del_object_hash((void*)this, &caller); + if(blockresult == 0 && ret == 0 && caller == OBJECT_EXTERNAL) + { + setProbePoint(&probeInfo); + blockresult = 2; + probingStart(); + } + probeBlockEnd(); + } + + (this->*FileDp)(); + + if(postBlockBegin(blockresult)) { + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", + LC_RESOURCE, probeInfo.eventIndex, "File::~File", + probeInfo.currentTime, probeInfo.pID, probeInfo.tID); + //Input,ret + log.length += sprintf(log.data + log.length,"`,`,"); + //PCAddr,errno,InternalCall,size,FD,FDType,FDApiType,FileSize,FilePath + log.length += sprintf(log.data + log.length,"`,0`,0`,%d`,%u`,0`,0x%x`,%d`,%d`,%lld`,",blockresult,(unsigned int)CALLER_ADDRESS,(unsigned int)this,FD_FILE,FD_API_CLOSE,size); + //callstack + +// if(E_SUCCESS != ret || blockresult == 2) { +// log.length += sprintf(log.data + log.length, +// "`,\ncallstack_start`,`,callstack_end"); +// } else{ + log.length += sprintf(log.data + log.length, + "`,\ncallstack_start`,"); + getBacktraceString(&log, 4096 - log.length - 17); + log.length += sprintf(log.data + log.length, "`,callstack_end"); +// } + + printLog(&log, MSG_LOG); + postBlockEnd(); + } +} + + +// static methods +//static result File::ConvertToSecureFile(const Tizen::Base::String &plainFilePath, +// const Tizen::Base::String &secureFilePath) { +// typedef result (File::*methodType)( +// const Tizen::Base::String &plainFilePath, +// const Tizen::Base::String &secureFilePath); +// static methodType ConvertToSecureFilep = 0; +// +//} +//static result File::ConvertToSecureFile(const Tizen::Base::String &plainFilePath, +// const Tizen::Base::String &secureFilePath, +// const Tizen::Base::ByteBuffer& key) { +// typedef result (File::*methodType)( +// const Tizen::Base::String &plainFilePath, +// const Tizen::Base::String &secureFilePath, +// const Tizen::Base::ByteBuffer& key); +// static methodType ConvertToSecureFilep = 0; +// +//} +//static result File::Copy(const Tizen::Base::String& srcFilePath, +// const Tizen::Base::String& destFilePath, bool failIfExist) { +// typedef result (File::*methodType)(const Tizen::Base::String& srcFilePath, +// const Tizen::Base::String& destFilePath, bool failIfExist); +// static methodType Copyp = 0; +// +//} +//static result File::GetAttributes(const Tizen::Base::String& filePath, +// FileAttributes& attribute) { +// typedef result (File::*methodType)(const Tizen::Base::String& filePath, +// FileAttributes& attribute); +// static methodType GetAttributesp = 0; +// +//} +//static const Tizen::Base::String File::GetFileExtension( +// const Tizen::Base::String& filePath) { +// typedef const Tizen::Base::String (File::*methodType)( +// const Tizen::Base::String& filePath); +// static methodType GetFileExtensionp = 0; +// +//} +//const Tizen::Base::String File::GetFileName( +// const Tizen::Base::String& filePath) { +// typedef const Tizen::Base::String (File::*methodType)( +// const Tizen::Base::String& filePath); +// static methodType GetFileNamep = 0; +// Tizen::Base::String ret; +// +// if (!GetFileNamep) { +// probeBlockStart(); +// void *tmpPtr = dlsym(RTLD_NEXT, +// "_ZN5Tizen2Io4File11GetFileNameERKNS_4Base6StringE"); +// +// if (tmpPtr == NULL || dlerror() != NULL) { +// perror("dlsym failed : Tizen::Io::File::GetFileName"); +// exit(0); +// } +// +// memcpy(&GetFileNamep, &tmpPtr, sizeof(tmpPtr)); +// probeBlockEnd(); +// } +// ret = (File::(*GetFileNamep))(filePath); +// +//return ret; +//} +//static bool File::IsEncrypted(const Tizen::Base::String &filePath) { +// typedef bool (File::*methodType)(const Tizen::Base::String &filePath); +// static methodType IsEncryptedp = 0; +// +//} +//static bool File::IsFileExist(const Tizen::Base::String& filePath) { +// typedef bool (File::*methodType)(const Tizen::Base::String& filePath); +// static methodType IsFileExistp = 0; +// +//} +//static result File::Move(const Tizen::Base::String& oldFilePath, +// const Tizen::Base::String& newFilePath) { +// typedef result (File::*methodType)(const Tizen::Base::String& oldFilePath, +// const Tizen::Base::String& newFilePath); +// static methodType Movep = 0; +// +//} +//static result File::Remove(const Tizen::Base::String& filePath) { +// typedef result (File::*methodType)(const Tizen::Base::String& filePath); +// static methodType Removep = 0; +// +//} + +} +} diff --git a/probe_tizenapi/tizen_lifecycle.cpp b/probe_tizenapi/tizen_lifecycle.cpp new file mode 100755 index 0000000..8e7dae4 --- /dev/null +++ b/probe_tizenapi/tizen_lifecycle.cpp @@ -0,0 +1,214 @@ +/* + * DA probe + * + * Copyright (File::*c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Jaewon Lim + * Woojin Jung + * Juyoung Kim + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#include +#include +#include +#include + +#include "daprobe.h" +#include "dahelper.h" +#include "probeinfo.h" +#include "tizen_probe.h" + +extern "C" +{ +Ecore_Event_Handler* register_orientation_event_listener(); +void unregister_orientation_event_listener(Ecore_Event_Handler* handler); +} + +using namespace Tizen::Base; +using namespace Tizen::Base::Collection; + +#define LIFECYCLE_PROBE_BLOCK(FUNCNAME) \ + setProbePoint(&probeInfo); \ + INIT_LOG; \ + APPEND_LOG_BASIC_NAME(LC_LIFECYCLE, FUNCNAME); \ + APPEND_LOG_COMMON_NONE(CALLER_ADDRESS); \ + printLog(&log, MSG_LOG) + +namespace Tizen { namespace App +{ + +//class _IAppImpl +//{ +// virtual void OnDeviceOrientationChanged(app_device_orientation_e orientation) = 0; +//}; + +class _AppImpl +{ + static void OnTerminate(void* user_data); +// static void OnDeviceOrientationChanged(app_device_orientation_e orientation, void* user_data); +}; + +class _UiAppImpl +// : public Tizen::Base::Object +// , public _IAppImpl +{ + void OnBackground(void); + void OnForeground(void); +// virtual void OnDeviceOrientationChanged(app_device_orientation_e orientation); +}; + +class _AppInfo +{ + static void SetAppState(AppState appstate); +}; + +result UiApp::Execute(UiAppInstanceFactory pUiAppFactory, + const IList* pArguments) +{ + typedef result (*methodType)(UiAppInstanceFactory pFactory, const IList* pArgs); + static methodType uiapp_executep; + DECLARE_COMMON_VARIABLE; + Ecore_Event_Handler* handler; + result ret; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen3App5UiApp7ExecuteEPFPS1_vEPKNS_4Base10Collection5IListE, + LIBOSP_UIFW, uiapp_executep); + + probeBlockStart(); + handler = register_orientation_event_listener(); + if(gTraceInfo.exec_map.map_start == NULL) + { + get_map_address(CALLER_ADDRESS, &(gTraceInfo.exec_map.map_start), + &(gTraceInfo.exec_map.map_end)); + } + LIFECYCLE_PROBE_BLOCK("INITIALIZING"); + probeBlockEnd(); + + ret = uiapp_executep(pUiAppFactory, pArguments); + + probeBlockStart(); + unregister_orientation_event_listener(handler); + probeBlockEnd(); + + return ret; +} + +void _AppImpl::OnTerminate(void* user_data) +{ + typedef void (*methodType)(void*); + static methodType appimpl_onterminatep; + DECLARE_COMMON_VARIABLE; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen3App8_AppImpl11OnTerminateEPv, LIBOSP_APPFW, appimpl_onterminatep); + + probeBlockStart(); + LIFECYCLE_PROBE_BLOCK("TERMINATING"); + probeBlockEnd(); + + appimpl_onterminatep(user_data); +} +/* +void _AppImpl::OnDeviceOrientationChanged(app_device_orientation_e orientation, void* user_data) +{ + typedef void (*methodType)(app_device_orientation_e, void*); + static methodType appimpl_ondeviceorientationchangedp; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen3App8_AppImpl26OnDeviceOrientationChangedE24app_device_orientation_ePv, + LIBOSP_APPFW, appimpl_ondeviceorientationchangedp); + + probeBlockStart(); + on_orientation_changed((int)orientation, false); + probeBlockEnd(); + + appimpl_ondeviceorientationchangedp(orientation, user_data); +} +*/ +void _AppInfo::SetAppState(AppState appState) +{ + typedef void (*methodType)(AppState appstate); + static methodType appinfo_setappstatep; + DECLARE_COMMON_VARIABLE; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen3App8_AppInfo11SetAppStateENS0_8AppStateE, LIBOSP_APPFW, appinfo_setappstatep); + + probeBlockStart(); + if(appState == RUNNING) + { + LIFECYCLE_PROBE_BLOCK("RUNNING"); + } + probeBlockEnd(); + + appinfo_setappstatep(appState); +} + +void _UiAppImpl::OnBackground(void) +{ + typedef void (_UiAppImpl::*methodType)(void); + static methodType uiappimpl_onbackgroundp; + DECLARE_COMMON_VARIABLE; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen3App10_UiAppImpl12OnBackgroundEv, LIBOSP_UIFW, uiappimpl_onbackgroundp); + + probeBlockStart(); + SCREENSHOT_LOCK(); + LIFECYCLE_PROBE_BLOCK("PAUSING"); + probeBlockEnd(); + + (this->*uiappimpl_onbackgroundp)(); +} + +void _UiAppImpl::OnForeground(void) +{ + typedef void (_UiAppImpl::*methodType)(void); + static methodType uiappimpl_onforegroundp; + DECLARE_COMMON_VARIABLE; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen3App10_UiAppImpl12OnForegroundEv, LIBOSP_UIFW, uiappimpl_onforegroundp); + + probeBlockStart(); + LIFECYCLE_PROBE_BLOCK("RUNNING"); + SCREENSHOT_UNLOCK(); +// SCREENSHOT_DONE(); + probeBlockEnd(); + + (this->*uiappimpl_onforegroundp)(); +} + +/* +void _UiAppImpl::OnDeviceOrientationChanged(app_device_orientation_e orientation) +{ + typedef void (*methodType)(_UiAppImpl* th, app_device_orientation_e orientation); + static methodType uiappimpl_ondeviceorientationchangedp; + + GET_REAL_FUNC_TIZEN(_ZThn4_N5Tizen3App10_UiAppImpl26OnDeviceOrientationChangedE24app_device_orientation_e, + LIBOSP_UIFW, uiappimpl_ondeviceorientationchangedp); + + probeBlockStart(); + on_orientation_changed((int)orientation, false); + probeBlockEnd(); + + uiappimpl_ondeviceorientationchangedp(static_cast<_UiAppImpl*>(dynamic_cast<_IAppImpl*>(this)), orientation); +} +*/ +} } // end of namespace + diff --git a/probe_tizenapi/tizen_sync.cpp b/probe_tizenapi/tizen_sync.cpp new file mode 100755 index 0000000..2acae4a --- /dev/null +++ b/probe_tizenapi/tizen_sync.cpp @@ -0,0 +1,1135 @@ +/* + * DA probe + * + * Copyright 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Woojin Jung + * Jaewon Lim + * Juyoung Kim + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#include +#include +#include "daprobe.h" +#include "probeinfo.h" +#include "dahelper.h" + +static enum DaOptions _sopt = OPT_THREAD; + +namespace Tizen { +namespace Base { +namespace Runtime { + +result Mutex::Create(void) { + typedef result + (Mutex::*methodType)(void); + static methodType Createp = 0; + result ret; + probeInfo_t probeInfo; + log_t log; + int blockresult; + bool bfiltering = true; + void *tmpPtr; + + if (!Createp) { + probeBlockStart(); + if(lib_handle[LIBOSP_APPFW] == NULL) { + lib_handle[LIBOSP_APPFW] = dlopen(lib_string[LIBOSP_APPFW], RTLD_LAZY); + if (lib_handle[LIBOSP_APPFW] == NULL) { + perror("dlopen failed : libosp-appfw.so"); + exit(0); + } + } + tmpPtr = dlsym(lib_handle[LIBOSP_APPFW], "_ZN5Tizen4Base7Runtime5Mutex6CreateEv"); + + if (tmpPtr == NULL || dlerror() != NULL) { + perror("dlsym failed : Tizen::Base::Runtime::Mutex::Create"); + exit(0); + } + + memcpy(&Createp, &tmpPtr, sizeof(tmpPtr)); + + probeBlockEnd(); + } + + if ((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { + setProbePoint(&probeInfo); + preBlockEnd(); + } + // + ret = (this->*Createp)(); + // + if (postBlockBegin(blockresult)) { + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", LC_SYNC, + probeInfo.eventIndex, "Mutex::Create", + probeInfo.currentTime, probeInfo.pID, probeInfo.tID); + //Input,ret + log.length += sprintf(log.data + log.length, "`,`,%ld", ret); + //PCAddr,errno,InternalCall,CallerPCAddr,SyncVal,SyncType,ApiType + log.length += sprintf(log.data + log.length, + "`,0`,%lu`,%d`,%u`,0x%x`,%d`,%d", ret, blockresult, + (unsigned int)CALLER_ADDRESS, (unsigned int) this, SYNC_TIZEN_MUTEX, SYNC_API_NEW); + //callstack + log.length += sprintf(log.data + log.length, "`,\ncallstack_start`,"); + getBacktraceString(&log, 4096 - log.length - 17); + log.length += sprintf(log.data + log.length, "`,callstack_end"); + + printLog(&log, MSG_LOG); + postBlockEnd(); + } + return ret; +} + +result Mutex::Create(const Tizen::Base::String& name) { + typedef result + (Mutex::*methodType)(const Tizen::Base::String& name); + static methodType Createp = 0; + result ret; + probeInfo_t probeInfo; + log_t log; + int blockresult; + bool bfiltering = true; + void *tmpPtr; + char temp[50]; + + if (!Createp) { + probeBlockStart(); + if(lib_handle[LIBOSP_APPFW] == NULL) { + lib_handle[LIBOSP_APPFW] = dlopen(lib_string[LIBOSP_APPFW], RTLD_LAZY); + if (lib_handle[LIBOSP_APPFW] == NULL) { + perror("dlopen failed : libosp-appfw.so"); + exit(0); + } + } + tmpPtr = dlsym(lib_handle[LIBOSP_APPFW], "_ZN5Tizen4Base7Runtime5Mutex6CreateERKNS0_6StringE"); + + if (tmpPtr == NULL || dlerror() != NULL) { + perror("dlsym failed : Tizen::Base::Runtime::Mutex::Create"); + exit(0); + } + + memcpy(&Createp, &tmpPtr, sizeof(tmpPtr)); + + probeBlockEnd(); + } + + if ((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { + setProbePoint(&probeInfo); + preBlockEnd(); + } + // + ret = (this->*Createp)(name); + // + if (postBlockBegin(blockresult)) { + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", LC_SYNC, + probeInfo.eventIndex, "Mutex::Create", + probeInfo.currentTime, probeInfo.pID, probeInfo.tID); + //Input,ret + WcharToChar(temp, name.GetPointer()); + log.length += sprintf(log.data + log.length, "`,%s`,%ld", temp, ret); + //PCAddr,errno,InternalCall,CallerPCAddr,SyncVal,SyncType,ApiType + log.length += sprintf(log.data + log.length, + "`,0`,%lu`,%d`,%u`,0x%x`,%d`,%d", ret, blockresult, + (unsigned int)CALLER_ADDRESS, (unsigned int) this, SYNC_TIZEN_MUTEX, SYNC_API_NEW); + //callstack + log.length += sprintf(log.data + log.length, "`,\ncallstack_start`,"); + getBacktraceString(&log, 4096 - log.length - 17); + log.length += sprintf(log.data + log.length, "`,callstack_end"); + + printLog(&log, MSG_LOG); + postBlockEnd(); + } + return ret; +} + +result Mutex::Release(void) { + typedef result + (Mutex::*methodType)(void); + static methodType Releasep = 0; + result ret; + probeInfo_t probeInfo; + log_t log; + int blockresult; + bool bfiltering = true; + void *tmpPtr; + + if (!Releasep) { + probeBlockStart(); + if(lib_handle[LIBOSP_APPFW] == NULL) { + lib_handle[LIBOSP_APPFW] = dlopen(lib_string[LIBOSP_APPFW], RTLD_LAZY); + if (lib_handle[LIBOSP_APPFW] == NULL) { + perror("dlopen failed : libosp-appfw.so"); + exit(0); + } + } + tmpPtr = dlsym(lib_handle[LIBOSP_APPFW], "_ZN5Tizen4Base7Runtime5Mutex7ReleaseEv"); + + if (tmpPtr == NULL || dlerror() != NULL) { + perror("dlsym failed : Tizen::Base::Runtime::Mutex::Release"); + exit(0); + } + + memcpy(&Releasep, &tmpPtr, sizeof(tmpPtr)); + + probeBlockEnd(); + } + + if ((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { + setProbePoint(&probeInfo); + preBlockEnd(); + } + // + ret = (this->*Releasep)(); + // + if (postBlockBegin(blockresult)) { + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", LC_SYNC, + probeInfo.eventIndex, "Mutex::Release", + probeInfo.currentTime, probeInfo.pID, probeInfo.tID); + //Input,ret + log.length += sprintf(log.data + log.length, "`,`,%ld", ret); + //PCAddr,errno,InternalCall,CallerPCAddr,SyncVal,SyncType,ApiType + log.length += sprintf(log.data + log.length, + "`,0`,%lu`,%d`,%u`,0x%x`,%d`,%d", ret, blockresult, + (unsigned int)CALLER_ADDRESS, (unsigned int) this, SYNC_TIZEN_MUTEX, SYNC_API_RELEASE); + //callstack + log.length += sprintf(log.data + log.length, "`,\ncallstack_start`,"); + getBacktraceString(&log, 4096 - log.length - 17); + log.length += sprintf(log.data + log.length, "`,callstack_end"); + + printLog(&log, MSG_LOG); + postBlockEnd(); + } + return ret; +} + +result Mutex::Acquire(void) { + typedef result + (Mutex::*methodType)(void); + static methodType Acquirep = 0; + result ret; + probeInfo_t probeInfo; + log_t log; + int blockresult; + bool bfiltering = true; + void *tmpPtr; + + if (!Acquirep) { + probeBlockStart(); + if(lib_handle[LIBOSP_APPFW] == NULL) { + lib_handle[LIBOSP_APPFW] = dlopen(lib_string[LIBOSP_APPFW], RTLD_LAZY); + if (lib_handle[LIBOSP_APPFW] == NULL) { + perror("dlopen failed : libosp-appfw.so"); + exit(0); + } + } + tmpPtr = dlsym(lib_handle[LIBOSP_APPFW], "_ZN5Tizen4Base7Runtime5Mutex7AcquireEv"); + + if (tmpPtr == NULL || dlerror() != NULL) { + perror("dlsym failed : Tizen::Base::Runtime::Mutex::Acquire"); + exit(0); + } + + memcpy(&Acquirep, &tmpPtr, sizeof(tmpPtr)); + + probeBlockEnd(); + } + + if ((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { + setProbePoint(&probeInfo); + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", LC_SYNC, + probeInfo.eventIndex, "Mutex::Acquire", + probeInfo.currentTime, probeInfo.pID, probeInfo.tID); + //Input,ret + log.length += sprintf(log.data + log.length, "`,`,"); + //PCAddr,errno,InternalCall,CallerPCAddr,SyncVal,SyncType,ApiType + log.length += sprintf(log.data + log.length, + "`,0`,0`,%d`,%u`,0x%x`,%d`,%d",blockresult, + (unsigned int)CALLER_ADDRESS, (unsigned int) this, SYNC_TIZEN_MUTEX, SYNC_API_ACQUIRE_WAIT_START); + //callstack + log.length += sprintf(log.data + log.length, "`,\ncallstack_start`,"); + getBacktraceString(&log, 4096 - log.length - 17); + log.length += sprintf(log.data + log.length, "`,callstack_end"); + + printLog(&log, MSG_LOG); + preBlockEnd(); + } + // + ret = (this->*Acquirep)(); + // + if (postBlockBegin(blockresult)) { + setProbePoint(&probeInfo); + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", LC_SYNC, + probeInfo.eventIndex, "Mutex::Acquire", + probeInfo.currentTime, probeInfo.pID, probeInfo.tID); + //Input,ret + log.length += sprintf(log.data + log.length, "`,`,%ld", ret); + //PCAddr,errno,InternalCall,CallerPCAddr,SyncVal,SyncType,ApiType + log.length += sprintf(log.data + log.length, + "`,0`,%lu`,%d`,%u`,0x%x`,%d`,%d", ret, blockresult, + (unsigned int)CALLER_ADDRESS, (unsigned int) this, SYNC_TIZEN_MUTEX, SYNC_API_ACQUIRE_WAIT_END); + //callstack + log.length += sprintf(log.data + log.length, "`,\ncallstack_start`,"); + getBacktraceString(&log, 4096 - log.length - 17); + log.length += sprintf(log.data + log.length, "`,callstack_end"); + + printLog(&log, MSG_LOG); + postBlockEnd(); + } + return ret; +} + +result Mutex::TryToAcquire(void) { + typedef result + (Mutex::*methodType)(void); + static methodType TryToAcquirep = 0; + result ret; + probeInfo_t probeInfo; + log_t log; + int blockresult; + bool bfiltering = true; + void *tmpPtr; + + if (!TryToAcquirep) { + probeBlockStart(); + if(lib_handle[LIBOSP_APPFW] == NULL) { + lib_handle[LIBOSP_APPFW] = dlopen(lib_string[LIBOSP_APPFW], RTLD_LAZY); + if (lib_handle[LIBOSP_APPFW] == NULL) { + perror("dlopen failed : libosp-appfw.so"); + exit(0); + } + } + tmpPtr = dlsym(lib_handle[LIBOSP_APPFW], "_ZN5Tizen4Base7Runtime5Mutex12TryToAcquireEv"); + + if (tmpPtr == NULL || dlerror() != NULL) { + perror("dlsym failed : Tizen::Base::Runtime::Mutex::TryToAcquire"); + exit(0); + } + + memcpy(&TryToAcquirep, &tmpPtr, sizeof(tmpPtr)); + + probeBlockEnd(); + } + + if ((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { + setProbePoint(&probeInfo); + preBlockEnd(); + } + // + ret = (this->*TryToAcquirep)(); + // + if (postBlockBegin(blockresult)) { + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", LC_SYNC, + probeInfo.eventIndex, "Mutex::TryToAcquire", + probeInfo.currentTime, probeInfo.pID, probeInfo.tID); + //Input,ret + log.length += sprintf(log.data + log.length, "`,`,%ld", ret); + //PCAddr,errno,InternalCall,CallerPCAddr,SyncVal,SyncType,ApiType + log.length += sprintf(log.data + log.length, + "`,0`,%lu`,%d`,%u`,0x%x`,%d`,%d", ret, blockresult, + (unsigned int)CALLER_ADDRESS, (unsigned int) this, SYNC_TIZEN_MUTEX, SYNC_API_TRY_ACQUIRE); + //callstack + log.length += sprintf(log.data + log.length, "`,\ncallstack_start`,"); + getBacktraceString(&log, 4096 - log.length - 17); + log.length += sprintf(log.data + log.length, "`,callstack_end"); + + printLog(&log, MSG_LOG); + postBlockEnd(); + } + return ret; +} + + +result Semaphore::Create(int count) { + typedef result + (Semaphore::*methodType)(int count); + static methodType Createp = 0; + result ret; + probeInfo_t probeInfo; + log_t log; + int blockresult; + bool bfiltering = true; + void *tmpPtr; + + if (!Createp) { + probeBlockStart(); + if(lib_handle[LIBOSP_APPFW] == NULL) { + lib_handle[LIBOSP_APPFW] = dlopen(lib_string[LIBOSP_APPFW], RTLD_LAZY); + if (lib_handle[LIBOSP_APPFW] == NULL) { + perror("dlopen failed : libosp-appfw.so"); + exit(0); + } + } + tmpPtr = dlsym(lib_handle[LIBOSP_APPFW], "_ZN5Tizen4Base7Runtime9Semaphore6CreateEi"); + + if (tmpPtr == NULL || dlerror() != NULL) { + perror("dlsym failed : Tizen::Base::Runtime::Semaphore::Create"); + exit(0); + } + + memcpy(&Createp, &tmpPtr, sizeof(tmpPtr)); + + probeBlockEnd(); + } + + if ((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { + setProbePoint(&probeInfo); + preBlockEnd(); + } + // + ret = (this->*Createp)(count); + // + if (postBlockBegin(blockresult)) { + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", LC_SYNC, + probeInfo.eventIndex, "Semaphore::Create", + probeInfo.currentTime, probeInfo.pID, probeInfo.tID); + //Input,ret + log.length += sprintf(log.data + log.length, "`,%d`,%ld", count, ret); + //PCAddr,errno,InternalCall,CallerPCAddr,SyncVal,SyncType,ApiType + log.length += sprintf(log.data + log.length, + "`,0`,%lu`,%d`,%u`,0x%x`,%d`,%d", ret, blockresult, + (unsigned int)CALLER_ADDRESS, (unsigned int) this, SYNC_TIZEN_SEMAPHORE, SYNC_API_NEW); + //callstack + log.length += sprintf(log.data + log.length, "`,\ncallstack_start`,"); + getBacktraceString(&log, 4096 - log.length - 17); + log.length += sprintf(log.data + log.length, "`,callstack_end"); + + printLog(&log, MSG_LOG); + postBlockEnd(); + } + return ret; +} + +result Semaphore::Create(const Tizen::Base::String& name, int count) { + typedef result + (Semaphore::*methodType)(const Tizen::Base::String& name, int count); + static methodType Createp = 0; + result ret; + probeInfo_t probeInfo; + log_t log; + int blockresult; + bool bfiltering = true; + void *tmpPtr; + char temp[50]; + + if (!Createp) { + probeBlockStart(); + if(lib_handle[LIBOSP_APPFW] == NULL) { + lib_handle[LIBOSP_APPFW] = dlopen(lib_string[LIBOSP_APPFW], RTLD_LAZY); + if (lib_handle[LIBOSP_APPFW] == NULL) { + perror("dlopen failed : libosp-appfw.so"); + exit(0); + } + } + tmpPtr = dlsym(lib_handle[LIBOSP_APPFW], "_ZN5Tizen4Base7Runtime9Semaphore6CreateERKNS0_6StringEi"); + + if (tmpPtr == NULL || dlerror() != NULL) { + perror("dlsym failed : Tizen::Base::Runtime::Semaphore::Create"); + exit(0); + } + + memcpy(&Createp, &tmpPtr, sizeof(tmpPtr)); + + probeBlockEnd(); + } + + if ((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { + setProbePoint(&probeInfo); + preBlockEnd(); + } + // + ret = (this->*Createp)(name, count); + // + if (postBlockBegin(blockresult)) { + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", LC_SYNC, + probeInfo.eventIndex, "Semaphore::Create", + probeInfo.currentTime, probeInfo.pID, probeInfo.tID); + //Input,ret + WcharToChar(temp, name.GetPointer()); + log.length += sprintf(log.data + log.length, "`,%s,%d`,%ld", temp, count, ret); + //PCAddr,errno,InternalCall,CallerPCAddr,SyncVal,SyncType,ApiType + log.length += sprintf(log.data + log.length, + "`,0`,%lu`,%d`,%u`,0x%x`,%d`,%d", ret, blockresult, + (unsigned int)CALLER_ADDRESS, (unsigned int) this, SYNC_TIZEN_SEMAPHORE, SYNC_API_NEW); + //callstack + log.length += sprintf(log.data + log.length, "`,\ncallstack_start`,"); + getBacktraceString(&log, 4096 - log.length - 17); + log.length += sprintf(log.data + log.length, "`,callstack_end"); + + printLog(&log, MSG_LOG); + postBlockEnd(); + } + return ret; + +} + +result Semaphore::Acquire(long timeout) { + typedef result + (Semaphore::*methodType)(long timeout); + static methodType Acquirep = 0; + result ret; + probeInfo_t probeInfo; + log_t log; + int blockresult; + bool bfiltering = true; + void *tmpPtr; + + if (!Acquirep) { + probeBlockStart(); + if(lib_handle[LIBOSP_APPFW] == NULL) { + lib_handle[LIBOSP_APPFW] = dlopen(lib_string[LIBOSP_APPFW], RTLD_LAZY); + if (lib_handle[LIBOSP_APPFW] == NULL) { + perror("dlopen failed : libosp-appfw.so"); + exit(0); + } + } + tmpPtr = dlsym(lib_handle[LIBOSP_APPFW], "_ZN5Tizen4Base7Runtime9Semaphore7AcquireEl"); + + if (tmpPtr == NULL || dlerror() != NULL) { + perror("dlsym failed : Tizen::Base::Runtime::Semaphore::Acquire"); + exit(0); + } + + memcpy(&Acquirep, &tmpPtr, sizeof(tmpPtr)); + + probeBlockEnd(); + } + + if ((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { + setProbePoint(&probeInfo); + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", LC_SYNC, + probeInfo.eventIndex, "Semaphore::Acquire", + probeInfo.currentTime, probeInfo.pID, probeInfo.tID); + //Input,ret + log.length += sprintf(log.data + log.length, "`,%ld`,", timeout); + //PCAddr,errno,InternalCall,CallerPCAddr,SyncVal,SyncType,ApiType + log.length += sprintf(log.data + log.length, + "`,0`,0`,%d`,%u`,0x%x`,%d`,%d",blockresult, + (unsigned int)CALLER_ADDRESS, (unsigned int) this, SYNC_TIZEN_SEMAPHORE, SYNC_API_ACQUIRE_WAIT_START); + //callstack + log.length += sprintf(log.data + log.length, "`,\ncallstack_start`,"); + getBacktraceString(&log, 4096 - log.length - 17); + log.length += sprintf(log.data + log.length, "`,callstack_end"); + + printLog(&log, MSG_LOG); + preBlockEnd(); + } + // + ret = (this->*Acquirep)(timeout); + // + if (postBlockBegin(blockresult)) { + setProbePoint(&probeInfo); + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", LC_SYNC, + probeInfo.eventIndex, "Semaphore::Acquire", + probeInfo.currentTime, probeInfo.pID, probeInfo.tID); + //Input,ret + log.length += sprintf(log.data + log.length, "`,%ld`,%ld", timeout, ret); + //PCAddr,errno,InternalCall,CallerPCAddr,SyncVal,SyncType,ApiType + log.length += sprintf(log.data + log.length, + "`,0`,%lu`,%d`,%u`,0x%x`,%d`,%d", ret, blockresult, + (unsigned int)CALLER_ADDRESS, (unsigned int) this, SYNC_TIZEN_SEMAPHORE, SYNC_API_ACQUIRE_WAIT_END); + //callstack + log.length += sprintf(log.data + log.length, "`,\ncallstack_start`,"); + getBacktraceString(&log, 4096 - log.length - 17); + log.length += sprintf(log.data + log.length, "`,callstack_end"); + + printLog(&log, MSG_LOG); + postBlockEnd(); + } + return ret; +} + +result Semaphore::TryToAcquire(void) { + typedef result + (Semaphore::*methodType)(void); + static methodType TryToAcquirep = 0; + result ret; + probeInfo_t probeInfo; + log_t log; + int blockresult; + bool bfiltering = true; + void *tmpPtr; + + if (!TryToAcquirep) { + probeBlockStart(); + if(lib_handle[LIBOSP_APPFW] == NULL) { + lib_handle[LIBOSP_APPFW] = dlopen(lib_string[LIBOSP_APPFW], RTLD_LAZY); + if (lib_handle[LIBOSP_APPFW] == NULL) { + perror("dlopen failed : libosp-appfw.so"); + exit(0); + } + } + tmpPtr = dlsym(lib_handle[LIBOSP_APPFW], "_ZN5Tizen4Base7Runtime9Semaphore12TryToAcquireEv"); + + if (tmpPtr == NULL || dlerror() != NULL) { + perror("dlsym failed : Tizen::Base::Runtime::Semaphore::TryToAcquire"); + exit(0); + } + + memcpy(&TryToAcquirep, &tmpPtr, sizeof(tmpPtr)); + + probeBlockEnd(); + } + + if ((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { + setProbePoint(&probeInfo); + preBlockEnd(); + } + // + ret = (this->*TryToAcquirep)(); + // + if (postBlockBegin(blockresult)) { + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", LC_SYNC, + probeInfo.eventIndex, "Semaphore::TryToAcquire", + probeInfo.currentTime, probeInfo.pID, probeInfo.tID); + //Input,ret + log.length += sprintf(log.data + log.length, "`,`,%ld", ret); + //PCAddr,errno,InternalCall,CallerPCAddr,SyncVal,SyncType,ApiType + log.length += sprintf(log.data + log.length, + "`,0`,%lu`,%d`,%u`,0x%x`,%d`,%d", ret, blockresult, + (unsigned int)CALLER_ADDRESS, (unsigned int) this, SYNC_TIZEN_SEMAPHORE, SYNC_API_TRY_ACQUIRE); + //callstack + log.length += sprintf(log.data + log.length, "`,\ncallstack_start`,"); + getBacktraceString(&log, 4096 - log.length - 17); + log.length += sprintf(log.data + log.length, "`,callstack_end"); + + printLog(&log, MSG_LOG); + postBlockEnd(); + } + return ret; +} + +result Semaphore::Release(void) { + typedef result + (Semaphore::*methodType)(void); + static methodType Releasep = 0; + result ret; + probeInfo_t probeInfo; + log_t log; + int blockresult; + bool bfiltering = true; + void *tmpPtr; + + if (!Releasep) { + probeBlockStart(); + if(lib_handle[LIBOSP_APPFW] == NULL) { + lib_handle[LIBOSP_APPFW] = dlopen(lib_string[LIBOSP_APPFW], RTLD_LAZY); + if (lib_handle[LIBOSP_APPFW] == NULL) { + perror("dlopen failed : libosp-appfw.so"); + exit(0); + } + } + tmpPtr = dlsym(lib_handle[LIBOSP_APPFW], "_ZN5Tizen4Base7Runtime9Semaphore7ReleaseEv"); + + if (tmpPtr == NULL || dlerror() != NULL) { + perror("dlsym failed : Tizen::Base::Runtime::Semaphore::Release"); + exit(0); + } + + memcpy(&Releasep, &tmpPtr, sizeof(tmpPtr)); + + probeBlockEnd(); + } + + if ((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { + setProbePoint(&probeInfo); + preBlockEnd(); + } + // + ret = (this->*Releasep)(); + // + if (postBlockBegin(blockresult)) { + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", LC_SYNC, + probeInfo.eventIndex, "Semaphore::Release", + probeInfo.currentTime, probeInfo.pID, probeInfo.tID); + //Input,ret + log.length += sprintf(log.data + log.length, "`,`,%ld", ret); + //PCAddr,errno,InternalCall,CallerPCAddr,SyncVal,SyncType,ApiType + log.length += sprintf(log.data + log.length, + "`,0`,%lu`,%d`,%u`,0x%x`,%d`,%d", ret, blockresult, + (unsigned int)CALLER_ADDRESS, (unsigned int) this, SYNC_TIZEN_SEMAPHORE, SYNC_API_RELEASE); + //callstack + log.length += sprintf(log.data + log.length, "`,\ncallstack_start`,"); + getBacktraceString(&log, 4096 - log.length - 17); + log.length += sprintf(log.data + log.length, "`,callstack_end"); + + printLog(&log, MSG_LOG); + postBlockEnd(); + } + return ret; +} + + +result Monitor::Construct(void) { + typedef result + (Monitor::*methodType)(void); + static methodType Constructp = 0; + result ret; + probeInfo_t probeInfo; + log_t log; + int blockresult; + bool bfiltering = true; + void *tmpPtr; + + if (!Constructp) { + probeBlockStart(); + if(lib_handle[LIBOSP_APPFW] == NULL) { + lib_handle[LIBOSP_APPFW] = dlopen(lib_string[LIBOSP_APPFW], RTLD_LAZY); + if (lib_handle[LIBOSP_APPFW] == NULL) { + perror("dlopen failed : libosp-appfw.so"); + exit(0); + } + } + tmpPtr = dlsym(lib_handle[LIBOSP_APPFW], "_ZN5Tizen4Base7Runtime7Monitor9ConstructEv"); + + if (tmpPtr == NULL || dlerror() != NULL) { + perror("dlsym failed : Tizen::Base::Runtime::Monitor::Construct"); + exit(0); + } + + memcpy(&Constructp, &tmpPtr, sizeof(tmpPtr)); + probeBlockEnd(); + } + + if ((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { + setProbePoint(&probeInfo); + preBlockEnd(); + } + // + ret = (this->*Constructp)(); + // + if (postBlockBegin(blockresult)) { + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", LC_SYNC, + probeInfo.eventIndex, "Monitor::Construct", + probeInfo.currentTime, probeInfo.pID, probeInfo.tID); + //Input,ret + log.length += sprintf(log.data + log.length, "`,`,%ld", ret); + //PCAddr,errno,InternalCall,CallerPCAddr,SyncVal,SyncType,ApiType + log.length += sprintf(log.data + log.length, + "`,0`,%lu`,%d`,%u`,0x%x`,%d`,%d", ret, blockresult, + (unsigned int)CALLER_ADDRESS, (unsigned int) this, SYNC_TIZEN_MONITOR, SYNC_API_NEW); + //callstack + log.length += sprintf(log.data + log.length, "`,\ncallstack_start`,"); + getBacktraceString(&log, 4096 - log.length - 17); + log.length += sprintf(log.data + log.length, "`,callstack_end"); + + printLog(&log, MSG_LOG); + postBlockEnd(); + } + return ret; +} + +result Monitor::Enter(void) { + typedef result + (Monitor::*methodType)(void); + static methodType Enterp = 0; + result ret; + probeInfo_t probeInfo; + log_t log; + int blockresult; + bool bfiltering = true; + void *tmpPtr; + + if (!Enterp) { + probeBlockStart(); + if(lib_handle[LIBOSP_APPFW] == NULL) { + lib_handle[LIBOSP_APPFW] = dlopen(lib_string[LIBOSP_APPFW], RTLD_LAZY); + if (lib_handle[LIBOSP_APPFW] == NULL) { + perror("dlopen failed : libosp-appfw.so"); + exit(0); + } + } + tmpPtr = dlsym(lib_handle[LIBOSP_APPFW], "_ZN5Tizen4Base7Runtime7Monitor5EnterEv"); + + if (tmpPtr == NULL || dlerror() != NULL) { + perror("dlsym failed : Tizen::Base::Runtime::Monitor::Enter"); + exit(0); + } + + memcpy(&Enterp, &tmpPtr, sizeof(tmpPtr)); + + probeBlockEnd(); + } + + if ((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { + setProbePoint(&probeInfo); + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", LC_SYNC, + probeInfo.eventIndex, "Monitor::Enter", + probeInfo.currentTime, probeInfo.pID, probeInfo.tID); + //Input,ret + log.length += sprintf(log.data + log.length, "`,`,"); + //PCAddr,errno,InternalCall,CallerPCAddr,SyncVal,SyncType,ApiType + log.length += sprintf(log.data + log.length, + "`,0`,0`,%d`,%u`,0x%x`,%d`,%d",blockresult, + (unsigned int)CALLER_ADDRESS, (unsigned int) this, SYNC_TIZEN_MONITOR, SYNC_API_ACQUIRE_WAIT_START); + //callstack + log.length += sprintf(log.data + log.length, "`,\ncallstack_start`,"); + getBacktraceString(&log, 4096 - log.length - 17); + log.length += sprintf(log.data + log.length, "`,callstack_end"); + + printLog(&log, MSG_LOG); + preBlockEnd(); + } + // + ret = (this->*Enterp)(); + // + if (postBlockBegin(blockresult)) { + setProbePoint(&probeInfo); + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", LC_SYNC, + probeInfo.eventIndex, "Monitor::Enter", + probeInfo.currentTime, probeInfo.pID, probeInfo.tID); + //Input,ret + log.length += sprintf(log.data + log.length, "`,`,%ld", ret); + //PCAddr,errno,InternalCall,CallerPCAddr,SyncVal,SyncType,ApiType + log.length += sprintf(log.data + log.length, + "`,0`,%lu`,%d`,%u`,0x%x`,%d`,%d", ret, blockresult, + (unsigned int)CALLER_ADDRESS, (unsigned int) this, SYNC_TIZEN_MONITOR, SYNC_API_ACQUIRE_WAIT_END); + //callstack + log.length += sprintf(log.data + log.length, "`,\ncallstack_start`,"); + getBacktraceString(&log, 4096 - log.length - 17); + log.length += sprintf(log.data + log.length, "`,callstack_end"); + + printLog(&log, MSG_LOG); + postBlockEnd(); + } + return ret; +} + +result Monitor::Exit(void) { + typedef result + (Monitor::*methodType)(void); + static methodType Exitp = 0; + result ret; + probeInfo_t probeInfo; + log_t log; + int blockresult; + bool bfiltering = true; + void *tmpPtr; + + if (!Exitp) { + probeBlockStart(); + if(lib_handle[LIBOSP_APPFW] == NULL) { + lib_handle[LIBOSP_APPFW] = dlopen(lib_string[LIBOSP_APPFW], RTLD_LAZY); + if (lib_handle[LIBOSP_APPFW] == NULL) { + perror("dlopen failed : libosp-appfw.so"); + exit(0); + } + } + tmpPtr = dlsym(lib_handle[LIBOSP_APPFW], "_ZN5Tizen4Base7Runtime7Monitor4ExitEv"); + + if (tmpPtr == NULL || dlerror() != NULL) { + perror("dlsym failed : Tizen::Base::Runtime::Monitor::Exit"); + exit(0); + } + + memcpy(&Exitp, &tmpPtr, sizeof(tmpPtr)); + + probeBlockEnd(); + } + + if ((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { + setProbePoint(&probeInfo); + preBlockEnd(); + } + // + ret = (this->*Exitp)(); + // + if (postBlockBegin(blockresult)) { + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", LC_SYNC, + probeInfo.eventIndex, "Monitor::Exit", + probeInfo.currentTime, probeInfo.pID, probeInfo.tID); + //Input,ret + log.length += sprintf(log.data + log.length, "`,`,%ld", ret); + //PCAddr,errno,InternalCall,CallerPCAddr,SyncVal,SyncType,ApiType + log.length += sprintf(log.data + log.length, + "`,0`,%lu`,%d`,%u`,0x%x`,%d`,%d", ret, blockresult, + (unsigned int)CALLER_ADDRESS, (unsigned int) this, SYNC_TIZEN_MONITOR, SYNC_API_RELEASE); + //callstack + log.length += sprintf(log.data + log.length, "`,\ncallstack_start`,"); + getBacktraceString(&log, 4096 - log.length - 17); + log.length += sprintf(log.data + log.length, "`,callstack_end"); + + printLog(&log, MSG_LOG); + postBlockEnd(); + } + return ret; +} + +result Monitor::Wait(void) { + typedef result + (Monitor::*methodType)(void); + static methodType Waitp = 0; + result ret; + probeInfo_t probeInfo; + log_t log; + int blockresult; + bool bfiltering = true; + void *tmpPtr; + + if (!Waitp) { + probeBlockStart(); + if(lib_handle[LIBOSP_APPFW] == NULL) { + lib_handle[LIBOSP_APPFW] = dlopen(lib_string[LIBOSP_APPFW], RTLD_LAZY); + if (lib_handle[LIBOSP_APPFW] == NULL) { + perror("dlopen failed : libosp-appfw.so"); + exit(0); + } + } + tmpPtr = dlsym(lib_handle[LIBOSP_APPFW], "_ZN5Tizen4Base7Runtime7Monitor4WaitEv"); + + if (tmpPtr == NULL || dlerror() != NULL) { + perror("dlsym failed : Tizen::Base::Runtime::Monitor::Wait"); + exit(0); + } + + memcpy(&Waitp, &tmpPtr, sizeof(tmpPtr)); + + probeBlockEnd(); + } + + if ((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { + setProbePoint(&probeInfo); + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", LC_SYNC, + probeInfo.eventIndex, "Monitor::Wait", + probeInfo.currentTime, probeInfo.pID, probeInfo.tID); + //Input,ret + log.length += sprintf(log.data + log.length, "`,`,"); + //PCAddr,errno,InternalCall,CallerPCAddr,SyncVal,SyncType,ApiType + log.length += sprintf(log.data + log.length, + "`,0`,0`,%d`,%u`,0x%x`,%d`,%d",blockresult, + (unsigned int)CALLER_ADDRESS, (unsigned int) this, SYNC_TIZEN_MONITOR, SYNC_API_COND_WAIT_START); + //callstack + log.length += sprintf(log.data + log.length, "`,\ncallstack_start`,"); + getBacktraceString(&log, 4096 - log.length - 17); + log.length += sprintf(log.data + log.length, "`,callstack_end"); + + printLog(&log, MSG_LOG); + preBlockEnd(); + } + // + ret = (this->*Waitp)(); + // + if (postBlockBegin(blockresult)) { + setProbePoint(&probeInfo); + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", LC_SYNC, + probeInfo.eventIndex, "Monitor::Wait", + probeInfo.currentTime, probeInfo.pID, probeInfo.tID); + //Input,ret + log.length += sprintf(log.data + log.length, "`,`,%ld", ret); + //PCAddr,errno,InternalCall,CallerPCAddr,SyncVal,SyncType,ApiType + log.length += sprintf(log.data + log.length, + "`,0`,%lu`,%d`,%u`,0x%x`,%d`,%d", ret, blockresult, + (unsigned int)CALLER_ADDRESS, (unsigned int) this, SYNC_TIZEN_MONITOR, SYNC_API_COND_WAIT_END); + //callstack + log.length += sprintf(log.data + log.length, "`,\ncallstack_start`,"); + getBacktraceString(&log, 4096 - log.length - 17); + log.length += sprintf(log.data + log.length, "`,callstack_end"); + + printLog(&log, MSG_LOG); + postBlockEnd(); + } + return ret; +} + +result Monitor::Notify(void) { + typedef result + (Monitor::*methodType)(void); + static methodType Notifyp = 0; + result ret; + probeInfo_t probeInfo; + log_t log; + int blockresult; + bool bfiltering = true; + void *tmpPtr; + + if (!Notifyp) { + probeBlockStart(); + if(lib_handle[LIBOSP_APPFW] == NULL) { + lib_handle[LIBOSP_APPFW] = dlopen(lib_string[LIBOSP_APPFW], RTLD_LAZY); + if (lib_handle[LIBOSP_APPFW] == NULL) { + perror("dlopen failed : libosp-appfw.so"); + exit(0); + } + } + tmpPtr = dlsym(lib_handle[LIBOSP_APPFW], "_ZN5Tizen4Base7Runtime7Monitor6NotifyEv"); + + if (tmpPtr == NULL || dlerror() != NULL) { + perror("dlsym failed : Tizen::Base::Runtime::Monitor::Notify"); + exit(0); + } + + memcpy(&Notifyp, &tmpPtr, sizeof(tmpPtr)); + + probeBlockEnd(); + } + + if ((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { + setProbePoint(&probeInfo); + preBlockEnd(); + } + // + ret = (this->*Notifyp)(); + // + if (postBlockBegin(blockresult)) { + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", LC_SYNC, + probeInfo.eventIndex, "Monitor::Notify", + probeInfo.currentTime, probeInfo.pID, probeInfo.tID); + //Input,ret + log.length += sprintf(log.data + log.length, "`,`,%ld", ret); + //PCAddr,errno,InternalCall,CallerPCAddr,SyncVal,SyncType,ApiType + log.length += sprintf(log.data + log.length, + "`,0`,%lu`,%d`,%u`,0x%x`,%d`,%d", ret, blockresult, + (unsigned int)CALLER_ADDRESS, (unsigned int) this, SYNC_TIZEN_MONITOR, SYNC_API_NOTIFY); + //callstack + log.length += sprintf(log.data + log.length, "`,\ncallstack_start`,"); + getBacktraceString(&log, 4096 - log.length - 17); + log.length += sprintf(log.data + log.length, "`,callstack_end"); + + printLog(&log, MSG_LOG); + postBlockEnd(); + } + return ret; +} + +result Monitor::NotifyAll(void) { + typedef result + (Monitor::*methodType)(void); + static methodType NotifyAllp = 0; + result ret; + probeInfo_t probeInfo; + log_t log; + int blockresult; + bool bfiltering = true; + void *tmpPtr; + + if (!NotifyAllp) { + probeBlockStart(); + if(lib_handle[LIBOSP_APPFW] == NULL) { + lib_handle[LIBOSP_APPFW] = dlopen(lib_string[LIBOSP_APPFW], RTLD_LAZY); + if (lib_handle[LIBOSP_APPFW] == NULL) { + perror("dlopen failed : libosp-appfw.so"); + exit(0); + } + } + tmpPtr = dlsym(lib_handle[LIBOSP_APPFW], "_ZN5Tizen4Base7Runtime7Monitor9NotifyAllEv"); + + if (tmpPtr == NULL || dlerror() != NULL) { + perror("dlsym failed : Tizen::Base::Runtime::Monitor::NotifyAll"); + exit(0); + } + + memcpy(&NotifyAllp, &tmpPtr, sizeof(tmpPtr)); + + probeBlockEnd(); + } + + if ((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { + setProbePoint(&probeInfo); + preBlockEnd(); + } + // + ret = (this->*NotifyAllp)(); + // + if (postBlockBegin(blockresult)) { + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", LC_SYNC, + probeInfo.eventIndex, "Monitor::NotifyAll", + probeInfo.currentTime, probeInfo.pID, probeInfo.tID); + //Input,ret + log.length += sprintf(log.data + log.length, "`,`,%ld", ret); + //PCAddr,errno,InternalCall,CallerPCAddr,SyncVal,SyncType,ApiType + log.length += sprintf(log.data + log.length, + "`,0`,%lu`,%d`,%u`,0x%x`,%d`,%d", ret, blockresult, + (unsigned int)CALLER_ADDRESS, (unsigned int) this, SYNC_TIZEN_MONITOR, SYNC_API_NOTIFY_ALL); + //callstack + log.length += sprintf(log.data + log.length, "`,\ncallstack_start`,"); + getBacktraceString(&log, 4096 - log.length - 17); + log.length += sprintf(log.data + log.length, "`,callstack_end"); + + printLog(&log, MSG_LOG); + postBlockEnd(); + } + return ret; +} + +} +} +} diff --git a/probe_tizenapi/tizen_thread.cpp b/probe_tizenapi/tizen_thread.cpp new file mode 100755 index 0000000..cb9fdb3 --- /dev/null +++ b/probe_tizenapi/tizen_thread.cpp @@ -0,0 +1,1737 @@ +/* + * DA probe + * + * Copyright (Thread::*c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Woojin Jung + * Yeongtaik Byeon + * Jaewon Lim + * Juyoung Kim + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#include +#include "daprobe.h" +#include "probeinfo.h" +#include "dahelper.h" + +static enum DaOptions _sopt = OPT_THREAD; + +namespace Tizen { +namespace Base { +namespace Runtime { + +class _ThreadImpl { +//public: +// virtual result Stop(void); +protected: +// virtual result Finalize(void); + const Thread* GetThread(void) const; +private: + static void* ThreadProc(void* pParam); +//protected: +// Thread* _pThread; +}; +//const Thread* +//_ThreadImpl::GetThread(void) const +//{ +// typedef const Thread* +// (_ThreadImpl::*methodType)(void) const; +// static methodType GetThreadp = 0; +// probeInfo_t probeInfo; +// log_t log; +// int blockresult; +// bool bfiltering = false; +// void *tmpPtr; +// +// if (!GetThreadp) { +// probeBlockStart(); +// void* lib_handle = dlopen("libosp-appfw.so", RTLD_LAZY); +// if (lib_handle == NULL) { +// perror("dlopen failed : libosp-appfw.so"); +// exit(0); +// } +// tmpPtr = dlsym(lib_handle, "_ZNK5Tizen4Base7Runtime11_ThreadImpl9GetThreadEv"); +// +// if (tmpPtr == NULL || dlerror() != NULL) { +// perror("dlsym failed : Tizen::Base::Runtime::_ThreadImpl::GetThreadp"); +// exit(0); +// } +// +// memcpy(&GetThreadp, &tmpPtr, sizeof(tmpPtr)); +// +// probeBlockEnd(); +// } +// +// if ((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { +// setProbePoint(&probeInfo); +// preBlockEnd(); +// } +// // +// const Thread* ret = (this->*GetThreadp)(); +// result res = GetLastResult(); +// // +// if (postBlockBegin(blockresult)) { +// log.type = 0; +// log.length = 0; +// log.data[0] = '\0'; +// log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", LC_THREAD, +// probeInfo.eventIndex, "_ThreadImpl::GetThread", probeInfo.currentTime, +// probeInfo.pID, probeInfo.tID); +// +// //Input,ret +// log.length += sprintf(log.data + log.length, "`,`,0x%x",ret); +// //PCAddr,errno,InternalCall,size,FD,FDType,FDApiType,FileSize,FilePath +// log.length += sprintf(log.data + log.length, +// "`,0`,%ld`,%d`,0`,%u`,0x%x`,%d`,%d`,`,", res,blockresult, +// (unsigned int)CALLER_ADDRESS, (unsigned int) this, THREAD_TIZENTHREAD_WORKER, THREAD_API_OTHER); +// //callstack +// log.length += sprintf(log.data + log.length, "`,\ncallstack_start`,"); +// getBacktraceString(&log, 4096 - log.length - 17); +// log.length += sprintf(log.data + log.length, "`,callstack_end"); +// +// printLog(&log, MSG_LOG); +// postBlockEnd(); +// } +// return ret; +//} + +void* +_ThreadImpl::ThreadProc(void* params) { + typedef void* + (*methodType)(void*); + static methodType ThreadProcp = 0; + probeInfo_t probeInfo; + log_t log; + int blockresult; + bool bfiltering = false; + void *tmpPtr; + + if (!ThreadProcp) { + probeBlockStart(); + if(lib_handle[LIBOSP_APPFW] == NULL) { + lib_handle[LIBOSP_APPFW] = dlopen(lib_string[LIBOSP_APPFW], RTLD_LAZY); + if (lib_handle[LIBOSP_APPFW] == NULL) { + perror("dlopen failed : libosp-appfw.so"); + exit(0); + } + } + tmpPtr = dlsym(lib_handle[LIBOSP_APPFW], "_ZN5Tizen4Base7Runtime11_ThreadImpl10ThreadProcEPv"); + + if (tmpPtr == NULL || dlerror() != NULL) { + perror("dlsym failed : Tizen::Base::Runtime::_ThreadImpl::ThreadProc"); + exit(0); + } + + memcpy(&ThreadProcp, &tmpPtr, sizeof(tmpPtr)); + + probeBlockEnd(); + } + + if ((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { + setProbePoint(&probeInfo); + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", LC_THREAD, + probeInfo.eventIndex, "_ThreadImpl::ThreadProc", probeInfo.currentTime, + probeInfo.pID, probeInfo.tID); + + _ThreadImpl* pSelf =(_ThreadImpl*)params; + const Thread* pThread = NULL; + if(pSelf != null){ + pThread = pSelf->GetThread(); + } + //Input,ret + log.length += sprintf(log.data + log.length, "`,0x%x`,",(unsigned int)pSelf); + //PCAddr,errno,InternalCall,CallerPCAddr,PThreadID,TizenThreadID,ThreadType,ApiType + log.length += sprintf(log.data + log.length, + "`,0`,0`,%d`,%u`,`,0x%x`,%d`,%d", blockresult, + (unsigned int)CALLER_ADDRESS, (unsigned int)pThread, THREAD_TIZENTHREAD_WORKER, THREAD_API_INTERNAL_START); + //callstack + log.length += sprintf(log.data + log.length, "`,\ncallstack_start`,"); + log.length += sprintf(log.data + log.length, "`,callstack_end"); + + printLog(&log, MSG_LOG); + preBlockEnd(); + } + // all probe should be reachable inside thread start_routine (user implemented Thread::Run) + probingEnd(); + (ThreadProcp)(params); + probingStart(); + // + if (postBlockBegin(blockresult)) { + setProbePoint(&probeInfo); + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", LC_THREAD, + probeInfo.eventIndex, "_ThreadImpl::ThreadProc", probeInfo.currentTime, + probeInfo.pID, probeInfo.tID); + + _ThreadImpl* pSelf =(_ThreadImpl*)params; + const Thread* pThread = NULL; + if(pSelf != null){ + pThread = pSelf->GetThread(); + } + //Input,ret + log.length += sprintf(log.data + log.length, "`,0x%x`,",(unsigned int)pSelf); + //PCAddr,errno,InternalCall,CallerPCAddr,PThreadID,TizenThreadID,ThreadType,ApiType + log.length += sprintf(log.data + log.length, + "`,0`,0`,%d`,%u`,`,0x%x`,%d`,%d", blockresult, + (unsigned int)CALLER_ADDRESS, (unsigned int)pThread, THREAD_TIZENTHREAD_WORKER, THREAD_API_INTERNAL_STOP); + //callstack + log.length += sprintf(log.data + log.length, "`,\ncallstack_start`,"); + log.length += sprintf(log.data + log.length, "`,callstack_end"); + + printLog(&log, MSG_LOG); + postBlockEnd(); + } + return null; +} +//result _ThreadImpl::Stop(void) { +// typedef result +// (_ThreadImpl::*methodType)(void); +// static methodType Stopp = 0; +// probeInfo_t probeInfo; +// log_t log; +// int blockresult; +// bool bfiltering = true; +// void *tmpPtr; +// +// if (!Stopp) { +// probeBlockStart(); +// void* lib_handle = dlopen("libosp-appfw.so", RTLD_LAZY); +// if (lib_handle == NULL) { +// perror("dlopen failed : libosp-appfw.so"); +// exit(0); +// } +// tmpPtr = dlsym(lib_handle, "_ZN5Tizen4Base7Runtime11_ThreadImpl4StopEv"); +// +// if (tmpPtr == NULL || dlerror() != NULL) { +// perror("dlsym failed : Tizen::Base::Runtime::_ThreadImpl::Stopp"); +// exit(0); +// } +// +// memcpy(&Stopp, &tmpPtr, sizeof(tmpPtr)); +// +// probeBlockEnd(); +// } +// +// if ((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { +// setProbePoint(&probeInfo); +// preBlockEnd(); +// } +// // +// result ret= (this->*Stopp)(); +// // +// if (postBlockBegin(blockresult)) { +// log.type = 0; +// log.length = 0; +// log.data[0] = '\0'; +// log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", LC_THREAD, +// probeInfo.eventIndex, "_ThreadImpl::Stop", probeInfo.currentTime, +// probeInfo.pID, probeInfo.tID); +// //Input,ret +// log.length += sprintf(log.data + log.length, "`,`,%ld", ret); +// //PCAddr,errno,InternalCall,size,FD,FDType,FDApiType,FileSize,FilePath +// log.length += sprintf(log.data + log.length, +// "`,0`,%ld`,%d`,0`,%u`,0x%x`,%d`,%d`,`,", ret, blockresult, +// (unsigned int)CALLER_ADDRESS, (unsigned int) this, THREAD_TIZENTHREAD_WORKER, THREAD_API_CLOSE); +// //callstack +// log.length += sprintf(log.data + log.length, "`,\ncallstack_start`,"); +// getBacktraceString(&log, 4096 - log.length - 17); +// log.length += sprintf(log.data + log.length, "`,callstack_end"); +// +// printLog(&log, MSG_LOG); +// postBlockEnd(); +// } +// return ret; +//} +// +//result _ThreadImpl::Finalize(void) { +// typedef result +// (_ThreadImpl::*methodType)(void); +// static methodType Finalizep = 0; +// probeInfo_t probeInfo; +// log_t log; +// int blockresult; +// bool bfiltering = false; +// void *tmpPtr; +// +// if (!Finalizep) { +// probeBlockStart(); +// void* lib_handle = dlopen("libosp-appfw.so", RTLD_LAZY); +// if (lib_handle == NULL) { +// perror("dlopen failed : libosp-appfw.so"); +// exit(0); +// } +// tmpPtr = dlsym(lib_handle, "_ZN5Tizen4Base7Runtime11_ThreadImpl8FinalizeEv"); +// +// if (tmpPtr == NULL || dlerror() != NULL) { +// perror("dlsym failed : Tizen::Base::Runtime::_ThreadImpl::Finalizep"); +// exit(0); +// } +// +// memcpy(&Finalizep, &tmpPtr, sizeof(tmpPtr)); +// probeBlockEnd(); +// } +// +// if ((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { +// setProbePoint(&probeInfo); +// preBlockEnd(); +// } +// // +// result ret= (this->*Finalizep)(); +// // +// if (postBlockBegin(blockresult)) { +// log.type = 0; +// log.length = 0; +// log.data[0] = '\0'; +// log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", LC_THREAD, +// probeInfo.eventIndex, "_ThreadImpl::Finalize", probeInfo.currentTime, +// probeInfo.pID, probeInfo.tID); +// //Input,ret +// log.length += sprintf(log.data + log.length, "`,`,%ld", ret); +// //PCAddr,errno,InternalCall,size,FD,FDType,FDApiType,FileSize,FilePath +// log.length += sprintf(log.data + log.length, +// "`,0`,%ld`,%d`,0`,%u`,0x%x`,%d`,%d`,`,", ret, blockresult, +// (unsigned int)CALLER_ADDRESS, (unsigned int) this, THREAD_TIZENTHREAD_WORKER, THREAD_API_CLOSE); +// //callstack +// log.length += sprintf(log.data + log.length, "`,\ncallstack_start`,"); +// getBacktraceString(&log, 4096 - log.length - 17); +// log.length += sprintf(log.data + log.length, "`,callstack_end"); +// +// printLog(&log, MSG_LOG); +// postBlockEnd(); +// } +// return ret; +//} +//Thread::Thread(void) { +// typedef void (Thread::*methodType)(); +// static methodType Threadp = 0; +// probeInfo_t probeInfo; +// log_t log; +// int blockresult; +// bool bfiltering = true; +// void *tmpPtr; +// +// if (!Threadp) { +// probeBlockStart(); +// +// tmpPtr = dlsym(RTLD_NEXT, "_ZN5Tizen4Base7Runtime6ThreadC1Ev"); +// +// if (tmpPtr == NULL || dlerror() != NULL) { +// log.type = 0; +// log.length = 0; +// log.data[0] = '\0'; +// log.length = sprintf(log.data,"dlsym failed : Tizen::Base::Runtime::Thread::Thread"); +// perror("dlsym failed : Tizen::Base::Runtime::Thread::Thread"); +// printLog(&log, MSG_MSG); +// return; +// } +// +// memcpy(&Threadp, &tmpPtr, sizeof(tmpPtr)); +// probeBlockEnd(); +// } +// +// if ((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { +// setProbePoint(&probeInfo); +// preBlockEnd(); +// } +//// +// (this->*Threadp)(); +//// +// if (postBlockBegin(blockresult)) { +// log.type = 0; +// log.length = 0; +// log.data[0] = '\0'; +// log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", LC_THREAD, +// probeInfo.eventIndex, "Thread::Thread", probeInfo.currentTime, +// probeInfo.pID, probeInfo.tID); +// //Input,ret +// log.length += sprintf(log.data + log.length, "`,`,"); +// //PCAddr,errno,InternalCall,size,FD,FDType,FDApiType,FileSize,FilePath +// +// log.length += sprintf(log.data + log.length, +// "`,0`,0`,%d`,0`,0x%x`,%d`,%d`,`,", blockresult, +// (unsigned int) this, THREAD_TIZENTHREAD_WORKER, THREAD_API_OPEN); +// //callstack +// log.length += sprintf(log.data + log.length, "`,\ncallstack_start`,"); +// getBacktraceString(&log, 4096 - log.length - 17); +// log.length += sprintf(log.data + log.length, "`,callstack_end"); +// +// printLog(&log, MSG_LOG); +// postBlockEnd(); +// } +//} +// +//Thread::~Thread(void) { +// typedef void (Thread::*methodType)(); +// static methodType ThreadDp = 0; +// probeInfo_t probeInfo; +// log_t log; +// int blockresult; +// bool bfiltering = true; +// void *tmpPtr; +// +// if (!ThreadDp) { +// probeBlockStart(); +// +// void* lib_handle = dlopen("libosp-appfw.so", RTLD_LAZY); +// if (lib_handle == NULL) { +// perror("dlopen failed : libosp-appfw.so"); +// exit(0); +// } +// tmpPtr = dlsym(lib_handle, "_ZN5Tizen4Base7Runtime6ThreadD0Ev"); +// +// if (tmpPtr == NULL || dlerror() != NULL) { +// perror("dlsym failed : Tizen::Base::Runtime::Thread::~Thread"); +// exit(0); +// } +// +// memcpy(&ThreadDp, &tmpPtr, sizeof(tmpPtr)); +// probeBlockEnd(); +// } +// +// if ((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { +// setProbePoint(&probeInfo); +// preBlockEnd(); +// } +//// +// (this->*ThreadDp)(); +//// +// if (postBlockBegin(blockresult)) { +// log.type = 0; +// log.length = 0; +// log.data[0] = '\0'; +// log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", LC_THREAD, +// probeInfo.eventIndex, "Thread::~Thread", probeInfo.currentTime, +// probeInfo.pID, probeInfo.tID); +// //Input,ret +// log.length += sprintf(log.data + log.length, "`,`,"); +// //PCAddr,errno,InternalCall,size,FD,FDType,FDApiType,FileSize,FilePath +// +// log.length += sprintf(log.data + log.length, +// "`,0`,0`,%d`,0`,0x%x`,%d`,%d`,`,", blockresult, +// (unsigned int) this, THREAD_TIZENTHREAD_WORKER, THREAD_API_CLOSE); +// //callstack +// log.length += sprintf(log.data + log.length, "`,\ncallstack_start`,"); +// getBacktraceString(&log, 4096 - log.length - 17); +// log.length += sprintf(log.data + log.length, "`,callstack_end"); +// +// printLog(&log, MSG_LOG); +// postBlockEnd(); +// } +//} +result Thread::Sleep(long milliSeconds) { + typedef result + (*methodType)(long); + static methodType Sleepp = 0; + probeInfo_t probeInfo; + log_t log; + int blockresult; + bool bfiltering = true; + void *tmpPtr; + + if (!Sleepp) { + probeBlockStart(); + if(lib_handle[LIBOSP_APPFW] == NULL) { + lib_handle[LIBOSP_APPFW] = dlopen(lib_string[LIBOSP_APPFW], RTLD_LAZY); + if (lib_handle[LIBOSP_APPFW] == NULL) { + perror("dlopen failed : libosp-appfw.so"); + exit(0); + } + } + tmpPtr = dlsym(lib_handle[LIBOSP_APPFW], "_ZN5Tizen4Base7Runtime6Thread5SleepEl"); + + if (tmpPtr == NULL || dlerror() != NULL) { + perror("dlsym failed : Tizen::Base::Runtime::Thread::Sleep"); + exit(0); + } + + memcpy(&Sleepp, &tmpPtr, sizeof(tmpPtr)); + + probeBlockEnd(); + } + + if ((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { + setProbePoint(&probeInfo); + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", LC_THREAD, + probeInfo.eventIndex, "Thread::Sleep", probeInfo.currentTime, + probeInfo.pID, probeInfo.tID); + + Thread *currentThread; + currentThread = GetCurrentThread(); + + //Input,ret + log.length += sprintf(log.data + log.length, "`,%ld`,",milliSeconds); + //PCAddr,errno,InternalCall,CallerPCAddr,PThreadID,TizenThreadID,ThreadType,ApiType + log.length += sprintf(log.data + log.length, + "`,0`,0`,%d`,%u`,`,0x%x`,%d`,%d",blockresult, + (unsigned int)CALLER_ADDRESS, (unsigned int)currentThread, THREAD_TIZENTHREAD_WORKER, THREAD_API_WAIT_START); + //callstack + log.length += sprintf(log.data + log.length, "`,\ncallstack_start`,"); + log.length += sprintf(log.data + log.length, "`,callstack_end"); + + printLog(&log, MSG_LOG); + preBlockEnd(); + } + // + result ret = (Sleepp)(milliSeconds); + // + if (postBlockBegin(blockresult)) { + setProbePoint(&probeInfo); + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", LC_THREAD, + probeInfo.eventIndex, "Thread::Sleep", probeInfo.currentTime, + probeInfo.pID, probeInfo.tID); + + Thread *currentThread; + currentThread = GetCurrentThread(); + + //Input,ret + log.length += sprintf(log.data + log.length, "`,%ld`,%ld",milliSeconds,ret); + //PCAddr,errno,InternalCall,CallerPCAddr,PThreadID,TizenThreadID,ThreadType,ApiType + log.length += sprintf(log.data + log.length, + "`,0`,%lu`,%d`,%u`,`,0x%x`,%d`,%d", ret,blockresult, + (unsigned int)CALLER_ADDRESS, (unsigned int)currentThread, THREAD_TIZENTHREAD_WORKER, THREAD_API_WAIT_END); + //callstack + log.length += sprintf(log.data + log.length, "`,\ncallstack_start`,"); + getBacktraceString(&log, 4096 - log.length - 17); + log.length += sprintf(log.data + log.length, "`,callstack_end"); + + printLog(&log, MSG_LOG); + postBlockEnd(); + } + return ret; +} + +Thread* Thread::GetCurrentThread(void) { + typedef Thread* + (*methodType)(void); + static methodType GetCurrentThreadp = 0; + probeInfo_t probeInfo; + log_t log; + int blockresult; + bool bfiltering = true; + void *tmpPtr; + + if (!GetCurrentThreadp) { + probeBlockStart(); + if(lib_handle[LIBOSP_APPFW] == NULL) { + lib_handle[LIBOSP_APPFW] = dlopen(lib_string[LIBOSP_APPFW], RTLD_LAZY); + if (lib_handle[LIBOSP_APPFW] == NULL) { + perror("dlopen failed : libosp-appfw.so"); + exit(0); + } + } + tmpPtr = dlsym(lib_handle[LIBOSP_APPFW], "_ZN5Tizen4Base7Runtime6Thread16GetCurrentThreadEv"); + + if (tmpPtr == NULL || dlerror() != NULL) { + perror("dlsym failed : Tizen::Base::Runtime::Thread::GetCurrentThread"); + exit(0); + } + + memcpy(&GetCurrentThreadp, &tmpPtr, sizeof(tmpPtr)); + + probeBlockEnd(); + } + + if ((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { + setProbePoint(&probeInfo); + preBlockEnd(); + } + // + Thread *currentThread = (GetCurrentThreadp)(); + result res = GetLastResult(); + // + if (postBlockBegin(blockresult)) { + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", LC_THREAD, + probeInfo.eventIndex, "Thread::GetCurrentThread", probeInfo.currentTime, + probeInfo.pID, probeInfo.tID); + + //Input,ret + log.length += sprintf(log.data + log.length, "`,`,0x%x",(unsigned int)currentThread); + //PCAddr,errno,InternalCall,CallerPCAddr,PThreadID,TizenThreadID,ThreadType,ApiType + log.length += sprintf(log.data + log.length, + "`,0`,%lu`,%d`,%u`,`,0x%x`,%d`,%d", res,blockresult, + (unsigned int)CALLER_ADDRESS, (unsigned int)currentThread, THREAD_TIZENTHREAD_WORKER, THREAD_API_OTHER); + //callstack + log.length += sprintf(log.data + log.length, "`,\ncallstack_start`,"); + getBacktraceString(&log, 4096 - log.length - 17); + log.length += sprintf(log.data + log.length, "`,callstack_end"); + + printLog(&log, MSG_LOG); + postBlockEnd(); + } + return currentThread; +} + +result Thread::Yield(void) { + typedef result + (*methodType)(void); + static methodType Yieldp = 0; + probeInfo_t probeInfo; + log_t log; + int blockresult; + bool bfiltering = true; + void *tmpPtr; + + if (!Yieldp) { + probeBlockStart(); + if(lib_handle[LIBOSP_APPFW] == NULL) { + lib_handle[LIBOSP_APPFW] = dlopen(lib_string[LIBOSP_APPFW], RTLD_LAZY); + if (lib_handle[LIBOSP_APPFW] == NULL) { + perror("dlopen failed : libosp-appfw.so"); + exit(0); + } + } + tmpPtr = dlsym(lib_handle[LIBOSP_APPFW], "_ZN5Tizen4Base7Runtime6Thread5YieldEv"); + + if (tmpPtr == NULL || dlerror() != NULL) { + perror("dlsym failed : Tizen::Base::Runtime::Thread::Yield"); + exit(0); + } + + memcpy(&Yieldp, &tmpPtr, sizeof(tmpPtr)); + + probeBlockEnd(); + } + + if ((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { + setProbePoint(&probeInfo); + preBlockEnd(); + } + // + result ret = (Yieldp)(); + // + if (postBlockBegin(blockresult)) { + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", LC_THREAD, + probeInfo.eventIndex, "Thread::Yield", probeInfo.currentTime, + probeInfo.pID, probeInfo.tID); + + Thread *currentThread; + currentThread = GetCurrentThread(); + + //Input,ret + log.length += sprintf(log.data + log.length, "`,`,%ld",ret); + //PCAddr,errno,InternalCall,CallerPCAddr,PThreadID,TizenThreadID,ThreadType,ApiType + log.length += sprintf(log.data + log.length, + "`,0`,%lu`,%d`,%u`,`,0x%x`,%d`,%d", ret,blockresult, + (unsigned int)CALLER_ADDRESS, (unsigned int)currentThread, THREAD_TIZENTHREAD_WORKER, THREAD_API_OTHER); + //callstack + log.length += sprintf(log.data + log.length, "`,\ncallstack_start`,"); + getBacktraceString(&log, 4096 - log.length - 17); + log.length += sprintf(log.data + log.length, "`,callstack_end"); + + printLog(&log, MSG_LOG); + postBlockEnd(); + } + return ret; +} + +result Thread::Exit(int exitCode) { + typedef result + (*methodType)(int exitCode); + static methodType Exitp = 0; + probeInfo_t probeInfo; + log_t log; + int blockresult; + bool bfiltering = true; + void *tmpPtr; + + if (!Exitp) { + probeBlockStart(); + if(lib_handle[LIBOSP_APPFW] == NULL) { + lib_handle[LIBOSP_APPFW] = dlopen(lib_string[LIBOSP_APPFW], RTLD_LAZY); + if (lib_handle[LIBOSP_APPFW] == NULL) { + perror("dlopen failed : libosp-appfw.so"); + exit(0); + } + } + tmpPtr = dlsym(lib_handle[LIBOSP_APPFW], "_ZN5Tizen4Base7Runtime6Thread4ExitEi"); + + if (tmpPtr == NULL || dlerror() != NULL) { + perror("dlsym failed : Tizen::Base::Runtime::Thread::Exit"); + exit(0); + } + + memcpy(&Exitp, &tmpPtr, sizeof(tmpPtr)); + + probeBlockEnd(); + } + + if ((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { + setProbePoint(&probeInfo); + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", LC_THREAD, + probeInfo.eventIndex, "Thread::Exit", probeInfo.currentTime, + probeInfo.pID, probeInfo.tID); + + Thread *currentThread; + currentThread = GetCurrentThread(); + + //Input,ret + log.length += sprintf(log.data + log.length, "`,%d`,",exitCode); + //PCAddr,errno,InternalCall,CallerPCAddr,PThreadID,TizenThreadID,ThreadType,ApiType + log.length += sprintf(log.data + log.length, + "`,0`,0`,%d`,%u`,`,0x%x`,%d`,%d",blockresult, + (unsigned int)CALLER_ADDRESS, (unsigned int)currentThread, THREAD_TIZENTHREAD_WORKER, THREAD_API_EXIT); + //callstack + log.length += sprintf(log.data + log.length, "`,\ncallstack_start`,"); + getBacktraceString(&log, 4096 - log.length - 17); + log.length += sprintf(log.data + log.length, "`,callstack_end"); + + printLog(&log, MSG_LOG); + preBlockEnd(); + } + // + result ret = (Exitp)(exitCode); + // + return ret; +} + +result Thread::Construct(ThreadType threadType, long stackSize, + ThreadPriority priority) { + typedef result + (Thread::*methodType)(ThreadType threadType, long stackSize, + ThreadPriority priority); + static methodType Constructp = 0; + result ret; + probeInfo_t probeInfo; + log_t log; + int blockresult; + bool bfiltering = true; + void *tmpPtr; + + if (!Constructp) { + probeBlockStart(); + if(lib_handle[LIBOSP_APPFW] == NULL) { + lib_handle[LIBOSP_APPFW] = dlopen(lib_string[LIBOSP_APPFW], RTLD_LAZY); + if (lib_handle[LIBOSP_APPFW] == NULL) { + perror("dlopen failed : libosp-appfw.so"); + exit(0); + } + } + tmpPtr = + dlsym( + lib_handle[LIBOSP_APPFW], + "_ZN5Tizen4Base7Runtime6Thread9ConstructENS1_10ThreadTypeElNS1_14ThreadPriorityE"); + + if (tmpPtr == NULL || dlerror() != NULL) { + perror("dlsym failed : Tizen::Base::Runtime::Thread::Construct"); + exit(0); + } + + memcpy(&Constructp, &tmpPtr, sizeof(tmpPtr)); + probeBlockEnd(); + } + + if ((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { + setProbePoint(&probeInfo); + preBlockEnd(); + } + // + ret = (this->*Constructp)(threadType, stackSize, priority); + // + if (postBlockBegin(blockresult)) { + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", LC_THREAD, + probeInfo.eventIndex, "Thread::Construct", + probeInfo.currentTime, probeInfo.pID, probeInfo.tID); + //Input,ret + log.length += sprintf(log.data + log.length, "`,%d, %ld, %d`,%ld", + threadType, stackSize, priority, ret); + //PCAddr,errno,InternalCall,CallerPCAddr,PThreadID,TizenThreadID,ThreadType,ApiType + log.length += sprintf(log.data + log.length, + "`,0`,%lu`,%d`,%u`,`,0x%x`,%d`,%d", ret, blockresult, + (unsigned int)CALLER_ADDRESS, (unsigned int) this, THREAD_TIZENTHREAD_WORKER, THREAD_API_NEW); + //callstack + log.length += sprintf(log.data + log.length, "`,\ncallstack_start`,"); + getBacktraceString(&log, 4096 - log.length - 17); + log.length += sprintf(log.data + log.length, "`,callstack_end"); + + printLog(&log, MSG_LOG); + postBlockEnd(); + } + return ret; +} +result Thread::Construct(long stackSize, ThreadPriority priority) { + typedef result + (Thread::*methodType)(long stackSize, ThreadPriority priority); + static methodType Constructp = 0; + result ret; + probeInfo_t probeInfo; + log_t log; + int blockresult; + bool bfiltering = true; + void *tmpPtr; + + if (!Constructp) { + probeBlockStart(); + if(lib_handle[LIBOSP_APPFW] == NULL) { + lib_handle[LIBOSP_APPFW] = dlopen(lib_string[LIBOSP_APPFW], RTLD_LAZY); + if (lib_handle[LIBOSP_APPFW] == NULL) { + perror("dlopen failed : libosp-appfw.so"); + exit(0); + } + } + tmpPtr = dlsym(lib_handle[LIBOSP_APPFW], + "_ZN5Tizen4Base7Runtime6Thread9ConstructElNS1_14ThreadPriorityE"); + if (tmpPtr == NULL || dlerror() != NULL) { + perror("dlsym failed : Tizen::Base::Runtime::Thread::Construct"); + exit(0); + } + + memcpy(&Constructp, &tmpPtr, sizeof(tmpPtr)); + probeBlockEnd(); + } + + if ((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { + setProbePoint(&probeInfo); + preBlockEnd(); + } + // + ret = (this->*Constructp)(stackSize, priority); + // + if (postBlockBegin(blockresult)) { + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", LC_THREAD, + probeInfo.eventIndex, "Thread::Construct", + probeInfo.currentTime, probeInfo.pID, probeInfo.tID); + //Input,ret + log.length += sprintf(log.data + log.length, "`,%ld, %d`,%ld", + stackSize, priority, ret); + //PCAddr,errno,InternalCall,CallerPCAddr,PThreadID,TizenThreadID,ThreadType,ApiType + log.length += sprintf(log.data + log.length, + "`,0`,%lu`,%d`,%u`,`,0x%x`,%d`,%d", ret, blockresult, + (unsigned int)CALLER_ADDRESS, (unsigned int) this, THREAD_TIZENTHREAD_WORKER, THREAD_API_NEW); + //callstack + log.length += sprintf(log.data + log.length, "`,\ncallstack_start`,"); + getBacktraceString(&log, 4096 - log.length - 17); + log.length += sprintf(log.data + log.length, "`,callstack_end"); + + printLog(&log, MSG_LOG); + postBlockEnd(); + } + return ret; +} +result Thread::Construct(const Tizen::Base::String &name, long stackSize, + ThreadPriority priority) { + typedef result + (Thread::*methodType)(const Tizen::Base::String &name, long stackSize, + ThreadPriority priority); + static methodType Constructp = 0; + result ret; + probeInfo_t probeInfo; + log_t log; + int blockresult; + bool bfiltering = true; + void *tmpPtr; + char temp[50]; + + if (!Constructp) { + probeBlockStart(); + if(lib_handle[LIBOSP_APPFW] == NULL) { + lib_handle[LIBOSP_APPFW] = dlopen(lib_string[LIBOSP_APPFW], RTLD_LAZY); + if (lib_handle[LIBOSP_APPFW] == NULL) { + perror("dlopen failed : libosp-appfw.so"); + exit(0); + } + } + tmpPtr = + dlsym( + lib_handle[LIBOSP_APPFW], + "_ZN5Tizen4Base7Runtime6Thread9ConstructERKNS0_6StringElNS1_14ThreadPriorityE"); + + if (tmpPtr == NULL || dlerror() != NULL) { + perror("dlsym failed : Tizen::Base::Runtime::Thread::Construct"); + exit(0); + } + + memcpy(&Constructp, &tmpPtr, sizeof(tmpPtr)); + probeBlockEnd(); + } + + if ((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { + setProbePoint(&probeInfo); + preBlockEnd(); + } + // + ret = (this->*Constructp)(name, stackSize, priority); + // + if (postBlockBegin(blockresult)) { + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", LC_THREAD, + probeInfo.eventIndex, "Thread::Construct", + probeInfo.currentTime, probeInfo.pID, probeInfo.tID); + //Input,ret + WcharToChar(temp, name.GetPointer()); + log.length += sprintf(log.data + log.length, "`,%s, %ld, %d`,%ld", temp, + stackSize, priority, ret); + //PCAddr,errno,InternalCall,CallerPCAddr,PThreadID,TizenThreadID,ThreadType,ApiType + log.length += sprintf(log.data + log.length, + "`,0`,%lu`,%d`,%u`,`,0x%x`,%d`,%d", ret, blockresult, + (unsigned int)CALLER_ADDRESS, (unsigned int) this, THREAD_TIZENTHREAD_WORKER, THREAD_API_NEW); + //callstack + log.length += sprintf(log.data + log.length, "`,\ncallstack_start`,"); + getBacktraceString(&log, 4096 - log.length - 17); + log.length += sprintf(log.data + log.length, "`,callstack_end"); + + printLog(&log, MSG_LOG); + postBlockEnd(); + } + return ret; +} +result Thread::Construct(const Tizen::Base::String &name, ThreadType threadType, + long stackSize, ThreadPriority priority) { + typedef result + (Thread::*methodType)(const Tizen::Base::String &name, ThreadType threadType, + long stackSize, ThreadPriority priority); + static methodType Constructp = 0; + result ret; + probeInfo_t probeInfo; + log_t log; + int blockresult; + bool bfiltering = true; + void *tmpPtr; + char temp[50]; + + if (!Constructp) { + probeBlockStart(); + if(lib_handle[LIBOSP_APPFW] == NULL) { + lib_handle[LIBOSP_APPFW] = dlopen(lib_string[LIBOSP_APPFW], RTLD_LAZY); + if (lib_handle[LIBOSP_APPFW] == NULL) { + perror("dlopen failed : libosp-appfw.so"); + exit(0); + } + } + + tmpPtr = + dlsym( + lib_handle[LIBOSP_APPFW], + "_ZN5Tizen4Base7Runtime6Thread9ConstructERKNS0_6StringENS1_10ThreadTypeElNS1_14ThreadPriorityE"); + if (tmpPtr == NULL || dlerror() != NULL) { + perror("dlsym failed : Tizen::Base::Runtime::Thread::Construct"); + exit(0); + } + + memcpy(&Constructp, &tmpPtr, sizeof(tmpPtr)); + probeBlockEnd(); + } + + if ((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { + setProbePoint(&probeInfo); + preBlockEnd(); + } + // + ret = (this->*Constructp)(name, threadType, stackSize, priority); + // + if (postBlockBegin(blockresult)) { + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", LC_THREAD, + probeInfo.eventIndex, "Thread::Construct", + probeInfo.currentTime, probeInfo.pID, probeInfo.tID); + //Input,ret + WcharToChar(temp, name.GetPointer()); + log.length += sprintf(log.data + log.length, "`,%s, %d, %ld, %d`,%ld", + temp, threadType, stackSize, priority, ret); + //PCAddr,errno,InternalCall,CallerPCAddr,PThreadID,TizenThreadID,ThreadType,ApiType + log.length += sprintf(log.data + log.length, + "`,0`,%lu`,%d`,%u`,`,0x%x`,%d`,%d", ret, blockresult, + (unsigned int)CALLER_ADDRESS, (unsigned int) this, THREAD_TIZENTHREAD_WORKER, THREAD_API_NEW); + //callstack + log.length += sprintf(log.data + log.length, "`,\ncallstack_start`,"); + getBacktraceString(&log, 4096 - log.length - 17); + log.length += sprintf(log.data + log.length, "`,callstack_end"); + + printLog(&log, MSG_LOG); + postBlockEnd(); + } + return ret; +} +result Thread::Construct(IRunnable &target, long stackSize, + ThreadPriority priority) { + typedef result + (Thread::*methodType)(IRunnable &target, long stackSize, + ThreadPriority priority); + static methodType Constructp = 0; + result ret; + probeInfo_t probeInfo; + log_t log; + int blockresult; + bool bfiltering = true; + void *tmpPtr; + + if (!Constructp) { + probeBlockStart(); + if(lib_handle[LIBOSP_APPFW] == NULL) { + lib_handle[LIBOSP_APPFW] = dlopen(lib_string[LIBOSP_APPFW], RTLD_LAZY); + if (lib_handle[LIBOSP_APPFW] == NULL) { + perror("dlopen failed : libosp-appfw.so"); + exit(0); + } + } + tmpPtr = + dlsym( + lib_handle[LIBOSP_APPFW], + "_ZN5Tizen4Base7Runtime6Thread9ConstructERNS1_9IRunnableElNS1_14ThreadPriorityE"); + + if (tmpPtr == NULL || dlerror() != NULL) { + perror("dlsym failed : Tizen::Base::Runtime::Thread::Construct"); + exit(0); + } + + memcpy(&Constructp, &tmpPtr, sizeof(tmpPtr)); + probeBlockEnd(); + } + + if ((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { + setProbePoint(&probeInfo); + preBlockEnd(); + } + // + ret = (this->*Constructp)(target, stackSize, priority); + // + if (postBlockBegin(blockresult)) { + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", LC_THREAD, + probeInfo.eventIndex, "Thread::Construct", + probeInfo.currentTime, probeInfo.pID, probeInfo.tID); + //Input,ret + log.length += sprintf(log.data + log.length, "`,0x%x, %ld, %d`,%ld", + (unsigned int) &target, stackSize, priority, ret); + //PCAddr,errno,InternalCall,CallerPCAddr,PThreadID,TizenThreadID,ThreadType,ApiType + log.length += sprintf(log.data + log.length, + "`,0`,%lu`,%d`,%u`,`,0x%x`,%d`,%d", ret, blockresult, + (unsigned int)CALLER_ADDRESS, (unsigned int) this, THREAD_TIZENTHREAD_WORKER, THREAD_API_NEW); + //callstack + log.length += sprintf(log.data + log.length, "`,\ncallstack_start`,"); + getBacktraceString(&log, 4096 - log.length - 17); + log.length += sprintf(log.data + log.length, "`,callstack_end"); + + printLog(&log, MSG_LOG); + postBlockEnd(); + } + return ret; +} +result Thread::Construct(const Tizen::Base::String &name, IRunnable &target, + long stackSize, ThreadPriority priority) { + typedef result + (Thread::*methodType)(const Tizen::Base::String &name, IRunnable &target, + long stackSize, ThreadPriority priority); + static methodType Constructp = 0; + result ret; + probeInfo_t probeInfo; + log_t log; + int blockresult; + bool bfiltering = true; + void *tmpPtr; + char temp[50]; + + if (!Constructp) { + probeBlockStart(); + if(lib_handle[LIBOSP_APPFW] == NULL) { + lib_handle[LIBOSP_APPFW] = dlopen(lib_string[LIBOSP_APPFW], RTLD_LAZY); + if (lib_handle[LIBOSP_APPFW] == NULL) { + perror("dlopen failed : libosp-appfw.so"); + exit(0); + } + } + tmpPtr = + dlsym( + lib_handle[LIBOSP_APPFW], + "_ZN5Tizen4Base7Runtime6Thread9ConstructERKNS0_6StringERNS1_9IRunnableElNS1_14ThreadPriorityE"); + + if (tmpPtr == NULL || dlerror() != NULL) { + perror("dlsym failed : Tizen::Base::Runtime::Thread::Construct"); + exit(0); + } + + memcpy(&Constructp, &tmpPtr, sizeof(tmpPtr)); + probeBlockEnd(); + } + + if ((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { + setProbePoint(&probeInfo); + preBlockEnd(); + } + // + ret = (this->*Constructp)(name, target, stackSize, priority); + // + if (postBlockBegin(blockresult)) { + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", LC_THREAD, + probeInfo.eventIndex, "Thread::Construct", + probeInfo.currentTime, probeInfo.pID, probeInfo.tID); + //Input,ret + WcharToChar(temp, name.GetPointer()); + log.length += sprintf(log.data + log.length, "`,%s, 0x%x, %ld, %d`,%ld", + temp, (unsigned int) &target, stackSize, priority, ret); + //PCAddr,errno,InternalCall,CallerPCAddr,PThreadID,TizenThreadID,ThreadType,ApiType + log.length += sprintf(log.data + log.length, + "`,0`,%lu`,%d`,%u`,`,0x%x`,%d`,%d", ret, blockresult, + (unsigned int)CALLER_ADDRESS, (unsigned int) this, THREAD_TIZENTHREAD_WORKER, THREAD_API_NEW); + //callstack + log.length += sprintf(log.data + log.length, "`,\ncallstack_start`,"); + getBacktraceString(&log, 4096 - log.length - 17); + log.length += sprintf(log.data + log.length, "`,callstack_end"); + + printLog(&log, MSG_LOG); + postBlockEnd(); + } + return ret; +} + +result Thread::GetExitCode(int &exitCode) const { + typedef result + (Thread::*methodType)(int &exitCode) const; + static methodType GetExitCodep = 0; + result ret; + probeInfo_t probeInfo; + log_t log; + int blockresult; + bool bfiltering = true; + void *tmpPtr; +// int exitOld = exitCode; + + if (!GetExitCodep) { + probeBlockStart(); + if(lib_handle[LIBOSP_APPFW] == NULL) { + lib_handle[LIBOSP_APPFW] = dlopen(lib_string[LIBOSP_APPFW], RTLD_LAZY); + if (lib_handle[LIBOSP_APPFW] == NULL) { + perror("dlopen failed : libosp-appfw.so"); + exit(0); + } + } + tmpPtr = dlsym(lib_handle[LIBOSP_APPFW], + "_ZNK5Tizen4Base7Runtime6Thread11GetExitCodeERi"); + + if (tmpPtr == NULL || dlerror() != NULL) { + perror("dlsym failed : Tizen::Base::Runtime::Thread::GetExitCode"); + exit(0); + } + + memcpy(&GetExitCodep, &tmpPtr, sizeof(tmpPtr)); + probeBlockEnd(); + } + + if ((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { + setProbePoint(&probeInfo); + preBlockEnd(); + } + // + ret = (this->*GetExitCodep)(exitCode); + // + if (postBlockBegin(blockresult)) { + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", LC_THREAD, + probeInfo.eventIndex, "Thread::GetExitCode", + probeInfo.currentTime, probeInfo.pID, probeInfo.tID); + //Input,ret +// log.length += sprintf(log.data + log.length, "`,(%d->%d)`,%ld", exitOld, +// exitCode, ret); + log.length += sprintf(log.data + log.length, "`,%d`,%ld", exitCode, ret); + //PCAddr,errno,InternalCall,CallerPCAddr,PThreadID,TizenThreadID,ThreadType,ApiType + log.length += sprintf(log.data + log.length, + "`,0`,%lu`,%d`,%u`,`,0x%x`,%d`,%d", ret, blockresult, + (unsigned int)CALLER_ADDRESS, (unsigned int) this, THREAD_TIZENTHREAD_WORKER, THREAD_API_OTHER); + //callstack + log.length += sprintf(log.data + log.length, "`,\ncallstack_start`,"); + getBacktraceString(&log, 4096 - log.length - 17); + log.length += sprintf(log.data + log.length, "`,callstack_end"); + + printLog(&log, MSG_LOG); + postBlockEnd(); + } + return ret; +} + +const Tizen::Base::String & Thread::GetName(void) const { + typedef const Tizen::Base::String & + (Thread::*methodType)(void) const; + static methodType GetNamep = 0; + probeInfo_t probeInfo; + log_t log; + int blockresult; + bool bfiltering = true; + void *tmpPtr; + char temp[50]; + + if (!GetNamep) { + probeBlockStart(); + if(lib_handle[LIBOSP_APPFW] == NULL) { + lib_handle[LIBOSP_APPFW] = dlopen(lib_string[LIBOSP_APPFW], RTLD_LAZY); + if (lib_handle[LIBOSP_APPFW] == NULL) { + perror("dlopen failed : libosp-appfw.so"); + exit(0); + } + } + tmpPtr = dlsym(lib_handle[LIBOSP_APPFW], "_ZNK5Tizen4Base7Runtime6Thread7GetNameEv"); + + if (tmpPtr == NULL || dlerror() != NULL) { + perror("dlsym failed : Tizen::Base::Runtime::Thread::GetName"); + exit(0); + } + + memcpy(&GetNamep, &tmpPtr, sizeof(tmpPtr)); + probeBlockEnd(); + } + + if ((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { + setProbePoint(&probeInfo); + preBlockEnd(); + } + // + const Tizen::Base::String& ret = (this->*GetNamep)(); + result res = GetLastResult(); + // + if (postBlockBegin(blockresult)) { + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", LC_THREAD, + probeInfo.eventIndex, "Thread::GetName", probeInfo.currentTime, + probeInfo.pID, probeInfo.tID); + //Input,ret + WcharToChar(temp, ret.GetPointer()); + log.length += sprintf(log.data + log.length, "`,`,%s", temp); + //PCAddr,errno,InternalCall,CallerPCAddr,PThreadID,TizenThreadID,ThreadType,ApiType + log.length += sprintf(log.data + log.length, + "`,0`,%lu`,%d`,%u`,`,0x%x`,%d`,%d", res, blockresult, + (unsigned int)CALLER_ADDRESS, (unsigned int) this, THREAD_TIZENTHREAD_WORKER, THREAD_API_OTHER); + //callstack + log.length += sprintf(log.data + log.length, "`,\ncallstack_start`,"); + getBacktraceString(&log, 4096 - log.length - 17); + log.length += sprintf(log.data + log.length, "`,callstack_end"); + + printLog(&log, MSG_LOG); + postBlockEnd(); + } + return ret; +} + +result Thread::Join(void) { + typedef result + (Thread::*methodType)(void); + static methodType Joinp = 0; + result ret; + probeInfo_t probeInfo; + log_t log; + int blockresult; + bool bfiltering = true; + void *tmpPtr; + + if (!Joinp) { + probeBlockStart(); + if(lib_handle[LIBOSP_APPFW] == NULL) { + lib_handle[LIBOSP_APPFW] = dlopen(lib_string[LIBOSP_APPFW], RTLD_LAZY); + if (lib_handle[LIBOSP_APPFW] == NULL) { + perror("dlopen failed : libosp-appfw.so"); + exit(0); + } + } + tmpPtr = dlsym(lib_handle[LIBOSP_APPFW], "_ZN5Tizen4Base7Runtime6Thread4JoinEv"); + + if (tmpPtr == NULL || dlerror() != NULL) { + perror("dlsym failed : Tizen::Base::Runtime::Thread::Join"); + exit(0); + } + + memcpy(&Joinp, &tmpPtr, sizeof(tmpPtr)); + probeBlockEnd(); + } + + if ((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { + setProbePoint(&probeInfo); + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", LC_THREAD, + probeInfo.eventIndex, "Thread::Join", probeInfo.currentTime, + probeInfo.pID, probeInfo.tID); + //Input,ret + log.length += sprintf(log.data + log.length, "`,`,"); + //PCAddr,errno,InternalCall,CallerPCAddr,PThreadID,TizenThreadID,ThreadType,ApiType + log.length += sprintf(log.data + log.length, + "`,0`,0`,%d`,%u`,`,0x%x`,%d`,%d",blockresult, + (unsigned int)CALLER_ADDRESS, (unsigned int) this, THREAD_TIZENTHREAD_WORKER, THREAD_API_WAIT_START); + //callstack + log.length += sprintf(log.data + log.length, "`,\ncallstack_start`,"); + log.length += sprintf(log.data + log.length, "`,callstack_end"); + + printLog(&log, MSG_LOG); + preBlockEnd(); + } + // + ret = (this->*Joinp)(); + // + if (postBlockBegin(blockresult)) { + setProbePoint(&probeInfo); + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", LC_THREAD, + probeInfo.eventIndex, "Thread::Join", probeInfo.currentTime, + probeInfo.pID, probeInfo.tID); + //Input,ret + log.length += sprintf(log.data + log.length, "`,`,%ld", ret); + //PCAddr,errno,InternalCall,CallerPCAddr,PThreadID,TizenThreadID,ThreadType,ApiType + log.length += sprintf(log.data + log.length, + "`,0`,%lu`,%d`,%u`,`,0x%x`,%d`,%d", ret,blockresult, + (unsigned int)CALLER_ADDRESS, (unsigned int) this, THREAD_TIZENTHREAD_WORKER, THREAD_API_WAIT_END); + //callstack + log.length += sprintf(log.data + log.length, "`,\ncallstack_start`,"); + getBacktraceString(&log, 4096 - log.length - 17); + log.length += sprintf(log.data + log.length, "`,callstack_end"); + + printLog(&log, MSG_LOG); + postBlockEnd(); + } + return ret; +} +//Tizen::Base::Object * Thread::Run(void) { +// typedef Tizen::Base::Object * (Thread::*methodType)(void); +// static methodType Runp = 0; +// Tizen::Base::Object * ret; +// probeInfo_t probeInfo; +// log_t log; +// int blockresult; +// bool bfiltering = true; +// void *tmpPtr; +// log.type = 0; +// log.length = 0; +// log.data[0] = '\0'; +// log.length = sprintf(log.data, "call Thread::Run"); +// printLog(&log, MSG_MSG); +// return null; +// if (!Runp) { +// probeBlockStart(); +// void* lib_handle = dlopen("libosp-appfw.so", RTLD_LAZY); +// if (lib_handle == NULL) { +// perror("dlopen failed : libosp-appfw.so"); +// log.type = 0; +// log.length = 0; +// log.data[0] = '\0'; +// log.length = sprintf(log.data, "dlopen failed :libosp-appfw.so"); +// printLog(&log, MSG_MSG); +// return null; +// } +// tmpPtr = +// dlsym( +// RTLD_NEXT, +// "_ZN5Tizen4Base7Runtime6Thread3RunEv"); +// +// if (tmpPtr == NULL || dlerror() != NULL) { +// perror("dlsym failed : Thread::Run"); +// log.type = 0; +// log.length = 0; +// log.data[0] = '\0'; +// log.length = sprintf(log.data, "dlsym failed : Thread::Run"); +// printLog(&log, MSG_MSG); +// return null; +// } +// +// memcpy(&Runp, &tmpPtr, sizeof(tmpPtr)); +// probeBlockEnd(); +// } +// +// if ((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { +// setProbePoint(&probeInfo); +// preBlockEnd(); +// } +// // +// ret = (this->*Runp)(); +// // +// if (postBlockBegin(blockresult)) { +// log.type = 0; +// log.length = 0; +// log.data[0] = '\0'; +// log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", LC_THREAD, +// probeInfo.eventIndex, "Thread::Run", +// probeInfo.currentTime, probeInfo.pID, probeInfo.tID); +// //Input,ret +// log.length += sprintf(log.data + log.length, "`,`,0x%x",(unsigned int)ret; +// //PCAddr,errno,InternalCall,size,FD,FDType,FDApiType,FileSize,FilePath +// +// +// log.length += sprintf(log.data + log.length, +// "`,0`,0`,%d`,0`,0x%x`,%d`,%d`,`,", blockresult, +// (unsigned int) this, THREAD_TIZENTHREAD_WORKER, THREAD_API_OTHER); +// //callstack +// log.length += sprintf(log.data + log.length, "`,\ncallstack_start`,"); +// getBacktraceString(&log, 4096 - log.length - 17); +// log.length += sprintf(log.data + log.length, "`,callstack_end"); +// +// printLog(&log, MSG_LOG); +// postBlockEnd(); +// } +// return ret; +//} + +result Thread::Start(void) { + typedef result (Thread::*methodType)(void); + static methodType Startp = 0; + result ret; + probeInfo_t probeInfo; + log_t log; + int blockresult; + bool bfiltering = true; + void *tmpPtr; + + if (!Startp) { + probeBlockStart(); + if(lib_handle[LIBOSP_APPFW] == NULL) { + lib_handle[LIBOSP_APPFW] = dlopen(lib_string[LIBOSP_APPFW], RTLD_LAZY); + if (lib_handle[LIBOSP_APPFW] == NULL) { + perror("dlopen failed : libosp-appfw.so"); + exit(0); + } + } + tmpPtr = dlsym(lib_handle[LIBOSP_APPFW], "_ZN5Tizen4Base7Runtime6Thread5StartEv"); + + if (tmpPtr == NULL || dlerror() != NULL) { + perror("dlsym failed : Tizen::Base::Runtime::Thread::Start"); + exit(0); + } + + memcpy(&Startp, &tmpPtr, sizeof(tmpPtr)); + probeBlockEnd(); + } + + if ((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { + setProbePoint(&probeInfo); + preBlockEnd(); + } + // + ret = (this->*Startp)(); + // + if (postBlockBegin(blockresult)) { + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", LC_THREAD, + probeInfo.eventIndex, "Thread::Start", probeInfo.currentTime, + probeInfo.pID, probeInfo.tID); + //Input,ret + log.length += sprintf(log.data + log.length, "`,`,%ld", ret); + //PCAddr,errno,InternalCall,CallerPCAddr,PThreadID,TizenThreadID,ThreadType,ApiType + log.length += sprintf(log.data + log.length, + "`,0`,%lu`,%d`,%u`,`,0x%x`,%d`,%d", ret, blockresult, + (unsigned int)CALLER_ADDRESS, (unsigned int) this, THREAD_TIZENTHREAD_WORKER, THREAD_API_START); + //callstack + log.length += sprintf(log.data + log.length, "`,\ncallstack_start`,"); + getBacktraceString(&log, 4096 - log.length - 17); + log.length += sprintf(log.data + log.length, "`,callstack_end"); + + printLog(&log, MSG_LOG); + postBlockEnd(); + } + return ret; +} +result Thread::Stop(void) { + typedef result (Thread::*methodType)(void); + static methodType Stopp = 0; + result ret; + probeInfo_t probeInfo; + log_t log; + int blockresult; + bool bfiltering = true; + void *tmpPtr; + + if (!Stopp) { + probeBlockStart(); + if(lib_handle[LIBOSP_APPFW] == NULL) { + lib_handle[LIBOSP_APPFW] = dlopen(lib_string[LIBOSP_APPFW], RTLD_LAZY); + if (lib_handle[LIBOSP_APPFW] == NULL) { + perror("dlopen failed : libosp-appfw.so"); + exit(0); + } + } + tmpPtr = dlsym(lib_handle[LIBOSP_APPFW], "_ZN5Tizen4Base7Runtime6Thread4StopEv"); + + if (tmpPtr == NULL || dlerror() != NULL) { + perror("dlsym failed : Tizen::Base::Runtime::Thread::Stop"); + exit(0); + } + + memcpy(&Stopp, &tmpPtr, sizeof(tmpPtr)); + probeBlockEnd(); + } + + if ((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { + setProbePoint(&probeInfo); + preBlockEnd(); + } + // + ret = (this->*Stopp)(); + // + if (postBlockBegin(blockresult)) { + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", LC_THREAD, + probeInfo.eventIndex, "Thread::Stop", probeInfo.currentTime, + probeInfo.pID, probeInfo.tID); + //Input,ret + log.length += sprintf(log.data + log.length, "`,`,%ld", ret); + //PCAddr,errno,InternalCall,CallerPCAddr,PThreadID,TizenThreadID,ThreadType,ApiType + log.length += sprintf(log.data + log.length, + "`,0`,%lu`,%d`,%u`,`,0x%x`,%d`,%d", ret, blockresult, + (unsigned int)CALLER_ADDRESS, (unsigned int) this, THREAD_TIZENTHREAD_WORKER, THREAD_API_STOP); + //callstack + log.length += sprintf(log.data + log.length, "`,\ncallstack_start`,"); + getBacktraceString(&log, 4096 - log.length - 17); + log.length += sprintf(log.data + log.length, "`,callstack_end"); + + printLog(&log, MSG_LOG); + postBlockEnd(); + } + return ret; +} + +result EventDrivenThread::Construct(long stackSize, ThreadPriority priority) { + typedef result + (Thread::*methodType)(long stackSize, ThreadPriority priority); + static methodType Constructp = 0; + result ret; + probeInfo_t probeInfo; + log_t log; + int blockresult; + bool bfiltering = true; + void *tmpPtr; + + if (!Constructp) { + probeBlockStart(); + if(lib_handle[LIBOSP_APPFW] == NULL) { + lib_handle[LIBOSP_APPFW] = dlopen(lib_string[LIBOSP_APPFW], RTLD_LAZY); + if (lib_handle[LIBOSP_APPFW] == NULL) { + perror("dlopen failed : libosp-appfw.so"); + exit(0); + } + } + tmpPtr = dlsym(lib_handle[LIBOSP_APPFW], + "_ZN5Tizen4Base7Runtime17EventDrivenThread9ConstructElNS1_14ThreadPriorityE"); + if (tmpPtr == NULL || dlerror() != NULL) { + perror("dlsym failed : Tizen::Base::Runtime::EventDrivenThread::Construct"); + exit(0); + } + + memcpy(&Constructp, &tmpPtr, sizeof(tmpPtr)); + probeBlockEnd(); + } + + if ((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { + setProbePoint(&probeInfo); + preBlockEnd(); + } + // + ret = (this->*Constructp)(stackSize, priority); + // + if (postBlockBegin(blockresult)) { + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", LC_THREAD, + probeInfo.eventIndex, "EventDrivenThread::Construct", + probeInfo.currentTime, probeInfo.pID, probeInfo.tID); + //Input,ret + log.length += sprintf(log.data + log.length, "`,%ld, %d`,%ld", + stackSize, priority, ret); + //PCAddr,errno,InternalCall,CallerPCAddr,PThreadID,TizenThreadID,ThreadType,ApiType + log.length += sprintf(log.data + log.length, + "`,0`,%lu`,%d`,%u`,`,0x%x`,%d`,%d", ret, blockresult, + (unsigned int)CALLER_ADDRESS, (unsigned int) this, THREAD_TIZENTHREAD_EVENTDRIVEN, THREAD_API_NEW); + //callstack + log.length += sprintf(log.data + log.length, "`,\ncallstack_start`,"); + getBacktraceString(&log, 4096 - log.length - 17); + log.length += sprintf(log.data + log.length, "`,callstack_end"); + + printLog(&log, MSG_LOG); + postBlockEnd(); + } + return ret; +} + +result EventDrivenThread::Construct(const Tizen::Base::String &name, long stackSize, + ThreadPriority priority) { + typedef result + (Thread::*methodType)(const Tizen::Base::String &name, long stackSize, + ThreadPriority priority); + static methodType Constructp = 0; + result ret; + probeInfo_t probeInfo; + log_t log; + int blockresult; + bool bfiltering = true; + void *tmpPtr; + char temp[50]; + + if (!Constructp) { + probeBlockStart(); + if(lib_handle[LIBOSP_APPFW] == NULL) { + lib_handle[LIBOSP_APPFW] = dlopen(lib_string[LIBOSP_APPFW], RTLD_LAZY); + if (lib_handle[LIBOSP_APPFW] == NULL) { + perror("dlopen failed : libosp-appfw.so"); + exit(0); + } + } + tmpPtr = + dlsym( + lib_handle[LIBOSP_APPFW], + "_ZN5Tizen4Base7Runtime17EventDrivenThread9ConstructERKNS0_6StringElNS1_14ThreadPriorityE"); + + if (tmpPtr == NULL || dlerror() != NULL) { + perror("dlsym failed : Tizen::Base::Runtime::EventDrivenThread::Construct"); + exit(0); + } + + memcpy(&Constructp, &tmpPtr, sizeof(tmpPtr)); + probeBlockEnd(); + } + + if ((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { + setProbePoint(&probeInfo); + preBlockEnd(); + } + // + ret = (this->*Constructp)(name, stackSize, priority); + // + if (postBlockBegin(blockresult)) { + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", LC_THREAD, + probeInfo.eventIndex, "EventDrivenThread::Construct", + probeInfo.currentTime, probeInfo.pID, probeInfo.tID); + //Input,ret + WcharToChar(temp, name.GetPointer()); + log.length += sprintf(log.data + log.length, "`,%s, %ld, %d`,%ld", temp, + stackSize, priority, ret); + //PCAddr,errno,InternalCall,CallerPCAddr,PThreadID,TizenThreadID,ThreadType,ApiType + log.length += sprintf(log.data + log.length, + "`,0`,%lu`,%d`,%u`,`,0x%x`,%d`,%d", ret, blockresult, + (unsigned int)CALLER_ADDRESS, (unsigned int) this, THREAD_TIZENTHREAD_EVENTDRIVEN, THREAD_API_NEW); + //callstack + log.length += sprintf(log.data + log.length, "`,\ncallstack_start`,"); + getBacktraceString(&log, 4096 - log.length - 17); + log.length += sprintf(log.data + log.length, "`,callstack_end"); + + printLog(&log, MSG_LOG); + postBlockEnd(); + } + return ret; + +} + +result EventDrivenThread::Quit() { + typedef result (Thread::*methodType)(void); + static methodType Quitp = 0; + result ret; + probeInfo_t probeInfo; + log_t log; + int blockresult; + bool bfiltering = true; + void *tmpPtr; + + if (!Quitp) { + probeBlockStart(); + if(lib_handle[LIBOSP_APPFW] == NULL) { + lib_handle[LIBOSP_APPFW] = dlopen(lib_string[LIBOSP_APPFW], RTLD_LAZY); + if (lib_handle[LIBOSP_APPFW] == NULL) { + perror("dlopen failed : libosp-appfw.so"); + exit(0); + } + } + tmpPtr = dlsym(lib_handle[LIBOSP_APPFW], "_ZN5Tizen4Base7Runtime17EventDrivenThread4QuitEv"); + + if (tmpPtr == NULL || dlerror() != NULL) { + perror("dlsym failed : Tizen::Base::Runtime::EventThread::Quit"); + exit(0); + } + + memcpy(&Quitp, &tmpPtr, sizeof(tmpPtr)); + probeBlockEnd(); + } + + if ((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { + setProbePoint(&probeInfo); + preBlockEnd(); + } + // + ret = (this->*Quitp)(); + // + if (postBlockBegin(blockresult)) { + log.type = 0; + log.length = 0; + log.data[0] = '\0'; + log.length = sprintf(log.data, "%d`,%d`,%s`,%lu`,%d`,%d", LC_THREAD, + probeInfo.eventIndex, "EventThread::Quit", probeInfo.currentTime, + probeInfo.pID, probeInfo.tID); + //Input,ret + log.length += sprintf(log.data + log.length, "`,`,%ld", ret); + //PCAddr,errno,InternalCall,CallerPCAddr,PThreadID,TizenThreadID,ThreadType,ApiType + log.length += sprintf(log.data + log.length, + "`,0`,%lu`,%d`,%u`,`,0x%x`,%d`,%d", ret, blockresult, + (unsigned int)CALLER_ADDRESS, (unsigned int) this, THREAD_TIZENTHREAD_EVENTDRIVEN, THREAD_API_STOP); + //callstack + log.length += sprintf(log.data + log.length, "`,\ncallstack_start`,"); + getBacktraceString(&log, 4096 - log.length - 17); + log.length += sprintf(log.data + log.length, "`,callstack_end"); + + printLog(&log, MSG_LOG); + postBlockEnd(); + } + return ret; +} + +} +} +} diff --git a/probe_ui/capi_capture.c b/probe_ui/capi_capture.c new file mode 100755 index 0000000..95dfbbf --- /dev/null +++ b/probe_ui/capi_capture.c @@ -0,0 +1,99 @@ +/* + * DA probe + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Jaewon Lim + * Woojin Jung + * Juyoung Kim + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +//#include +//#include +//#include +//#include +//#include +//#include +//#include + +#include +#include +//#include + +#include "daprobe.h" +#include "probeinfo.h" +#include "da_ui.h" + +Evas_Object *elm_win_add(Evas_Object *parent, const char* name, Elm_Win_Type type) +{ + static Evas_Object * (*elm_win_addp)(Evas_Object *parent, const char* name, Elm_Win_Type type); + + BEFORE_ORIGINAL_SNAPSHOT(elm_win_add, LIBELEMENTARY); + + ret = elm_win_addp(parent, name, type); + + AFTER_ORIGINAL_SNAPSHOT(ret); + + return ret; +} + +Evas_Object * elm_controlbar_add (Evas_Object *parent) +{ + static Evas_Object * (*elm_controlbar_addp)(Evas_Object *parent); + + BEFORE_ORIGINAL_SNAPSHOT(elm_controlbar_add, LIBELEMENTARY); + + ret = elm_controlbar_addp(parent); + + AFTER_ORIGINAL_SNAPSHOT(ret); + + return ret; + +// ecore_evas_callback_post_render_set(ecore_evas_ecore_evas_get(evas_object_evas_get(parent)), _cbecore); +} + +Evas_Object *elm_naviframe_add(Evas_Object *parent) +{ + static Evas_Object * (*elm_naviframe_addp)(Evas_Object *parent); + + BEFORE_ORIGINAL_SNAPSHOT(elm_naviframe_add, LIBELEMENTARY); + + ret = elm_naviframe_addp(parent); + + AFTER_ORIGINAL_SNAPSHOT(ret); + + return ret; +} + +Evas_Object *elm_pager_add(Evas_Object *parent) +{ + static Evas_Object * (*elm_pager_addp)(Evas_Object *parent); + + BEFORE_ORIGINAL_SNAPSHOT(elm_pager_add, LIBELEMENTARY); + + ret = elm_pager_addp(parent); + + AFTER_ORIGINAL_SNAPSHOT(ret); + + return ret; +} diff --git a/probe_ui/da_ui.h b/probe_ui/da_ui.h new file mode 100755 index 0000000..b11cf17 --- /dev/null +++ b/probe_ui/da_ui.h @@ -0,0 +1,65 @@ +/* + * DA probe + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Jaewon Lim + * Woojin Jung + * Juyoung Kim + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#ifndef __DA_SNAPSHOT_H__ +#define __DA_SNAPSHOT_H__ + +#include "daprobe.h" +#include "dahelper.h" + +/******************************************************************** + * SNAPSHOT PROBE MACRO + * + * log format + * SeqNumber`,ApiName`,Time`,Pid`,Tid`,InputParm`,Return`,PCAddr`,Error`,Size`,FUNCTYPE`,\n + * callstack_start`,callstack`,callstack_end + * + * FUNCTYPE + * SNAPSHOT_API_TYPE_PAGER, + * SNAPSHOT_API_TYPE_CONTROLBAR, + * SNAPSHOT_API_TYPE_NAVIFRAME, + * SNAPSHOT_API_TYPE_OTHER + * + **********************************************************************/ + +#define BEFORE_ORIGINAL_SNAPSHOT(FUNCNAME, LIBNAME) \ + Evas_Object* ret; \ + GET_REAL_FUNC(FUNCNAME, LIBNAME) + +#define AFTER_ORIGINAL_SNAPSHOT(EVASOBJECT) \ + do { \ + probeBlockStart(); \ + evas_event_callback_add(evas_object_evas_get(EVASOBJECT), \ + EVAS_CALLBACK_RENDER_FLUSH_POST, \ + _cb_render_post, NULL); \ + probeBlockEnd(); \ + } while(0) + +#endif // __DA_SNAPSHOT_H__ diff --git a/probe_ui/tizen_capture.cpp b/probe_ui/tizen_capture.cpp new file mode 100755 index 0000000..645d5d1 --- /dev/null +++ b/probe_ui/tizen_capture.cpp @@ -0,0 +1,375 @@ +/* + * DA probe + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Jaewon Lim + * Woojin Jung + * Juyoung Kim + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#include + +#include +//#include + +#include "daprobe.h" +#include "dahelper.h" +#include "dacollection.h" +#include "daerror.h" +//#include "da_ui.h" +#include "tizen_probe.h" + +using namespace Tizen::Base; +using namespace Tizen::Ui; +using namespace Tizen::Graphics; +using namespace Tizen::Media; + +/* +#define LIBUTILX "libutilX.so.1" + +typedef void* (*utilx_create_screen_shot_type)(Display* dpy, int width, int height); +typedef void (*utilx_release_screen_shot_type)(void); + +static Tizen::Graphics::Bitmap* sysutil_capture_screen() +{ + static utilx_create_screen_shot_type utilx_create_screen_shotp; + static utilx_release_screen_shot_type utilx_release_screen_shotp; + result r; + Bitmap* pBitmap = NULL; + + if(unlikely(utilx_create_screen_shotp == NULL)) + { + void* lib_handle = dlopen(LIBUTILX, RTLD_LAZY); + if(lib_handle == NULL) { + SetLastResult(ERR_DLOPEN); + return NULL; + } + utilx_create_screen_shotp = (utilx_create_screen_shot_type)dlsym(lib_handle, "utilx_create_screen_shot"); + if(utilx_create_screen_shotp == NULL || dlerror() != NULL) { + SetLastResult(ERR_DLSYM); + return NULL; + } + } + + if(unlikely(utilx_release_screen_shotp == NULL)) + { + void* lib_handle = dlopen(LIBUTILX, RTLD_LAZY); + if(lib_handle == NULL) { + SetLastResult(ERR_DLOPEN); + return NULL; + } + utilx_release_screen_shotp = (utilx_release_screen_shot_type)dlsym(lib_handle, "utilx_release_screen_shot"); + if(utilx_release_screen_shotp == NULL || dlerror() != NULL) { + SetLastResult(ERR_DLSYM); + return NULL; + } + } + + Display* pDpy = XOpenDisplay(NULL); + if(pDpy == NULL) + { + SetLastResult(ERR_USER - 1); + return NULL; + } + + int width = DisplayWidth(pDpy, DefaultScreen(pDpy)); + int height = DisplayHeight(pDpy, DefaultScreen(pDpy)); + + void* pDump = utilx_create_screen_shotp(pDpy, width, height); + if(likely(pDump != NULL)) + { + ByteBuffer buffer; + r = buffer.Construct(static_cast(pDump), 0, width*height*4, width*height*4);\ + if(likely(r == E_SUCCESS)) + { + Tizen::Graphics::Dimension dim(width, height); + Bitmap* pBitmap = new Bitmap(); + if(likely(pBitmap != NULL)) + { + r = pBitmap->Construct(buffer, dim, BITMAP_PIXEL_FORMAT_ARGB8888); + if(unlikely(r != E_SUCCESS)) + { + SetLastResult(r); + delete pBitmap; + pBitmap = NULL; + } + else { SetLastResult(E_SUCCESS); } + } + else { SetLastResult(ERR_OUTOFMEMORY); } + } + else { SetLastResult(r); } + } + else { SetLastResult(ERR_USER - 2); } + + utilx_release_screen_shotp(); + + return pBitmap; +} + +static Bitmap* getBitmapFromBuffer(void* pDump, int width, int height) +{ + result r; + ByteBuffer buffer; + Bitmap* pBitmap = NULL; + + r = buffer.Construct(static_cast(pDump), 0, width*height*4, width*height*4); + if(likely(r == E_SUCCESS)) + { + Tizen::Graphics::Dimension dim(width, height); + pBitmap = new Bitmap(); + if(likely(pBitmap != NULL)) + { + r = pBitmap->Construct(buffer, dim, BITMAP_PIXEL_FORMAT_ARGB8888); + if(unlikely(r != E_SUCCESS)) + { + SetLastResult(r); + delete pBitmap; + pBitmap = NULL; + } + else { SetLastResult(E_SUCCESS); } + } + else { SetLastResult(ERR_OUTOFMEMORY); } + } + else { SetLastResult(r); } + + return pBitmap; +} + +// return 0 if succeed +// return -1 if failed to capture +int captureScreen() +{ + Image img; + Bitmap* bitmap; + DECLARE_COMMON_VARIABLE; + result r; + int ret = 0, width, height; + char* capbuf; + + probeBlockStart(); + + capbuf = captureScreenShotX(&width, &height); + if(capbuf != NULL) + { + bitmap = getBitmapFromBuffer((void*)capbuf, width, height); + if(bitmap != NULL) + { + String dstPath; + setProbePoint(&probeInfo); + + dstPath.Format(MAX_PATH_LENGTH, L"/tmp/da/%d.jpg", probeInfo.eventIndex); + img.Construct(); + r = img.EncodeToFile(*bitmap, IMG_FORMAT_JPG, dstPath, true); + if(r == E_SUCCESS) + { + INIT_LOG; + APPEND_LOG_BASIC_NAME(LC_SNAPSHOT, "captureScreen"); + APPEND_LOG_COMMON_NONE(0); + log.length += sprintf(log.data + log.length, "`,%S", dstPath.GetPointer()); + printLog(&log, MSG_LOG); + } + else + { + ret = -1; + } + + delete bitmap; + } + else + { + char buf[128]; + r = GetLastResult(); + sprintf(buf, "bitmap is null (%p, %d, %s)\n", capbuf, (int)r, GetErrorMessage(r)); + PRINTMSG(buf); + ret = -1; + } + } + else + { + ret = -1; + } + + releaseScreenShotX(); + probeBlockEnd(); + + return ret; +} +*/ + +namespace Tizen { namespace Ui { +/* +class _EcoreEvas +{ +public: + Evas* GetEvas(void) const; +}; + +class _EcoreEvasMgr +{ + void SetEcoreEvas(const _EcoreEvas& ecoreevas); +}; + + +void _EcoreEvasMgr::SetEcoreEvas(const _EcoreEvas& ecoreevas) +{ + typedef void (_EcoreEvasMgr::*methodType)(const _EcoreEvas& ecoreevas); + static methodType _ecoreevasmgr_setecoreevasp; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui13_EcoreEvasMgr12SetEcoreEvasERKNS0_10_EcoreEvasE, + LIBOSP_UIFW, _ecoreevasmgr_setecoreevasp); + + probeBlockStart(); + evas_event_callback_add(ecoreevas.GetEvas(), + EVAS_CALLBACK_RENDER_FLUSH_POST, _cb_render_post, NULL); + probeBlockEnd(); + + (this->*_ecoreevasmgr_setecoreevasp)(ecoreevas); +} +*/ + +result Control::SetShowState(bool state) +{ + typedef result (Control::*methodType)(bool state); + static methodType control_setshowstatep; + result ret; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui7Control12SetShowStateEb, + LIBOSP_UIFW, control_setshowstatep); + + ret = (this->*control_setshowstatep)(state); + + probeBlockStart(); + { + char *type, *classname; + if(find_uiobject_hash((void*)this, &type, &classname) == 1) + { + if(strcmp(type, "Panel") == 0 || strcmp(type, "OverlayPanel") == 0 || strcmp(type, "ScrollPanel") == 0) + { + SCREENSHOT_SET(); +// SCREENSHOT_DONE(); + } + else + { + // do nothing + } + } + else + { + // never happened + } + } + probeBlockEnd(); + + return ret; +} + +namespace Controls { + +result Frame::SetCurrentForm(const Form& form) +{ + typedef result (Frame::*methodType)(const Form& form); + static methodType frame_setcurrentformp; + result ret; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui8Controls5Frame14SetCurrentFormERKNS1_4FormE, + LIBOSP_UIFW, frame_setcurrentformp); + + ret = (this->*frame_setcurrentformp)(form); + + probeBlockStart(); + SCREENSHOT_SET(); +// SCREENSHOT_DONE(); + probeBlockEnd(); + + return ret; +} + +result Frame::SetCurrentForm(Form* pForm) +{ + typedef result (Frame::*methodType)(Form* pForm); + static methodType frame_setcurrentformp; + result ret; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui8Controls5Frame14SetCurrentFormEPNS1_4FormE, + LIBOSP_UIFW, frame_setcurrentformp); + + ret = (this->*frame_setcurrentformp)(pForm); + + probeBlockStart(); + SCREENSHOT_SET(); +// SCREENSHOT_DONE(); + probeBlockEnd(); + + return ret; +} + + +} // end of namespace Tizen::Ui::Controls + +namespace Animations { + +result FrameAnimator::SetCurrentForm(const Tizen::Ui::Controls::Form& form) +{ + typedef result (FrameAnimator::*methodType)(const Tizen::Ui::Controls::Form& form); + static methodType frameanimator_setcurrentformp; + result ret; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui10Animations13FrameAnimator14SetCurrentFormERKNS0_8Controls4FormE, + LIBOSP_UIFW, frameanimator_setcurrentformp); + + ret = (this->*frameanimator_setcurrentformp)(form); + + probeBlockStart(); + SCREENSHOT_SET(); +// SCREENSHOT_DONE(); + probeBlockEnd(); + + return ret; +} + +result FrameAnimator::SetCurrentForm(Tizen::Ui::Controls::Form* pForm) +{ + typedef result (FrameAnimator::*methodType)(Tizen::Ui::Controls::Form* pForm); + static methodType frameanimator_setcurrentformp; + result ret; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui10Animations13FrameAnimator14SetCurrentFormEPNS0_8Controls4FormE, + LIBOSP_UIFW, frameanimator_setcurrentformp); + + ret = (this->*frameanimator_setcurrentformp)(pForm); + + probeBlockStart(); + SCREENSHOT_SET(); +// SCREENSHOT_DONE(); + probeBlockEnd(); + + return ret; +} + + +} // end of namespace Tizen::Ui::Animations + +} } // end of namespace Tizen::Ui + + diff --git a/probe_ui/tizen_display.cpp b/probe_ui/tizen_display.cpp new file mode 100644 index 0000000..aa0e695 --- /dev/null +++ b/probe_ui/tizen_display.cpp @@ -0,0 +1,108 @@ +#include + +#include "daprobe.h" +#include "dahelper.h" +#include "tizen_probe.h" + +namespace Tizen { namespace Ui { namespace Animations { + +class _RootVisualElement +{ +}; + +class _DisplayManager +{ +// bool RenderAll(bool check); +// bool Render(_RootVisualElement& root, bool check); + result PostRender(_RootVisualElement& root); +// result Flush(void); +// bool UpdateScene(bool force); +}; +/* +bool _DisplayManager::RenderAll(bool check) +{ + typedef bool (_DisplayManager::*methodtype)(bool check); + static methodtype mp; + bool ret; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui10Animations15_DisplayManager9RenderAllEb, LIBOSP_UIFW, mp); + probeBlockStart(); + probeBlockEnd(); + + ret = (this->*mp)(check); + + probeBlockStart(); + probeBlockEnd(); + + return ret; +} + +bool _DisplayManager::Render(_RootVisualElement& root, bool check) +{ + typedef bool (_DisplayManager::*methodtype)(_RootVisualElement& root, bool check); + static methodtype mp; + bool ret; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui10Animations15_DisplayManager6RenderERNS1_18_RootVisualElementEb, LIBOSP_UIFW, mp); + probeBlockStart(); + probeBlockEnd(); + ret = (this->*mp)(root, check); + probeBlockStart(); + probeBlockEnd(); + + return ret; +} +*/ +result _DisplayManager::PostRender(_RootVisualElement& root) +{ + typedef result (_DisplayManager::*methodtype)(_RootVisualElement& root); + static methodtype mp; + result ret; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui10Animations15_DisplayManager10PostRenderERNS1_18_RootVisualElementE, LIBOSP_UIFW, mp); + probeBlockStart(); + probeBlockEnd(); + + ret = (this->*mp)(root); + + probeBlockStart(); + SCREENSHOT_DONE(); + probeBlockEnd(); + + return ret; +} +/* +result _DisplayManager::Flush(void) +{ + typedef result (_DisplayManager::*methodtype)(void); + static methodtype mp; + result ret; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui10Animations15_DisplayManager5FlushEv, LIBOSP_UIFW, mp); + probeBlockStart(); + probeBlockEnd(); + ret = (this->*mp)(); + probeBlockStart(); + probeBlockEnd(); + + return ret; +} + +bool _DisplayManager::UpdateScene(bool force) +{ + typedef bool (_DisplayManager::*methodtype)(bool force); + static methodtype mp; + bool ret; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui10Animations15_DisplayManager11UpdateSceneEb, LIBOSP_UIFW, mp); + probeBlockStart(); + probeBlockEnd(); + ret = (this->*mp)(force); + probeBlockStart(); + probeBlockEnd(); + + return ret; +} +*/ + +} } } // end of namespace diff --git a/probe_ui/tizen_frameani.cpp b/probe_ui/tizen_frameani.cpp new file mode 100644 index 0000000..4ce0fe8 --- /dev/null +++ b/probe_ui/tizen_frameani.cpp @@ -0,0 +1,78 @@ +/* + * DA probe + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Jaewon Lim + * Woojin Jung + * Juyoung Kim + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#include "daprobe.h" +#include "dahelper.h" +#include "tizen_frameani.h" + +DAFrameAnimationEventListener DAFrameAnimationEventListener::rInstance; + +DAFrameAnimationEventListener::DAFrameAnimationEventListener() +{ +} + +DAFrameAnimationEventListener::~DAFrameAnimationEventListener() +{ +} + +void DAFrameAnimationEventListener::OnFormTransitionAnimationFinished(FrameAnimator &source, Frame &frame, Form &form1, Form &form2) +{ + probeBlockStart(); + SCREENSHOT_SET(); +// SCREENSHOT_DONE(); + probeBlockEnd(); +} + +void DAFrameAnimationEventListener::OnFormTransitionAnimationStarted(FrameAnimator &source, Frame &frame, Form &form1, Form &form2) +{ + probeBlockStart(); + SCREENSHOT_UNSET(); + probeBlockEnd(); +} + +void DAFrameAnimationEventListener::OnFormTransitionAnimationStopped(FrameAnimator &source, Frame &frame, Form &form1, Form &form2) +{ + probeBlockStart(); + SCREENSHOT_SET(); +// SCREENSHOT_DONE(); + probeBlockEnd(); +} + +DAFrameAnimationEventListener& DAFrameAnimationEventListener::GetInstance(void) +{ + return rInstance; +} + +IFrameAnimatorEventListener& GetFrameAnimatorEventListener() +{ + DAFrameAnimationEventListener& listener = DAFrameAnimationEventListener::GetInstance(); + return static_cast(listener); +} + diff --git a/probe_ui/tizen_frameani.h b/probe_ui/tizen_frameani.h new file mode 100644 index 0000000..7d8556b --- /dev/null +++ b/probe_ui/tizen_frameani.h @@ -0,0 +1,58 @@ +/* + * DA probe + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Jaewon Lim + * Woojin Jung + * Juyoung Kim + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#ifndef __TIZEN_FRAMEANI_H__ +#define __TIZEN_FRAMEANI_H__ + +#include + +using namespace Tizen::Ui::Animations; +using namespace Tizen::Ui::Controls; + +class DAFrameAnimationEventListener : + public IFrameAnimatorEventListener +{ +public: + DAFrameAnimationEventListener(); + virtual ~DAFrameAnimationEventListener(); + + virtual void OnFormTransitionAnimationFinished (FrameAnimator &source, Frame &frame, Form &form1, Form &form2); + virtual void OnFormTransitionAnimationStarted (FrameAnimator &source, Frame &frame, Form &form1, Form &form2); + virtual void OnFormTransitionAnimationStopped (FrameAnimator &source, Frame &frame, Form &form1, Form &form2); + + static DAFrameAnimationEventListener& GetInstance(void); + +private: + static DAFrameAnimationEventListener rInstance; +}; + + +#endif // __TIZEN_FRAMEANI_H__ + diff --git a/probe_ui/tizen_scenemanager.cpp b/probe_ui/tizen_scenemanager.cpp new file mode 100755 index 0000000..c1664c4 --- /dev/null +++ b/probe_ui/tizen_scenemanager.cpp @@ -0,0 +1,171 @@ +/* + * DA probe + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Jaewon Lim + * Woojin Jung + * Juyoung Kim + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#include +#include +#include + +#include "daprobe.h" +#include "dacollection.h" // for find_uiobject_hash +#include "dahelper.h" // for captureScreen +#include "tizen_probe.h" + +using namespace Tizen::Base; +using namespace Tizen::Ui::Controls; +using namespace Tizen::Ui::Scenes; + +#define APPEND_SCENE_ELEM(_ID, _CONTROL) \ + do { \ + if(_CONTROL != NULL) { \ + char *name = NULL, *type = NULL; \ + if(find_uiobject_hash((void*)(_CONTROL), &type, &name) == 1) { \ + log.length += sprintf(log.data + log.length, "`,%S`,%s", \ + const_cast((_ID).GetPointer()), name); \ + } else { \ + log.length += sprintf(log.data + log.length, "`,%S`,", \ + const_cast((_ID).GetPointer())); \ + } \ + } else { \ + log.length += sprintf(log.data + log.length, "`,`,"); \ + } \ + } while(0) + +int SceneManagerUsed = 0; + +class SceneManagerEventListener : public ISceneManagerEventListener +{ +public: + virtual void OnSceneTransitionCompleted(const SceneId &previousSceneId, const SceneId ¤tSceneId); + virtual void OnSceneTransitionStarted(const SceneId ¤tSceneId, const SceneId &nextSceneId); + static SceneManagerEventListener& GetInstance(); +private: + static SceneManagerEventListener rInstance; + unsigned long startTime; +}; + +SceneManagerEventListener SceneManagerEventListener::rInstance; + +void SceneManagerEventListener::OnSceneTransitionCompleted(const SceneId &previousSceneId, const SceneId ¤tSceneId) +{ + probeBlockStart(); + { + SceneManager* scenemanager = SceneManager::GetInstance(); + + if(scenemanager->GetCurrentSceneId() == currentSceneId) + { + if(isOptionEnabled(OPT_UI)) + { + DECLARE_COMMON_VARIABLE; + Scene* scene; + String sceneid, formid, panelid; + Form* pform; + Panel* ppanel; + unsigned long transition, user = 0; + + setProbePoint(&probeInfo); + INIT_LOG; + + scene = scenemanager->GetCurrentScene(); + sceneid = scene->GetSceneId(); + formid = scene->GetFormId(); + panelid = scene->GetPanelId(); + pform = scene->GetForm(); + ppanel = scene->GetPanel(); + + transition = (probeInfo.currentTime - startTime); + + APPEND_LOG_BASIC_NAME(LC_SCENE, "OnSceneTransitionCompleted"); + APPEND_LOG_COMMON_NONE(0); + log.length += sprintf(log.data + log.length, "`,%S", + const_cast(sceneid.GetPointer())); + APPEND_SCENE_ELEM(formid, pform); + APPEND_SCENE_ELEM(panelid, ppanel); + log.length += sprintf(log.data + log.length, "`,%lu`,%lu`,", transition, user); + + printLog(&log, MSG_LOG); + } + } + else + { + // never happened + assert(false); + } + + SCREENSHOT_SET(); +// SCREENSHOT_DONE(); + } + + SceneManagerUsed = 0; + probeBlockEnd(); +} + +void SceneManagerEventListener::OnSceneTransitionStarted(const SceneId ¤tSceneId, const SceneId &nextSceneId) +{ + probeBlockStart(); + SceneManagerUsed = 1; + startTime = getCurrentTime(); + probeBlockEnd(); +} + +SceneManagerEventListener& SceneManagerEventListener::GetInstance() +{ + return rInstance; +} + + +namespace Tizen { namespace Ui { namespace Scenes { + +SceneManager* SceneManager::GetInstance(void) +{ + typedef SceneManager* (*methodType)(void); + static methodType scenemanager_getinstancep; + static int initialized = 0; + SceneManager* ret; + + GET_REAL_FUNC_TIZEN(_ZN5Tizen2Ui6Scenes12SceneManager11GetInstanceEv, LIBOSP_UIFW, scenemanager_getinstancep); + + ret = scenemanager_getinstancep(); + + probeBlockStart(); + if(unlikely(initialized == 0)) + { + if(likely(ret != NULL)) + { + ret->AddSceneManagerEventListener(SceneManagerEventListener::GetInstance()); + initialized = 1; + } + } + probeBlockEnd(); + + return ret; +} + + +} } } // end of namespace diff --git a/probe_userfunc/libdauserfunc.c b/probe_userfunc/libdauserfunc.c new file mode 100755 index 0000000..06b8e92 --- /dev/null +++ b/probe_userfunc/libdauserfunc.c @@ -0,0 +1,562 @@ +/* + * DA probe + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Woojin Jung + * Jaewon Lim + * Juyoung Kim + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "daprobe.h" +#include "probeinfo.h" +#include "dautil.h" +#include "dahelper.h" +#include "da_sync.h" + +//#define USING_BACKTRACE + +#define RETURN_ADDRESS(nr) \ + __builtin_extract_return_addr (__builtin_return_address(nr)) + +#if defined(__i386__) +#define GET_PC(ctx) ((void *) ctx.eip) +#elif defined (__arm__) +#define GET_PC(ctx) ((void *) (ctx)->uc_mcontext.arm_pc) +#endif + +#define USERFUNCTION_MAX_DEPTH 32 +#define PROFIL_LOG_SENDING_INTERVAL_USEC 100000 // 100 milliseconds +#define SAMPLE_MAX_IN_INTERVAL 50 +#define PROFIL_TRIM_STACK_DEPTH 2 + +#define IS_FULL_SAMPLE_ARRAY ((((sample_write_index + 1) % SAMPLE_MAX_IN_INTERVAL) == sample_read_index) ? 1 : 0) +#define IS_EMPTY_SAMPLE_ARRAY ((sample_write_index == sample_read_index) ? 1 : 0) + +#define CUSTOM_CB_FUNC_NAME "_chart_timerThread" + +void *custom_cb_addr = (void*)-1; + +int profil_option = 0; +volatile int profil_turned_on = 0; +volatile int profil_thread_on = 0; +u_long low_pc, high_pc; + +typedef struct elapsed_time_t { + struct timeval startTime; + struct timeval endTime; + struct timeval resultTime; + void *self; +} elapsed_time; + +__thread elapsed_time elapsed_time_array[USERFUNCTION_MAX_DEPTH]; +__thread int elapsed_time_index; + +pthread_t profil_log_thread; +pthread_mutex_t profil_log_mutex; + +typedef struct sample_info_t { + unsigned long time; + void *pc; + int bt_size; + void *bt_array[MAX_STACK_DEPTH]; +} sample_info; + +int sample_seq = 0; +int sample_read_index = 0; +int sample_write_index = 0; +sample_info sample_info_array[SAMPLE_MAX_IN_INTERVAL]; + +int __profile_frequency(); + +static unsigned long long getElapsedTime(struct timeval eTime) +{ + return ((unsigned long long) eTime.tv_sec) * 1000000 + eTime.tv_usec; +} + +static unsigned long getTime() +{ + struct timespec ts; + clock_gettime(CLOCK_REALTIME, &ts); + + return (unsigned long)(ts.tv_sec * 10000 + (ts.tv_nsec/100000)); +} + +#ifdef USING_BACKTRACE +int profil_backtrace_symbols(log_t *log, int bufsize, int index) +{ + char **strings = NULL; + size_t i; + int initsize; + int stringlen; + + if(log == NULL) + return 0; + + initsize = log->length; + log->data[log->length] = '\0'; // is this necessary ? + if(likely(sample_info_array[index].bt_size > PROFIL_TRIM_STACK_DEPTH)) + { + strings = BACKTRACE_SYMBOLS(sample_info_array[index].bt_array + PROFIL_TRIM_STACK_DEPTH, + sample_info_array[index].bt_size - PROFIL_TRIM_STACK_DEPTH); + + if(likely(strings != NULL)) + { + for(i = PROFIL_TRIM_STACK_DEPTH; i < sample_info_array[index].bt_size; i++) + { + stringlen = strlen(strings[i - PROFIL_TRIM_STACK_DEPTH]) + 14; + if(log->length + stringlen >= bufsize + initsize) + break; + + log->length += sprintf(log->data + log->length, "%010u`,%s`,", + (unsigned int)(sample_info_array[index].bt_array[i]), + strings[i - PROFIL_TRIM_STACK_DEPTH]); + } + log->data[log->length-2] = '\0'; + log->length -= 2; + free(strings); + } + else + { + for(i = PROFIL_TRIM_STACK_DEPTH; i < sample_info_array[index].bt_size; i++) + { + stringlen = 23; + if(log->length + stringlen >= bufsize + initsize) + break; + + log->length += sprintf(log->data + log->length, "%010u`,(unknown)`,", + (unsigned int)(sample_info_array[index].bt_array[i])); + } + log->data[log->length-2] = '\0'; + log->length -= 2; + } + return (int)(sample_info_array[index].bt_size - PROFIL_TRIM_STACK_DEPTH); + } + else + { + return 0; + } +} +#else +int profil_backtrace_symbols(log_t *log, int bufsize, int index) +{ + char **strings = NULL; + size_t i; + int initsize; + int stringlen; + + if(log == NULL) + return 0; + + initsize = log->length; + log->data[log->length] = '\0'; // is this necessary ? + strings = BACKTRACE_SYMBOLS(sample_info_array[index].bt_array, + sample_info_array[index].bt_size); + + if(likely(strings != NULL)) + { + for(i = 0; i < sample_info_array[index].bt_size; i++) + { + stringlen = strlen(strings[i]) + 14; + if(log->length + stringlen >= bufsize + initsize) + break; + + log->length += sprintf(log->data + log->length, "%010u`,%s`,", + (unsigned int)(sample_info_array[index].bt_array[i]), + strings[i]); + } + log->data[log->length-2] = '\0'; + log->length -= 2; + free(strings); + } + else + { + for(i = 0; i < sample_info_array[index].bt_size; i++) + { + stringlen = 23; + if(log->length + stringlen >= bufsize + initsize) + break; + + log->length += sprintf(log->data + log->length, "%010u`,(unknown)`,", + (unsigned int)(sample_info_array[index].bt_array[i])); + } + log->data[log->length-2] = '\0'; + log->length -= 2; + } + return (int)(sample_info_array[index].bt_size); +} +#endif + +void *profil_log_func(void *data) +{ + log_t log; + + probeBlockStart(); + + sigset_t profsigmask; + sigemptyset(&profsigmask); + sigaddset(&profsigmask, SIGPROF); + pthread_sigmask(SIG_BLOCK, &profsigmask, NULL); + + INIT_LOG; + + while(profil_thread_on) + { + while(!IS_EMPTY_SAMPLE_ARRAY) + { + log.length = sprintf(log.data, "%d`,%d`,%lu`,%u`,\ncallstackstart`,", + LC_SAMPLE, sample_seq++, sample_info_array[sample_read_index].time, + (unsigned int)sample_info_array[sample_read_index].pc); + profil_backtrace_symbols(&log, DA_LOG_MAX - log.length - 17, sample_read_index); + log.length += sprintf(log.data + log.length, "`,callstack_end"); + printLog(&log, MSG_LOG); + sample_read_index = (sample_read_index + 1) % SAMPLE_MAX_IN_INTERVAL; + } + usleep(PROFIL_LOG_SENDING_INTERVAL_USEC); + } + probeBlockEnd(); + + return NULL; +} + +void __cyg_profile_func_enter(void *this, void *callsite) +{ + probeInfo_t probeInfo; + log_t log; + + sigset_t profsigmask, oldsigmask; + sigemptyset(&profsigmask); + sigaddset(&profsigmask, SIGPROF); + pthread_sigmask(SIG_BLOCK, &profsigmask, &oldsigmask); + + probeBlockStart(); + do { + // remove custom chart callback function + if(gTraceInfo.custom_chart_callback_count > 0) + { + if(custom_cb_addr == (void*)-1) + { + char **strings = BACKTRACE_SYMBOLS(&callsite, 1); + if(likely(strings != NULL)) + { + if(strstr(strings[0], CUSTOM_CB_FUNC_NAME) != NULL) + { + custom_cb_addr = callsite; + free(strings); + break; + } + free(strings); + } + } + else + { + if(callsite == custom_cb_addr) + break; + } + } + + setProbePoint(&probeInfo); + INIT_LOG; + log.length = sprintf(log.data, "%d`,%d`,`,%lu`,%d`,%d`,`,`,%u`,`,0`,%u`,%lu`,%lu`,%d`,0", + LC_USERFUNC, probeInfo.eventIndex, probeInfo.currentTime, probeInfo.pID, probeInfo.tID, + (unsigned int) this, (unsigned int) callsite, low_pc, high_pc, USERFUNC_ENTER); + APPEND_LOG_CALLSTACK(); + printLog(&log, MSG_LOG); + + gettimeofday(&(elapsed_time_array[elapsed_time_index].startTime), NULL); + elapsed_time_array[elapsed_time_index].self = this; + elapsed_time_index++; + + } while(0); + probeBlockEnd(); + + pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL); + return; +} + +void __cyg_profile_func_exit(void *this, void *callsite) +{ + probeInfo_t probeInfo; + log_t log; + + sigset_t profsigmask, oldsigmask; + sigemptyset(&profsigmask); + sigaddset(&profsigmask, SIGPROF); + pthread_sigmask(SIG_BLOCK, &profsigmask, &oldsigmask); + + probeBlockStart(); + do { + // remove custom chart callback function + if(gTraceInfo.custom_chart_callback_count > 0) + { + if(custom_cb_addr == (void*)-1) + { + char **strings = BACKTRACE_SYMBOLS(&callsite, 1); + if(likely(strings != NULL)) + { + if(strstr(strings[0], CUSTOM_CB_FUNC_NAME) != NULL) + { + custom_cb_addr = callsite; + free(strings); + break; + } + free(strings); + } + } + else + { + if(callsite == custom_cb_addr) + break; + } + } + + elapsed_time_index--; + + if(this != elapsed_time_array[elapsed_time_index].self) + { // this should never happen + PRINTMSG("function exit: enter/exit function matching failed!!\n"); + } + + gettimeofday(&(elapsed_time_array[elapsed_time_index].endTime), NULL); + timersub(&(elapsed_time_array[elapsed_time_index].endTime), + &(elapsed_time_array[elapsed_time_index].startTime), + &(elapsed_time_array[elapsed_time_index].resultTime)); + + setProbePoint(&probeInfo); + INIT_LOG; + log.length = sprintf(log.data, "%d`,%d`,`,%lu`,%d`,%d`,`,`,%u`,`,0`,%u`,%lu`,%lu`,%d`,%llu", + LC_USERFUNC, probeInfo.eventIndex, probeInfo.currentTime, probeInfo.pID, probeInfo.tID, + (unsigned int) this, (unsigned int) callsite, low_pc, high_pc, USERFUNC_EXIT, + getElapsedTime(elapsed_time_array[elapsed_time_index].resultTime)); + APPEND_LOG_CALLSTACK(); + printLog(&log, MSG_LOG); + } while(0); + probeBlockEnd(); + + pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL); + return; +} + +#if defined(__i386__) +void mcount(void) +{ + return; +} + +#elif defined(__arm__) +void mcount_internal(u_long frompc, u_long selfpc) +{ + return; +} + +void __attribute__((__naked__)) __gnu_mcount_nc(void) +{ + asm( + "push {r0, r1, r2, r3, lr}\n\t" + "bic r1, lr, #1\n\t" + "ldr r0, [sp, #20]\n\t" + "bl mcount_internal\n\t" + "pop {r0, r1, r2, r3, ip, lr}\n\t" + "bx ip"); +} +#endif + +static inline void profil_count(void *pc) +{ +#if defined(__arm__) + /* This is a hack to prevent profil_count function from being called + inside of __gnu_mcount_nc. DO NOT put any other function between + __gnu_mcount_nc and profil_count. */ + if((pc >= (void*)(&profil_count - 0x18)) && (pc <= (void*)(&profil_count))) + return; +#endif + if(gProbeBlockCount != 0) + return; + + probeBlockStart(); + + real_pthread_mutex_lock(&profil_log_mutex); + do { + if(IS_FULL_SAMPLE_ARRAY) + { // when this happens, array size should be increased + PRINTMSG("profil log: sample info array is full\n"); + break; + } + sample_info_array[sample_write_index].time = getTime(); + sample_info_array[sample_write_index].pc = pc; +#ifdef USING_BACKTRACE + sample_info_array[sample_write_index].bt_size + = backtrace(sample_info_array[sample_write_index].bt_array, MAX_STACK_DEPTH); +//#if defined(__i386__) +// restore frame clobbered by signal handler + sample_info_array[sample_write_index].bt_array[2] = pc; +//#endif +#else + sample_info_array[sample_write_index].bt_array[0] = pc; + { + int i; + for(i = 0; i < elapsed_time_index; i++) + { + sample_info_array[sample_write_index].bt_array[i + 1] + = elapsed_time_array[i].self; + } + sample_info_array[sample_write_index].bt_size = elapsed_time_index + 1; + } +#endif + sample_write_index = (sample_write_index + 1) % SAMPLE_MAX_IN_INTERVAL; + } while(0); + real_pthread_mutex_unlock(&profil_log_mutex); + + probeBlockEnd(); +} + +#if defined(__i386__) +static void profil_counter(int signo, const struct sigcontext scp) +{ + profil_count((void *) GET_PC(scp)); + + /* This is a hack to prevent the compiler from implementing the + above function call as a sibcall. The sibcall would overwrite + the signal context */ + asm volatile(""); +} +#elif defined(__arm__) +static void profil_counter(int signr, siginfo_t *si, struct ucontext *uctx) +{ + profil_count((void *) GET_PC(uctx)); + + /* This is a hack to prevent the compiler from implementing the + above function call as a sibcall. The sibcall would overwrite + the signal context */ + asm volatile(""); +} +#endif + +#if 0 +// this function can cause floating point exception. +int __profile_frequency(void) +{ + /* + * Discover the tick frequency of the machine if something goes wrong, + * we return 0, an impossible hertz. + */ + struct itimerval tim; + + tim.it_interval.tv_sec = 0; + tim.it_interval.tv_usec = 1; + tim.it_value.tv_sec = 0; + tim.it_value.tv_usec = 0; + setitimer(ITIMER_REAL, &tim, 0); + setitimer(ITIMER_REAL, 0, &tim); + if (tim.it_interval.tv_usec < 2) + return 0; + return (1000000 / tim.it_interval.tv_usec); +} +#endif + +int __profil(int mode) +{ + struct sigaction act; + struct itimerval timer; + + static struct sigaction oact; + static struct itimerval otimer; + + if(profil_thread_on != 1) + { + profil_option = mode; + return 0; + } + + if(mode == 0) + { + if(profil_turned_on == 0) + { + return 0; + } + + if(setitimer(ITIMER_PROF, &otimer, NULL) < 0) + return -1; + profil_turned_on = 0; + return sigaction(SIGPROF, &oact, NULL); + } + + if(profil_turned_on == 1) + { + if(setitimer(ITIMER_PROF, &otimer, NULL) < 0 + || sigaction(SIGPROF, &oact, NULL) < 0) + { + return -1; + } + } + profil_turned_on = 1; + + act.sa_handler = (sighandler_t) &profil_counter; +#if defined(__i386__) + act.sa_flags = SA_RESTART; +#elif defined(__arm__) + act.sa_flags = SA_RESTART | SA_SIGINFO; +#endif + sigfillset(&act.sa_mask); + if(sigaction(SIGPROF, &act, &oact) < 0) + return -1; + + timer.it_value.tv_sec = 0; + timer.it_value.tv_usec = 1000000 / __profile_frequency(); + timer.it_interval = timer.it_value; + return setitimer(ITIMER_PROF, &timer, &otimer); +} + +void __monstartup(u_long lowpc, u_long highpc) +{ + low_pc = lowpc; + high_pc = highpc; + + pthread_mutex_init(&profil_log_mutex, NULL); + probeBlockStart(); + profil_thread_on = 1; + __profil(profil_option); + if(pthread_create(&profil_log_thread, NULL, &profil_log_func, NULL) < 0) + { + perror("Fail to create profil_log thread"); + } + probeBlockEnd(); + return; +} + +void _mcleanup(void) +{ + __profil(0); + profil_thread_on = 0; + return; +} + -- 2.7.4