系统级编程Lab 14. Exception and Process/Thread

这篇博客介绍了系统级编程的实践内容,包括在鼠标点击位置显示时间的实现,通过GetLocalTime()和wsprintf()函数处理时间显示。作者还解决了右键点击导致无限画画死循环的问题,通过创建线程避免影响主线程。此外,提到了多线程同步的实践,并给出了相关的代码示例。

系统级编程最后一周的实验,一共5个Practice,因为网上没有相关的解答,我给出自己的解答,有兴趣的可以参考参考,有误的可以发送我的邮箱doglikejie@163.com交流



这是ppt的题目要求

我分析之后给出我的源代码

Practice1

第一题是在鼠标点击位置显示时间

我使用了以下重要函数来实现这一功能

GetLocalTime(),这个函数的使用,我先定义了一个SYSTEMTIME类型的变量systime,然后GetLocalTime(&systime);这一行代码把本地时间储存在systime变量里。

然后很重要的一个函数wsprintf(),为什么我这里使用wsprintf函数而不是老师给的sprintf函数,因为我在vs2017环境下编译意外的发现sprintf函数无法被识别,具体原因我也不知道,所以就用了wsprintf函数代替。

 wsprintf(str, "[%d年%d月%d日%d时%d分%d秒]   ",

 systime.wYear, systime.wMonth, systime.wDay,

 systime.wHour, systime.wMinute, systime.wSecond);

因为windows编程没有printf这种函数,所以我用wsprintf函数的目的是为了将时间保存为字符串便于打印。我们利用systime.wYear等进一步确定精确的年月日时分秒。

 x = LOWORD(lParam);

 y = HIWORD(lParam);

这两行分别保存横坐标和纵坐标,关于如何保存鼠标的问题,我查阅网上发现不同的解法,我这里偷懒直接int两个变量x,y保存,网上的通解应该是POINT 一个变量,然后通过变量.x,变量.来储存横纵坐标,这两种方法的优劣我还没思考过。

 hdc = GetDC(hwnd);

 //输出字符串

 TextOut(hdc, x, y, str, strlen(str));

ReleaseDC(hwnd, hdc);

GetDC()和ReleaseDC()必须成对出现,GetDC之后必须释放掉。TextOut负责打印字符串,参数的用法可以查阅msdn。

#include <windows.h>

 

LRESULT CALLBACK WndProc (HWND,UINT,WPARAM,LPARAM) ;

 

int WINAPI WinMain (HINSTANCE hInstance,HINSTANCE hPrevInstance,

                    PSTR szCmdLine,int iCmdShow)

{

     static TCHAR szAppName[] =TEXT ("HelloWin") ;

     HWND         hwnd ;

     MSG          msg ;

     WNDCLASS     wndclass ;

 

     wndclass.style         = CS_HREDRAW |CS_VREDRAW ;

     wndclass.lpfnWndProc   = WndProc ;

     wndclass.cbClsExtra    = 0 ;

     wndclass.cbWndExtra    = 0 ;

     wndclass.hInstance     = hInstance ;

     wndclass.hIcon         = LoadIcon (NULL,IDI_APPLICATION) ;

     wndclass.hCursor       = LoadCursor (NULL,IDC_ARROW) ;

     wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;

     wndclass.lpszMenuName  = NULL ;

     wndclass.lpszClassName = szAppName ;

 

     if (!RegisterClass (&wndclass))

     {

          MessageBox (NULL,TEXT ("This program requires Windows NT!"),

                      szAppName, MB_ICONERROR) ;

          return 0 ;

     }

     hwnd = CreateWindow (szAppName,                  // window class name

                          TEXT ("The Hello Program"),// window caption

                          WS_OVERLAPPEDWINDOW,        // window style

                          CW_USEDEFAULT,              // initial x position

                          CW_USEDEFAULT,              // initial y position

                          CW_USEDEFAULT,              // initial x size

                          CW_USEDEFAULT,              // initial y size

                          NULL,                       // parent window handle

                          NULL,                       // window menu handle

                          hInstance,                  // program instance handle

 

<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.example</groupId> <artifactId>lab6</artifactId> <version>1.0-SNAPSHOT</version> <properties> <maven.compiler.source>8</maven.compiler.source> <maven.compiler.target>8</maven.compiler.target> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>org.apache.hadoop</groupId> <artifactId>hadoop-common</artifactId> <version>3.4.1</version> </dependency> <dependency> <groupId>org.apache.hadoop</groupId> <artifactId>hadoop-mapreduce-client-core</artifactId> <version>3.4.1</version> </dependency> </dependencies> </project> 以上是我的配置,以下是我的报错 hadoop jar lab6.jar data/wordfile1.txt data/wordfile2.txt output Exception in thread "main" java.lang.SecurityException: Invalid signature file digest for Manifest main attributes at sun.security.util.SignatureFileVerifier.processImpl(SignatureFileVerifier.java:325) at sun.security.util.SignatureFileVerifier.process(SignatureFileVerifier.java:267) at java.util.jar.JarVerifier.processEntry(JarVerifier.java:332) at java.util.jar.JarVerifier.update(JarVerifier.java:242) at java.util.jar.JarFile.initializeVerifier(JarFile.java:402) at java.util.jar.JarFile.getInputStream(JarFile.java:480) at org.apache.hadoop.util.RunJar.unJar(RunJar.java:201) at org.apache.hadoop.util.RunJar.unJar(RunJar.java:105) at org.apache.hadoop.util.RunJar.run(RunJar.java:317) at org.apache.hadoop.util.RunJar.main(RunJar.java:245) 我希望你能帮我解决
最新发布
11-12
日志如下 C:\own\app\python_code\.venv\Scripts\python.exe C:\own\app\python_code\work\IBL_click_all\click_all.py 🚀 启动 Android 应用探索器... 🔄 开始探索当前页面... ⏳ 等待页面加载最多 1s... ✅ 页面加载完成 📌 导航栏元素数量: 3, 非导航栏元素数量: 6 🟢 点击成功: com.brother.ptouch.iprintandlabel:id/navigation_my_label/My Labels/My Labels ⏳ 等待页面加载最多 1s... ✅ 页面加载完成 📌 导航栏元素数量: 3, 非导航栏元素数量: 3 🟢 点击成功: com.brother.ptouch.iprintandlabel:id/navigation_setting/Settings/Settings ⏳ 等待页面加载最多 1s... ✅ 页面加载完成 📌 导航栏元素数量: 3, 非导航栏元素数量: 6 🟢 点击成功: com.brother.ptouch.iprintandlabel:id/navigation_buy/Shop/Shop ⚠️ 当前不在目标应用 (com.android.chrome/org.chromium.chrome.browser.firstrun.FirstRunActivity),正在尝试恢复... ✅ 通过 back 成功返回目标 App ⏳ 等待页面加载最多 10s... ✅ 页面加载完成 📌 导航栏元素数量: 3, 非导航栏元素数量: 6 🟢 点击成功: null/null ⏳ 等待页面加载最多 1s... ✅ 页面加载完成 📌 导航栏元素数量: 3, 非导航栏元素数量: 6 🟢 点击成功: com.brother.ptouch.iprintandlabel:id/setting_printer/null ⚠️ 当前不在目标应用 (com.google.android.permissioncontroller/com.android.permissioncontroller.permission.ui.GrantPermissionsActivity),正在尝试恢复... ✅ 通过 back 成功返回目标 App ⏳ 等待页面加载最多 10s... ✅ 页面加载完成 📌 导航栏元素数量: 0, 非导航栏元素数量: 6 🟢 点击成功: com.brother.ptouch.iprintandlabel:id/wifi_printer_recycler_view/null ⏳ 等待页面加载最多 1s... ✅ 页面加载完成 📌 导航栏元素数量: 0, 非导航栏元素数量: 6 🟢 点击成功: com.brother.ptouch.iprintandlabel:id/gps_selected_item_button/Settings/null ⚠️ 当前不在目标应用 (com.android.settings/.spa.SpaActivity),正在尝试恢复... 🔁 正在通过 activate_app 恢复... ⏳ 等待页面加载最多 10s... ✅ 页面加载完成 ✅ 自动处理了弹窗 📌 导航栏元素数量: 0, 非导航栏元素数量: 8 🟢 点击成功: com.android.permissioncontroller:id/grant_singleton/null ⚠️ 当前不在目标应用 (com.google.android.permissioncontroller/com.android.permissioncontroller.permission.ui.GrantPermissionsActivity),正在尝试恢复... ✅ 通过 back 成功返回目标 App ⏳ 等待页面加载最多 10s... ✅ 页面加载完成 📌 导航栏元素数量: 0, 非导航栏元素数量: 6 ✅ 当前页面所有可点击元素已处理完毕。 🔙 返回上一页继续探索... ⏳ 等待页面加载最多 1s... ✅ 页面加载完成 📌 导航栏元素数量: 3, 非导航栏元素数量: 6 🟢 点击成功: com.brother.ptouch.iprintandlabel:id/setting_unit/null ⏳ 等待页面加载最多 1s... ✅ 页面加载完成 ✅ 自动处理了弹窗 📌 导航栏元素数量: 3, 非导航栏元素数量: 6 🟢 点击成功: com.brother.ptouch.iprintandlabel:id/setting_support/Support/null ⚠️ 当前不在目标应用 (com.android.chrome/org.chromium.chrome.browser.firstrun.FirstRunActivity),正在尝试恢复... ✅ 通过 back 成功返回目标 App ⏳ 等待页面加载最多 10s... ✅ 页面加载完成 📌 导航栏元素数量: 3, 非导航栏元素数量: 6 🟢 点击成功: com.brother.ptouch.iprintandlabel:id/setting_information/Information/null ⏳ 等待页面加载最多 1s... ✅ 页面加载完成 📌 导航栏元素数量: 3, 非导航栏元素数量: 13 🟢 点击成功: com.brother.ptouch.iprintandlabel:id/info_list/null ⏳ 等待页面加载最多 1s... ✅ 页面加载完成 📌 导航栏元素数量: 3, 非导航栏元素数量: 17 🟢 点击成功: com.brother.ptouch.iprintandlabel:id/send_info_check/Send Information/null ⏳ 等待页面加载最多 1s... ✅ 页面加载完成 📌 导航栏元素数量: 3, 非导航栏元素数量: 17 🟢 点击成功: com.brother.ptouch.iprintandlabel:id/privacy_policy_text_view/Privacy Policy/null ⏳ 等待页面加载最多 1s... ✅ 页面加载完成 📌 导航栏元素数量: 3, 非导航栏元素数量: 21 🟢 点击成功: com.brother.ptouch.iprintandlabel:id/privacy_policy_text2/When you use the SOFTWARE, information from the Brother Machine and the devices connected to the Brother Machine (“Device”), including but not limited to, product model, serial number, locale ID (regional information), OS type of your installation, firmware, use of each function of the SOFTWARE, may be recorded in our server. Additionally, printing information such as printing date, quantity, the types and sizes of paper, and the types of files, etc. (collectively, “Device Data”) may be recorded in our server. Device Data (except for the serial number) cannot be used in itself or in combination with any other information we may have to identify you as a person. We reserve the right to use such Device Data solely for the improvement of the SOFTWARE or any other products/services of Brother, our marketing/research activities without identifying you as a person, product planning or any other related activities for our customer’s benefits (collectively “Purposes”). We will not use your Device Data other than for the Purposes without your prior consent. We may disclose your Device Data to third parties in an anonymous format solely for achieving the Purposes, and always by obliging such third parties to control such data as confidential. Device Data includes the serial number of your Brother Machine. The serial number can be associated with the data which you might register to our sales company’s product registration website. However, we will not use the serial number to identify you or other than for the Purposes. Serial number may be stored in Server located in countries without an adequate level of protection for personal data compared to that in your country, but we will control the serial number in strict accordance with “Brother’s Statement on Device Data Worldwide” which is available at Brother’s Website <https://web.global.brother/aa/privacy.html> . /null ⏳ 等待页面加载最多 1s... ✅ 页面加载完成 📌 导航栏元素数量: 3, 非导航栏元素数量: 21 🟢 点击成功: com.brother.ptouch.iprintandlabel:id/navigation_layout/Create/Create ⏳ 等待页面加载最多 1s... ✅ 页面加载完成 📌 导航栏元素数量: 3, 非导航栏元素数量: 6 🟢 点击成功: com.brother.ptouch.iprintandlabel:id/tabLayout/null ⏳ 等待页面加载最多 1s... ✅ 页面加载完成 📌 导航栏元素数量: 3, 非导航栏元素数量: 6 🟢 点击成功: null/Templates/Templates ⏳ 等待页面加载最多 1s... ✅ 页面加载完成 📌 导航栏元素数量: 3, 非导航栏元素数量: 6 🟢 点击成功: com.brother.ptouch.iprintandlabel:id/download_template_button/DOWNLOAD TEMPLATES/null ⏳ 等待页面加载最多 1s... ✅ 页面加载完成 📌 导航栏元素数量: 3, 非导航栏元素数量: 5 🟢 点击成功: com.brother.ptouch.iprintandlabel:id/actionButtonNewLabel/NEW LABEL/null ⏳ 等待页面加载最多 1s... ✅ 页面加载完成 📌 导航栏元素数量: 0, 非导航栏元素数量: 7 🟢 点击成功: null/Navigate up/Navigate up ⏳ 等待页面加载最多 1s... ✅ 页面加载完成 📌 导航栏元素数量: 0, 非导航栏元素数量: 3 🟢 点击成功: com.brother.ptouch.iprintandlabel:id/buttonPanel/null ⏳ 等待页面加载最多 1s... ✅ 页面加载完成 📌 导航栏元素数量: 0, 非导航栏元素数量: 8 🟢 点击成功: com.brother.ptouch.iprintandlabel:id/edit_undo/Undo/null ⏳ 等待页面加载最多 1s... ✅ 页面加载完成 📌 导航栏元素数量: 0, 非导航栏元素数量: 7 🟢 点击成功: com.brother.ptouch.iprintandlabel:id/edit_save/Save/null ⏳ 等待页面加载最多 1s... ✅ 页面加载完成 📌 导航栏元素数量: 0, 非导航栏元素数量: 4 🟢 点击成功: com.brother.ptouch.iprintandlabel:id/edit_save_label_edit/42/null ⏳ 等待页面加载最多 1s... ✅ 页面加载完成 ⚠️ 分类元素时异常: Message: Cached elements 'By.xpath: //*[ (@clickable='true' or @focusable='true') and @displayed='true' and @enabled='true' ] ' do not exist in DOM anymore; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#staleelementreferenceexception Stacktrace: io.appium.uiautomator2.common.exceptions.StaleElementReferenceException: Cached elements 'By.xpath: //*[ (@clickable='true' or @focusable='true') and @displayed='true' and @enabled='true' ] ' do not exist in DOM anymore at io.appium.uiautomator2.model.ElementsCache.restore(ElementsCache.java:78) at io.appium.uiautomator2.model.ElementsCache.get(ElementsCache.java:153) at io.appium.uiautomator2.handler.GetElementAttribute.safeHandle(GetElementAttribute.java:23) at io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:59) at io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:259) at io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:253) at io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:77) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:352) at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:352) at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:438) at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:328) at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:302) at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:253) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:352) at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:287) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:352) at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1422) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360) at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:931) at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163) at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:700) at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:635) at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:552) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:514) at io.netty.util.concurrent.SingleThreadEventExecutor$6.run(SingleThreadEventExecutor.java:1044) at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) at java.lang.Thread.run(Thread.java:1119) ⚠️ 分类元素时异常: Message: Cached elements 'By.xpath: //*[ (@clickable='true' or @focusable='true') and @displayed='true' and @enabled='true' ] ' do not exist in DOM anymore; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#staleelementreferenceexception Stacktrace: io.appium.uiautomator2.common.exceptions.StaleElementReferenceException: Cached elements 'By.xpath: //*[ (@clickable='true' or @focusable='true') and @displayed='true' and @enabled='true' ] ' do not exist in DOM anymore at io.appium.uiautomator2.model.ElementsCache.restore(ElementsCache.java:78) at io.appium.uiautomator2.model.ElementsCache.get(ElementsCache.java:153) at io.appium.uiautomator2.handler.GetElementAttribute.safeHandle(GetElementAttribute.java:23) at io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:59) at io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:259) at io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:253) at io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:77) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:352) at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:352) at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:438) at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:328) at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:302) at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:253) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:352) at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:287) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:352) at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1422) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360) at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:931) at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163) at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:700) at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:635) at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:552) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:514) at io.netty.util.concurrent.SingleThreadEventExecutor$6.run(SingleThreadEventExecutor.java:1044) at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) at java.lang.Thread.run(Thread.java:1119) 📌 导航栏元素数量: 0, 非导航栏元素数量: 2 🔴 点击失败 unknown_element: Message: Cached elements 'By.xpath: //*[ (@clickable='true' or @focusable='true') and @displayed='true' and @enabled='true' ] ' do not exist in DOM anymore; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#staleelementreferenceexception Stacktrace: io.appium.uiautomator2.common.exceptions.StaleElementReferenceException: Cached elements 'By.xpath: //*[ (@clickable='true' or @focusable='true') and @displayed='true' and @enabled='true' ] ' do not exist in DOM anymore at io.appium.uiautomator2.model.ElementsCache.restore(ElementsCache.java:78) at io.appium.uiautomator2.model.ElementsCache.get(ElementsCache.java:153) at io.appium.uiautomator2.handler.Click.safeHandle(Click.java:36) at io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:59) at io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:259) at io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:253) at io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:77) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:352) at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:352) at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:438) at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:328) at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:302) at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:253) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:352) at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:287) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:352) at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1422) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360) at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:931) at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163) at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:700) at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:635) at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:552) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:514) at io.netty.util.concurrent.SingleThreadEventExecutor$6.run(SingleThreadEventExecutor.java:1044) at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) at java.lang.Thread.run(Thread.java:1119) 🔴 点击失败 unknown_element: Message: Cached elements 'By.xpath: //*[ (@clickable='true' or @focusable='true') and @displayed='true' and @enabled='true' ] ' do not exist in DOM anymore; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#staleelementreferenceexception Stacktrace: io.appium.uiautomator2.common.exceptions.StaleElementReferenceException: Cached elements 'By.xpath: //*[ (@clickable='true' or @focusable='true') and @displayed='true' and @enabled='true' ] ' do not exist in DOM anymore at io.appium.uiautomator2.model.ElementsCache.restore(ElementsCache.java:78) at io.appium.uiautomator2.model.ElementsCache.get(ElementsCache.java:153) at io.appium.uiautomator2.handler.Click.safeHandle(Click.java:36) at io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:59) at io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:259) at io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:253) at io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:77) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:352) at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:352) at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:438) at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:328) at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:302) at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:253) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:352) at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:287) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:352) at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1422) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360) at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:931) at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163) at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:700) at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:635) at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:552) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:514) at io.netty.util.concurrent.SingleThreadEventExecutor$6.run(SingleThreadEventExecutor.java:1044) at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) at java.lang.Thread.run(Thread.java:1119) ✅ 当前页面所有可点击元素已处理完毕。 🔙 返回上一页继续探索... ⏳ 等待页面加载最多 1s... ✅ 页面加载完成 📌 导航栏元素数量: 3, 非导航栏元素数量: 6 ✅ 当前页面所有可点击元素已处理完毕。 🔙 返回上一页继续探索... ⏳ 等待页面加载最多 1s... ✅ 页面加载完成 📌 导航栏元素数量: 3, 非导航栏元素数量: 6 ✅ 当前页面所有可点击元素已处理完毕。 🔙 返回上一页继续探索... ⏳ 等待页面加载最多 1s... ✅ 页面加载完成 📌 导航栏元素数量: 3, 非导航栏元素数量: 6 ✅ 当前页面所有可点击元素已处理完毕。 🔙 返回上一页继续探索... ⏳ 等待页面加载最多 1s... ✅ 页面加载完成 📌 导航栏元素数量: 3, 非导航栏元素数量: 6 ✅ 当前页面所有可点击元素已处理完毕。 🔙 返回上一页继续探索... ⚠️ 当前不在目标应用 (com.google.android.apps.nexuslauncher/.NexusLauncherActivity),正在尝试恢复... 🔁 正在通过 activate_app 恢复... ⏳ 等待页面加载最多 10s... ✅ 页面加载完成 ✅ 成功激活目标 App 📌 导航栏元素数量: 3, 非导航栏元素数量: 6 ✅ 当前页面所有可点击元素已处理完毕。 🔙 返回上一页继续探索... ⚠️ 当前不在目标应用 (com.google.android.apps.nexuslauncher/.NexusLauncherActivity),正在尝试恢复... 🔁 正在通过 activate_app 恢复... ⏳ 等待页面加载最多 10s... ✅ 页面加载完成 ✅ 成功激活目标 App 📌 导航栏元素数量: 3, 非导航栏元素数量: 6 ✅ 当前页面所有可点击元素已处理完毕。 🔙 返回上一页继续探索... ⚠️ 当前不在目标应用 (com.google.android.apps.nexuslauncher/.NexusLauncherActivity),正在尝试恢复... 🔁 正在通过 activate_app 恢复... ⏳ 等待页面加载最多 10s... ✅ 页面加载完成 ✅ 成功激活目标 App 📌 导航栏元素数量: 3, 非导航栏元素数量: 6 ✅ 当前页面所有可点击元素已处理完毕。 🔙 返回上一页继续探索... ⚠️ 当前不在目标应用 (com.google.android.apps.nexuslauncher/.NexusLauncherActivity),正在尝试恢复... 🛑 已多次回到 ('com.google.android.apps.nexuslauncher', '.NexusLauncherActivity'),疑似陷入循环,停止恢复。 ❌ 无法恢复至目标应用,退出。 🔚 自动化结束。 Process finished with exit code 0 日志繁琐
10-17
Introduction The usual implementation of malloc and free are unforgiving to errors in their callers' code, including cases where the programmer overflows an array, forgets to free memory, or frees a memory block twice. This often does not affect the program immediately, waiting until the corrupted memory is used later (in the case of overwrites) or gradually accumulating allocated but unused blocks. Thus, debugging can be extremely difficult. In this assignment, you will write a wrapper for the malloc package that will catch errors in the code that calls malloc and free. The skills you will have learned upon the completion of this exercise are pointer arithmetic and a greater understanding of the consequences of subtle memory mistakes. Logistics Unzip debugging_malloc.zip into an empty directory. The files contained are as follows: File(s): Function: debugmalloc.c Contains the implementation of the three functions you will be writing. This is the one file you will be editing and handing in. debugmalloc.h Contains the declaration of the functions, as well as the macros that will call them. driver.c Contains main procedure and the code that will be calling the functions in the malloc package dmhelper.c, dmhelper.h Contain the helper functions and macros that you will be calling from your code grader.pl Perl script that runs your code for the various test cases and gives you feedback based on your current code debugmalloc.dsp Exercise 3 project file debugmalloc.dsw Exercise 3 workspace file tailor.h, getopt.c, getopt.h Tools that are used only by the driver program for I/O purposes. You will not need to know what the code in these files do. Others Required by Visual C++. You do not need to understand their purpose Specification Programs that use this package will call the macros MALLOC and FREE. MALLOC and FREE are used exactly the same way as the malloc() and free() functions in the standard C malloc package. That is, the line void *ptr = MALLOC ( n ) ;will allocate a payload of at least n bytes, and ptr will point to the front of this block. The line FREE(ptr);will cause the payload pointed to by ptr to be deallocated and become available for later use. The macros are defined as follows: #define MALLOC(s) MyMalloc(s, __FILE__, __LINE__) #define FREE(p) MyFree(p, __FILE__, __LINE__) The __FILE__ macro resolves to the filename and __LINE__ resolves to the current line number. The debugmalloc.c file contains three functions that you are required to implement, as shown: void *MyMalloc(size_t size, char *filename, int linenumber); void MyFree(void *ptr, char *filename, int linenumber); int AllocatedSize(); Using the macros above allow MyMalloc and MyFree to be called with the filename and line number of the actual MALLOC and FREE calls, while retaining the same form as the usual malloc package. By default, MyMalloc and MyFree() simply call malloc() and free(), respectively, and return immediately. AllocatedSize() should return the number of bytes currently allocated by the user: the sum of the requested bytes through MALLOC minus the bytes freed using FREE. By default, it simply returns 0 and thus is unimplemented. The definitions are shown below: void *MyMalloc(size_t size, char *filename, int linenumber) { return (malloc(size)); } void MyFree(void *ptr, char *filename, int linenumber) { free(ptr); } int AllocatedSize() { return 0; } Your job is to modify these functions so that they will catch a number of errors that will be described in the next section. There are also two optional functions in the debugmalloc.c file that you can implement: void PrintAllocatedBlocks(); int HeapCheck(); PrintAllocatedBlocks should print out information about all currently allocated blocks. HeapCheck should check all the blocks for possible memory overwrites. Implementation Details To catch the errors, you will allocate a slightly larger amount of space and insert a header and a footer around the "requested payload". MyMalloc() will insert information into this area, and MyFree() will check to see if the information has not changed. The organization of the complete memory block is as shown below: Header Checksum ... Fence Payload Footer Fence Note:MyMalloc() returns a pointer to the payload, not the beginning of the whole block. Also, the ptr parameter passed into MyFree(void *ptr) will point to the payload, not the beginning of the block. Information that you might want to store in this extra (header, footer) area include: a "fence" immediately around the requested payload with a known value like 0xCCDEADCC, so that you can check if it has been changed when the block is freed. the size of the block a checksum for the header to ensure that it has not been corrupted (A checksum of a sequence of bits is calculated by counting the number of "1" bits in the stream. For example, the checksum for "1000100010001000" is 4. It is a simple error detection mechanism.) the filename and line number of the MALLOC() call The errors that can occur are: Error #1: Writing past the beginning of the user's block (through the fence) Error #2: Writing past the end of the user's block (through the fence) Error #3: Corrupting the header information Error #4: Attempting to free an unallocated or already-freed block Error #5: Memory leak detection (user can use ALLOCATEDSIZE to check for leaks at the end of the program) To report the first four errors, call one of these two functions: void error(int errorcode, char *filename, int linenumber); errorcode is the number assigned to the error as stated above. filename and linenumber contain the filename and line number of the line (the free call) in which the error is invoked. For example, call error(2, filename, linenumber) if you come across a situation where the footer fence has been changed. void errorfl(int errorcode, char *filename_malloc, int linenumber_malloc, char *filename_free, int linenumber_free); This is the same as the error(), except there are two sets of filenames and line numbers, one for the statement in which the block was malloc'd, and the other for the statement in which the block was free'd (and the error was invoked). The fact that MyMalloc() and MyFree() are given the filename and line number of the MALLOC() and FREE() call can prove to be very useful when you are reporting errors. The more information you print out, the easier it will be for the programmer to locate the error. Use errorfl() instead of error() whenever possible. errorfl() obviously cannot be used on situations where FREE() is called on an unallocated block, since it was not ever MALLOC'd. Note: You will only be reporting errors from MyFree(). None of the errors can be caught in MyMalloc() In the case of memory leaks, the driver program will call AllocatedSize(), and the grader will look at its return value and possible output. AllocatedSize() should return the number of bytes currently allocated from MALLOC and FREE calls. For example, the code segment: void *ptr1 = MALLOC(10), *ptr2 = MALLOC(8); FREE(ptr2); printf("%d\n", AllocatedSize()); should print out "10". Once you have gotten to the point where you can catch all of the errors, you can go an optional step further and create a global list of allocated blocks. This will allow you to perform analysis of memory leaks and currently allocated memory. You can implement the void PrintAllocatedBlocks() function, which prints out the filename and line number where all currently allocated blocks were MALLOC()'d. A macro is provided for you to use to print out information about a single block in a readable and gradeable format: PRINTBLOCK(int size, char *filename, int linenumber) Also, you can implement the int HeapCheck() function. This should check all of the currently allocated blocks and return -1 if there is an error and 0 if all blocks are valid. In addition, it should print out the information about all of the corrupted blocks, using the macro #define PRINTERROR(int errorcode, char *filename, int linenumber), with errorcode equal to the error number (according to the list described earlier) the block has gone through. You may find that this global list can also allow you to be more specific in your error messages, as it is otherwise difficult to determine the difference between an overwrite of a non-payload area and an attempted FREE() of an unallocated block. Evaluation You are given 7 test cases to work with, plus 1 extra for testing a global list. You can type "debugmalloc -t n" to run the n-th test. You can see the code that is being run in driver.c. If you have Perl installed on your machine, use grader.pl to run all the tests and print out a table of results. There are a total of 100 possible points. Here is a rundown of the test cases and desired output (do not worry about the path of the filename): Test case #1 Code char *str = (char *) MALLOC(12); strcpy(str, "123456789"); FREE(str); printf("Size: %d\n", AllocatedSize()); PrintAllocatedBlocks(); Error # None Correct Output Size: 0 Points worth 10 Details 10 points for not reporting an error and returning 0 in AllocatedSize() Test case #2 Code char *str = (char *) MALLOC(8); strcpy(str, "12345678"); FREE(str); Error # 2 Correct Output Error: Ending edge of the payload has been overwritten. in block allocated at driver.c, line 21 and freed at driver.c, line 23 Points worth 15 Details 6 pts for catching error 3 pts for printing the filename/line numbers 6 pts for correct error message Test case #3 Code char *str = (char *) MALLOC(2); strcpy(str, "12"); FREE(str); Error # 2 Correct Output Error: Ending edge of the payload has been overwritten. in block allocated at driver.c, line 28 and freed at driver.c, line 30 Points worth 15 Details 6 pts for catching error 3 pts for printing the filename/line numbers 6 pts for correct error message Test case #4 Code void *ptr = MALLOC(4); *ptr2 = MALLOC(6); FREE(ptr); printf("Size: %d\n", AllocatedSize()); PrintAllocatedBlocks(); Error # None Correct Output Size: 6 Currently allocated blocks: 6 bytes, created at driver.c, line 34 Points worth 15 Details 15 pts for not reporting an error and returning 6 from AllocatedSize Extra for printing out the extra block Test case #5 Code void *ptr = MALLOC(4); FREE(ptr); FREE(ptr); Error # 4 Correct Output Error: Attempting to free an unallocated block. in block freed at driver.c, line 43 Points worth 15 Details 15 pts for catching error Extra for correct error message Test case #6 Code char *ptr = (char *) MALLOC(4); *((int *) (ptr - 8)) = 8 + (1 << 31); FREE(ptr); Error # 1 or 3 Correct Output Error: Header has been corrupted.or Error: Starting edge of the payload has been overwritten. in block allocated at driver.c, line 47 and freed at driver.c, line 49 Points worth 15 Details 9 pts for catching error 6 pts for a correct error message Test case #7 Code char ptr[5]; FREE(ptr); Error # 4 Correct Output Error: Attempting to free an unallocated block. in block freed at driver.c, line 54 Points worth 15 Details 15 pts for recognizing error Extra for printing correct error message Test case #8 (Optional) Code int i; int *intptr = (int *) MALLOC(6); char *str = (char *) MALLOC(12); for(i = 0; i < 6; i++) { intptr[i] = i; } if (HeapCheck() == -1) { printf("\nCaught Errors\n"); } Error # None Correct Output Error: Ending edge of the payload has been overwritten. Invalid block created at driver.c, line 59 Caught Errors Points worth Extra Details "Caught Errors" indicates that the HeapCheck() function worked correctly. Extra points possible. Your instructor may give you extra credit for implementing a global list and the PrintAllocatedBlocks() and HeapCheck() functions.
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值